You are on page 1of 39

Building Environment Controller

By

I Bassa
Group 5
208502448 Supervisor

Dr A L L Jarvis Electronic Design 3 Phase 3 Report School of Electrical, Electronic and Computer Engineering

Abstract
This report documents the complete design of the Building Environment Controller done by Group 5 in Phase 3 of Electronic Design 3. The environment controller uses the X-10 communication protocol which uses the ac mains as a communication bus. The project was been divided into 4 modules which are allocated to each member of the design group. The modules are the central control unit, fire detection unit, sensor unit and load controller unit. The report also covers the integration of the other X-10 modules. In this report, full design documentation of the sensing moduleis presented. The report also includes information regarding prototyping and testing of the sensor module as well as prototyping of the X-10 protocol. The Sensor Module includes temperature sensing, humidity sensing and a people counter sensor to determine how many people there are in a particular room. These measurements are processed by a PIC microcontroller and are displayed on three dual seven segment displays. The microcontroller is also responsible for sending appropriate signals to the central controller to regulate the environmental conditions. The sensor module was successfully built and measurements of temperature and humidity were successfully achieved. The X-10 Communication scheme was only partially achieved;the Sensor Unit was only able to transmit a single signal over the AC mains. Full functionality of the communication protocol could not be achieved due to time constraints and the difficulty involved in implementing the protocol.

ii | P a g e

Declaration
I hereby declare that the contents of this report are my own original and unaided work, except where specific mention is made to the contrary in the form of a numbered reference.

Author s Full Name:

Irshad Bassa

Author s Student Number:

208502448

Author s Signature:

Date:

27/03/2011

iii | P a g e

Table of Contents
Abstract ................................ ................................ ................................ ................................ ............. ii Declaration ................................ ................................ ................................ ................................ ....... iii 1. 2. 3. 4. 5. Introduction................................ ................................ ................................ ............................... 1 Module Allocation................................ ................................ ......... Error! Bookmark not defined. Integration of X-10 Modules................................ ................................ ................................ ..... 3 Top-Down Design ................................ ................................ ................................ ....................... 4 Sensor Unit ................................ ................................ ................................ ................................ 5 5.1. X-10 Communication Protocol ................................ ................................ ............................ 5 Zero-Crossing Detector ................................ ................................ ............................... 5 120 kHz Carrier Generator ................................ ................................ .......................... 5 X-10 Addressing ................................ ................................ ................................ ........ 6 5.1.1. 5.1.2. 5.1.3. 5.2. 5.3. 5.4. 5.5. 5.6.

Temperature Sensing ................................ ................................ ................................ ......... 8 Humidity Sensing................................ ................................ ................................ ................ 8 Display ................................ ................................ ................................ ............................. 10 Microcontroller ................................ ................................ ................................ ................ 11 IR Beam People Counter................................ ................................ ................................ ... 12 Transmitter Circuit................................ ................................ ................................ .... 12 Receiver Circuit................................ ................................ ................................ ......... 13 Original Design ................................ ................................ ................................ ......... 14 Transformer Power Supply Design ................................ ................................ ............ 14

5.6.1. 5.6.2. 5.7. 5.7.1. 5.7.2. 6. 6.1. 6.2. 6.3. 7. 8. 9.

Power Supply ................................ ................................ ................................ ................... 14

Other X-10 Modules................................ ................................ ................................ ................. 16 Central Control Unit ................................ ................................ ................................ ......... 16 Fire Detection Unit ................................ ................................ ................................ ........... 16 Load Appliance Controller ................................ ................................ ................................ 16

Sensor Module Schematic ................................ ................................ ................................ ........ 17 Printed Circuit Board Design ................................ ................................ ................................ .... 18 Prototyping ................................ ................................ ................................ .............................. 19 9.1. 9.2. 9.3. 9.4. Temperature ................................ ................................ ................................ .................... 19 Humidity ................................ ................................ ................................ .......................... 19 People Counter ................................ ................................ ................................ ................ 20 X-10 Communication ................................ ................................ ................................ ...... 20 Software Design ................................ ................................ ................................ ................... 21 Future Enhancements ................................ ................................ ................................ .......... 23 Conclusion ................................ ................................ ................................ ........................... 24

10. 11. 12.

References................................ ................................ ................................ ................................ ....... 25 Appendix A ................................ ................................ ................................ ................................ ......... I iv | P a g e

Appendix B ................................ ................................ ................................ ................................ ........ II

v|Pa ge

1. Introduction
The need for regulated environmental conditions is very important in buildings and offices as it can result in employee satisfaction. This satisfaction can lead to increased productivity. Regulated environmental conditions also results in safe working conditions.This is in line with regulations such as the Occupational Safety and Health act [1].There is also a need for more power saving schemes in the current world. Currently office environments waste a huge amount of electricity on lights and air-conditioners [2] when there is nobody in the offices. There needs to be a solution to automate the control of lighting and air-conditioners. The purpose of this report is to present thecomplete design of the Building Environment Controller , more particularly the design of the Sensor Unit and X-10 protocol. The purpose of the controller is to measure environmental conditions such as temperature and humidity and be able to regulate them. The Building Environment Controller is also able to conserve electricity by turning of lights and air-conditioners when not in use. The design also makes use of the X-10 communication protocol which makes use of the AC mains as a communication bus. A modular breakdown of the project was done to distribute the workload amongst the design team. The project is broken down into four modules, namely, the central controller unit, the sensor unit, the fire detection unit and the load appliance controller. The modular breakdown of the project is shown below in Figure 1. The module allocations to specific group members are shown in Table 1.

Figure 1 Building Environment Controller

1|Page

Table 1 Module Allocations

Module Allocation

Group Member

Central Control Module

Ayesha Saeed

Sensor Module

Irshad Bassa

Fire Detection Module Load Appliance Module

Imraan Vawda

Wayne Frederick

2|Page

2. Integration of X-10 Modules


The different modules of Building Environment Controller are integrated by means of the AC mains. The AC mains are used as a communication bus. The following figure shows the integration of the modules. The sensor module and fire detection module transmit information to the control unit. The control unit then sends appropriate instructions to the appliance controller to regulate the environment. The integration of modules are shown in Figure 2

Figure 2 Integration of Modules

3|Page

3.

op-Down Desi n

The Se sor Un t s respons ble for measur ng temperature and hum d ty It also measures how many people are present n a room at any part cular t me by the use of IR beam sensors. It then relays the nformat on to the main controller via the X-10 communication system. The top-down design of the sensor unit is shown below.

Sensor Module

Communication Protocol

Power Supply

X-10 Protocol

Transformerless Power Supply

Temperature

Humidity

4|Page

Fi u

3 Top- own Desi n of Senso Module

Zero-Crossing Detection

120 Hz Carrier Generator

120 Hz Carrier Detector

M 35 Sensor

HCZ-H8 Sensor

IR Beam

4 Multiple ed Seven Segment Display

Microcontroller PIC 16F877XA

People Counter

Display

4. Sensor Unit
4.1.X-10 Communication Protocol
The X-10 communication protocol is a communication capable of sending signals over the ac mains in buildings and offices. The X-10 protocol uses 120 kHz modulated bursts timed with the zerocrossing of the AC mains to send and receive digital information. The protocol allows for modules to communicate with one another by simply being plugged into the wall plug. A message is transmitted across this system consists of four parts; a start code, an office code, a key code and a suffix [3]. The X-10 Protocol works by synchronising transmissions with the zero-crossing of an AC signal. By monitoring zero-crossing, the module knows when to receive or send a signal. A binary 1 signal is represented by a 120 kHz burst, 1 ms long after the zero crossing. A binary 0 signal is represented by a lack of 120 kHz burst. [3] The sensor module would only need to be able to send X-10 signals;therefore the module would need to have a zero-crossing detector, a 120 kHz carrier generator. [3]

4.1.1. Zero-Crossing Detector The zero-crossing is easily implemented by connecting the AC voltage through a resistor to pin RB0 (INT0). This pin is configured an external interrupt. The resistor is used to limit the current flowing to the microcontroller. We will use a current IPeak=30A for the design of the resistor, this is well within current capacity of the microcontroller pin. The calculation of the resistor value is shown below:
Eq. 1

The PIC microcontroller has input protection diodes designed into the I/O pins. The diodes clamp any voltage higher than VDD or lower than VSS [4]. Therefore, when the AC voltage is in the negative half of its cycle, the RB0 pin will be clamped to VSS - 0.6V [5]. This will be interpreted as a logic zero. When the AC voltage rises above the input threshold, it will be interpreted as logic 1 . Pin RB0 is configured as an external interrupts. Upon every ISR, the edge select bit is toggled. This will ensure that the ISR is executed at every zero-crossing.

4.1.2. 120 kHz Carrier Generator The X-10 Protocol uses 120 kHz modulation to transmit information over the 50 Hz AC mains. To avoid using external circuitry, the microcontroller s CCP2 module is used to generate a 120 kHz PWM square wave of duty cycle 50%.The use of a high pass filter allows for the 120 kHz signal to be safely coupled to the mains. Referring to the circuit diagram shown in Figure 4, C1 is chosen to present low impedance to the 120 kHz signal and it must provide high impedance to the 50 Hz mains. A value of 100F which is X2 rated was chosenfor the high pass filter. With regards to software, the TRISC bit 3 is set to 0 to enable 120kHz PWM signal and the TRISC bit 3 is set to 1 to disable the PWM signal. Timer 0 is then used to measure a 1ms burst.

5|Page

VCC 5V C1 V1 VCC Q1 CCP2 4 R3 200 BC547C 0 3 R2 50 1 100uF R1 1M 220 Vrms 50 Hz 0 2

Fi u e 4120 kHz C

4. .3. XAddressing Addressing is an e tremely important aspect in the X-10 communication protocol. It allows the correct information to be sent specific modules. Furthermore it allows the information conveyed to be interpreted and thus the correct functionality to be performed by the Building Environment Controller . The addressing used in the design consists of a start code a house code a key code and finally a suffix code. The start code is used to notify the X-10 devices that a transmission is pending. The start code used in the Building Environment Controller was 1-1-1-0. Then the house code is used to ensure the information is sent to the correct device. Finally the key code is used to implement functionality of the modules. The key code is further divided into a unit address or function code. The addressing scheme is shown in Error! Reference source not found .

Start Code (4 bits)

House Code (4 bits)

Key Code (4 Bits)

Suffix (1 bit)

Unit Address Unit Address

Function Code

Due to noise presented on the power lines, a binary 1 would be represented as 1-0 and a binary 0 would be represented by 0-1 . Furthermore, each transmission is sent twice to reduce error. The addressing of the various modules is shown inTable 2.

6|Page

 



i er Generator Circuit



Table 2 Addressing of various modules

Message Type

House Code

Key Code Unit Address Function Code 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 1 1 0 0 1 0 1

Suffix

Central Control Unit Address Load Appliance Address Fire Detector Address Sensor Module Address Load On Command Load Off Command Load Brighter Command Load Dimmer Command Fire Detected Command Empty Room: Lights off Command Entered Room: Lights on Command S itch on AC S itch off AC

0 1 0 1 1 1 1 1 0 0 0 0 0

1 1 0 0 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 -

1 1 1 1 -

1 1 1 1 -

0 0 0 0 -

0 0 0 0 1 1 1 1 1 1 1 1 1

7|Page

" "

4.2.Temperature Sensing
Temperature sensing will be done by the use of a LM35 Temperature Sensor. The sensor is pre calibrated to measure in Celsius. It has an accuracy of 0.25C at room temperature. The sensor provides temperature readings based on a linear 10 mV/C scale factor[6]. The circuit configuration of the LM35 is shown below. Pin 2 of the sensor is connected to the ADC pin AN0 of the microcontroller. The LM35 sensor will be places as close as possible to pin AN0 (within a few centimetres) to prevent attenuation of the signal. The ambient temperature of the room will be calculated and outputted to a multiplexed 4 Seven Segment displays.
VCC 5V U1 VCC 0
Vs GND Vout

1 AN0

LM35

Figure 5 LM35 Temperature Sensor Circuit

4.3.Humidity Sensing
Humidity Sensing will be carried by the use of the HCZ-H8 Resistive Humidity Sensor. This sensor was chosen primarily for feasibility reasons as well as availability. The sensor changes its resistance based on the relative humidity of environment. The sensor has a relative humidity range between 20% and 90% with an accuracy range of 3% [7]. The sensor requires an AC signal to operate due to the fact that a DC signal would corrode the device over time due to current only flowing in one direction. With the use of an AC signal, the fields would be reversed and allow for longevity in the lifetime of the sensor. The signal chosen to drive the sensor was a 1 kHz square AC wave with a value of 2Vpk-pk. This was achieved by first creating a 1 kHz PWM signal from the microcontroller. This signal ranges from 0-5V. The signal is then passed into a 741 Op-Amp. The Op-Amp circuit was configured as an inverting summing amplifier. Since the Op-Amp requires a negative rail an LMC7660 voltage converter was used to create a -5V rail to supply the Op-Amp. The schematic [8] of the LM7660 is shown in Figure 6. The Op-Amp was configured as a difference amplifier. The gains are set appropriately to give a -1V to +1V square wave output. Figure 8 shows the simulation results obtained from Multisim. A square wave source is used to simulate PWM signal from the microcontroller.

Figure 6 LMC 7660 [8]

8|Page

XSC1 VCC 5V VCC


7 3 1 5
A B _ + _ E xt T ri g + _

U1 4

R3 1 V1 1k 5V 2k

741 R1

Figure 7 Circuit to create -1V to +1V square

Figure 8 Simulation Results

The schematic of the sensor is shown below. The AC signal created by the PWM is passed through a DC blocking capacitor, which removes the DC component from the signal. The capacitor value should be chosen to be large enough so that the reactance would be small at 1 kHz. The value chosen was 10F. The main reason to create the AC signal from the microcontroller was to be able to sync the sampling. Calculation of the humidity is done by first measuring the resistance of the sensor. This resistance is then used to find the corresponding relative humidity by using the look-up table found in Appendix A. The look-up table uses resistance of the sensor and current temperature to determine the relative humidity of the room. The resistance of the sensor is measured by measuring voltages at points V1 and V2 by using ADC pins AN1 and AN2. The current I1 passing through RSeries can then be measured by the use of Ohm s Law.

The resistance of the sensor RSensor can then be measured:

9|Page

%$

10k R2

2k VEE VEE -5V GND GND

ave

50%

C1 1 10uF 1kHz AC Si nal 2Vpp

V1 I1 Rseries 2 100k AN1

V2 3 Rsensor AN2

4.4.Display
The use of 4 seven segment displays will be used to display the measured values of temperature and humidity. It will also be able to display the number of people currently in the room which would be used in the prototyping phase of the design. The 4 seven segments displays will be multiplexed to save power consumption as well as reduce the amount of I/O ports needed. The multiplexed connection uses the phenomenon of persistence of vision where an afterimage remains on the retina of the eye for approximately 40 milliseconds [9]. We can therefore update each display every 6.667 milliseconds. The corresponding refresh rate frequency is 150 Hz. The use of Timer3 as an overflow interrupt will be used to generate the required refresh rate. The schematic of the circuit is shown below. The type of seven segment display used in the design was the common anode. There are 6 control lines used which are connected to the seven segment displays via BJT transistors which are configured as a switch. Port D is connected to the segment lines of the displays.

10 | P a g e

&

GND GND

Figure 9 Humidity Sensor Circuit

Figure 10 Multiplexed Seven Segment Displays

4.5.Microcontroller
The role of the microcontroller is to be able to communicate with the main control unit. It is also responsible for reading measurements from the various sensors. It processes these measurements and does appropriate calculations to regulate the environmental conditions. The choice of microcontroller to use in the design of the sensor is very important. It also has to take into account the required specifications for the design. It was advised to us that we should use PIC microcontroller to broaden our knowledge of microcontrollers. Therefore PIC microcontrollers were only looked at when comparing microcontrollers for features. The table below shows the requirements for the sensor design.
Table 3 Requirements for design of sensor module

Requirement Operating Voltage External Interrupt Digital Outputs Timers PWM Output Analogue Inputs

Value 5V 3 14 4 2 3

For choosing a suitable microcontroller, Microchip s microcontroller parameter search page was looked at. The search was narrowed down to the 4 microcontrollers shown in the table below. This was based on requirements, price and availability.
Table 4 PIC Microcontroller comparison

Microcontroller

Operating Voltage 5V

External Interrupts 1

I/O Pins 33

ADC 10 Channel 10 Channel 13 Channel 8 Channel

Timers

PWM

Price1

PIC 16F877A

R47.95

PIC 16F887

5V

33

R35.95

PIC 18F4520

5V

33

R46.70

PIC 18F458

5V

33

R84.50

By looking through the table, it was found that the PIC 18F877 is the appropriate microcontroller in terms of price and functionality. The pin diagram of the PIC 18F877 is shown in Figure 11below.

Price from Mantech Electronics as of 28 March 2011

th

11 | P a g e

Fi ure 11 Pin Diagram of PIC 18F4520 [10]

4.6.IR Beam People Counter


The IR Beam People Counter will be able to count the number of people in a room at a certain time. This will help in regulating air temperature and humidity in the room. The People Counter will be implemented by the use of two infrared red beam sensors. The sensors will be placed on either side of the entrance of a room. As it can be seen below in Figure 12, IR Beam Sensor A is placed outside the room and IR Beam Sensor B is placed inside the room. The order in which the sensors are triggered gives an account if a person has entered or exited the room.

The IR Beam Sensor consists of two circuits, a transmitter and receiver circuit.
4.6. . ransmitter Circuit The transmitter circuit consists of a 555 timer which is configured in the astable configuration. The design also makes use of 2 LEDs to increase the intensity of the beam. The 555 timer is configured to have a frequency of 38 kHz. The corresponding duty cycle calculated was 52 . According to the datasheet of the 555 timer, the maximum possible output current is 200mA [11]. The volt drop across the Infrared LED is 1.35V. The maximum current for the LED is 100mA [12]. We can design LED current to be 90mA. Therefore we can design the output current from the 555 to be 180 mA.

12 | P a g e

'

Figure 12 IR Beam Sensors

) (

VCC 5V Vs 1.5k R1
RST VCC OUT

1 Rout 22

4
DIS THR

18k R2

7
TRI CON GND

LED1

LED2

1nF

555_TIMER_RATED Timer

4. .2. Receiver Circuit The TSOP4838 IR Receiver Sensor is used to implement the receiver circuit. The sensor receives the 38kHz signal from the IR LED. The receiver gives an active low output when the beam is broken. The block diagram of the receiver module is shown below.

The circuit of the IR Sensor is shown below. The output signal is then connected to external interrupt pins INT1 and INT2. The interrupt registers would be configured to trigger on falling edge.

13 | P a g e

2 1

Figure 13 Transmitter Circuit

Figure 14 Block Diagram of Receiver Sensor [13]

Figure 15 IR Beam Circuit [13]

4.7.Power Supply
4.7.1. Original Design Since form factor is important to the design as it would need to plug into a wall socket, a power supply with a transformer would not applicable. An alternative to this would be a transformerless power supply. This would also reduce cost since transformers are expensive and their form factor is quite big. However, a transformerless power supply would have need safety precaution as there is no isolation from the mains.The circuit used is based on the guidelines presented by Microchip [14]. However it was found that the power supply did not function as expected. The power supply collapsed under an extremely small load. It was then decided to use an alternate power supply which is presented in

Figure 16 Transformerless Po er Supply

4.7.2. Transformer Power Supply Design The transformer power supply design used was designed by Imraan Vawda. It was a similar design used in Electronic Design 1. The reason that this design was used was due to the design being found reliable after tests were conducted. The use of a transformer ensured that the power supply was safer due to isolation being present. Although form factor was increased, it was found that the reliability of the power supply made up for the size shortcomings.

14 | P a g e

Figure 17 Transformer Po er Supply

15 | P a g e

5. .Central Control Unit


The control unit provides an interface between the end-user and the various application modules. It uses an LCD screen as its console and allows the user to control and monitor environmental conditions. From the menu, the user can select a device and program the on/off times of the device. This is done by allocating an address code to each device and then using the AC mains as a data bus to transmit control messages to corresponding devices. The central control unit functionality requires it to have an X-10 generator and receiver circuit. The circuit [4] of the receiver circuit is shown below.

Figure 18 Recei er Circuit

5.2.Fire Detection Unit


The fire detection unit will be used to detect fire in a room. The unit makes use of a thermistor to sense if a fire is present in the room. Once a fire has been detected an alarm would be sounded in the room where the fire has been detected. The controller unit would also get an alert of the fire and a predefined S S notification would be sent to the user via a GS module.

5.3.Load Appliance Controller

The load appliance controller will be able to drive about 500W of power into an attached load. It will be able to control lighting in a room as well as being able to control the speed of ceiling fans. Another application would be to be able to switch of the air condition in a room. The load appliance controller would be to flash the lights in the case of an emergency such as a fire being detected. The use of the load appliance controller will be able to reduce the amount of electricity being used and thus decreasing the carbon footprint of the company.

16 | P a g e

76

5.

ther X-

Modules

6. Sensor Module Schematic


The following circuit diagram shown in Figure 19 shows the complete schematic of the Sensor Module which is a collaboration of all the circuits presented in Section 4.
Sensor Module AC Signal Humidity
J1 4k R2 R3 10k
4 7 3 1 5

U10

I1

C1 470uF

AN1 22 Rse rie s 100k V1

23

AN2 V2

50%

Temperature
U8
Vs GND Vout

31 PIC18F4520 U1 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

Rse nsor

21
2

AN0

30 29 HDR1X4 28 R1 10M 27 V1 311 Vrms 50 Hz 0

32 741 R4 2k C3 1uF 25 C2 10uF 24


1 2 3 4

LM35 9 13 14

VCC

U9
8 7 6 5

15 33 16 VCC 5V

38

Zero-Crossing 120kHz Generator


R6 34 CCP2 Q7 R7 200 BC547C 36 50 35 C4 100uF R5 1M

26 LM7660

-5V

Display

Negative Rail
RE0 Q1 37 Q2 RE1 BC558B BC558B RE2 RC0 8 12 10 11 BC558B 18
CA CA CA CA CA

Q3

Q4

BC558B

BC558B

Q5

Q6 INT1 BC558B 19
CA

J2 C5 4.7uF 40 HDR1X3 J3 INT2 U7 HDR1X3 39 IR BEAM B IR BEAM A

RC3 RC4

U2
A B C D E F G A B C D E F G

U3
A B C D E F G

U4
A B C D E F G

U5
A B C D E F G

U6
A B C D E F G

IR Beam Sensor
RD3 RD4 RD5 RD6

RD0 1 RD1 2 RD2 3 4 5 7 6 17

Figure 19 Sensor Module Schematic

17 | P a g e

7. Printed Circuit Board Design


The PCB of the sensor module was implemented by exporting the above schematic into Ultiboard. The PCB was manually placed and routed to ensure the design was optimised. The PCB was made on a double-sided board; this was due to the complexity of 3 dual seven segment displays. Figure 20 and Figure 21 shows the final routed PCB.

Figure 20 Top Layer of PCB

Figure 21 Bottom Layer

18 | P a g e

8. Prototyping
Before prototyping of the Sensor module was conducted, the PCB was assembled and the different tracks were tested for connectivity. The constructed PCB is shown in Figure 22 below.

Figure 22 Constructed PCB

8.1.Temperature
The temperature sensor was first prototyped. It was found that there were minimal problems encountered in interfacing the LM35 to the ADC of the microcontroller. It was found that the temperature reading from the LM35 deviated from the actual by approximately 3C. This was measured by a thermometer. This error was corrected in programming by offsetting the measured value.

8.2.Humidity
The prototyping of the humidity sensor first consisted of testing the AC signal to pass through the resistive humidity sensor. Figure 23 shows the PWM signal from the microcontroller.

Figure 23 PWM output from CCP1

19 | P a g e

The above signal is then passed into the op-amp and the following waveform was achieved as shown in Figure 24. This waveform concurs with simulation results.

Figure 24 -1 to +1V AC Signal generated

8.3.People Counter
The prototyping of the IR Beam sensor caused much difficulty as the sensors purchased did not behave as expected. This meant that the signal sent from the IR LEDs could not be detected. Due to time constraints, the people counter circuit could not be made functional and thus left out of the design on the day of demonstration.

8.4. X-10 Communication


The X-10 communication was only partially achieved. This was achieved by sending a signal across the AC mains to the Load Controller. Full functionality of addressing and communicating between modules could not be achieved due time constraints.

20 | P a g e

9. Software Design
The programming language chosen to implement the sensor mod was C programming language, ule more particularly Hitech C compiler for PIC microcontrollers. The advantage of using C is that it is more efficient than Assembly Language in terms of development time. The software will be designed to use Interrupt Driven Methodology. This is very efficient as only 1 microcontroller will be needed to implement all the functionality of the sensor module design. It also allows the microcontroller to perform a vast array of tasks. Flowcharts of the main program and interrupts are shown in. The final code used in design of the sensor unit is shown in Appendix .

Figure 25 Main Program Flo

Figure 26 Timer 0 Interrupt for Seven Segment Displays

21 | P a g e

Chart

Figure 27 INT0 Flowchart

Figure 28 Function Send_Data()

22 | P a g e

10.

Future Enhancements

By consulting with Mr Farouk Bassa, it was found that ISO compliant laboratories require temperature measurements to be taken at different intervals during the day. Thus the sensor unit could be improved to be able to store measured variables such as temperature and humidity at particular intervals. Furthermore a computer application could be developed to be able to download the information to PC. With regards to the X-10 Communication protocol, with more time available the design could be completed and the X-10 protocol could be properly implemented with complete functionality. The X-10 does have its flaws with regards to speed and difficulty in implementing. There is room for improving the system to be able to send larger amounts of data.

23 | P a g e

11.

Conclusion

The report encompasses the complete design of the Building Environmental Controller , in particularly the Sensor Unit. The modules were divided into a central control unit and three application modules. The modules are able to communicate to each other via the X-10 communication protocol. This protocol allows for messages to be transmitted and received through the ac mains. It essentially uses the ac mains as a communication bus. Most of the functionalities of the sensor unit were achieved. The sensor unit successfully measured temperature and humidity. The X-10 communication protocol was only partially achieved. A signal was sent through the mains and it was received on the other end of the mains by the Load Appliance Controller.

24 | P a g e

References
1. Labour.gov.za. Labour.gov.za. [Online] 1993. [Cited: 2 May 2011.] http://www.labour.gov.za/legislation/acts/occupational-health-and-safety/read-online/amendedoccupational-health-and-safety-act. 2. Zeroemmissionproject.com. Zeroemmissionproject.com. [Online] 16 April 2010. [Cited: 02 May 2011.] http://zeroemissionproject.com/blog/article/25. 3. Microchip.Microchip.com. [Online] 2010. [Cited: 20 March 2011.] http://ww1.microchip.com/downloads/en/AppNotes/00655a.pdf. 4. . Microchip.com. [Online] 2010. [Cited: 15 March 2011.] http://ww1.microchip.com/downloads/en/AppNotes/00236B.pdf. AN236. 5. . microchip.com. [Online] 2010. [Cited: 20 March 2011.] http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en01 1013. 6. National Semiconductor. National Semiconductor/Downloads. National Semiconductor. [Online] November 2000. [Cited: 22 April 2011.] www.national.com/pf/LM/LM35.html. 7. Mobicon Electronic Component.fenghua.com. [Online] 2010. [Cited: 16 March 2011.] http://www.fenghua.com/pdf/humidsensor/HCZ-H8.pdf . 8. National Instruments. National. National. [Online] February 2005. [Cited: 15 April 2011.] www.national.com/pf/LM/LMC7660.htm. 9. Unkno n.Mediacollege.com. [Online] 2009. [Cited: 22 March 2011.] http://www.mediacollege.com/glossary/p/persistence-of-vision.html. 10. Microchip. Microchip.com. Microchip.com. [Online] 2004. [Cited: 12 April 2011.] ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf . 11. National.national.com. [Online] 2006. [Cited: 28 March 2011.] www.national.com/ds/LM/LM555.pdf . 12. Vishay.datasheetcatalog.com. [Online] 2008. [Cited: 26 March 2011.] www.datasheetcatalog.com/datasheets.../TSAL6400.shtml. 13. . Vishay.com. Vishay.com. [Online] 23 June 2003. [Cited: 9 April 2011.] www.vishay.com/docs/82090/tsop48xx.pdf. 14. Microchip.Microchip.com. [Online] 2010. [Cited: 25 March 2011.] http://ww1.microchip.com/downloads/en/AppNotes/00954A.pdf. 15. frontline-electronics.com. [Online] July 2010. [Cited: 24 March 2011.] http://www.frontlineelectronics.com/Downloads/Demo2.pdf. 16. Atmel.Atmel.com. [Online] 2010. [Cited: 22 March 2011.] http://www.atmel.com/dyn/resources/prod_documents/doc2542.pdf. 17. Unkno n.frontline-electronics.com. [Online] 2009. [Cited: 15 March 2011.] http://www.frontline-electronics.com/Downloads/Demo2.pdf. 18. Wikipedia.Wikipedia.org. [Online] 2010. [Cited: 26 March 2011.] http://en.wikipedia.org/wiki/220V#History_of_voltage_and_frequency. 19. Cook, David.Intermediate Robot Building. s.l. : TIA, 2010. 20. Ido Bar-Tana. Modification of X10 220V Heavy Duty Appliance module for use with 3 Phase systems. Ido Bar-Tana. [Online] Mega Watt. [Cited: 25 March 2011.] http://idobartana.com/hakb/modifying_heavy.htm. 25 | P a g e

21. Burroughs, Jon. X10 Home Automation. Electronics Project Design. [Online] 1 May 2010. [Cited: 23 February 2011.] http://www.electronics-project-design.com/cgibin/counter.pl?url=http%3A%2F%2Fwww%2Emicrochip%2Ecom%2Fstellent%2Fidcplg%3FIdcService %3DSS_GET_PAGE%26nodeId%3D1824%26appnote%3Den012050&referrer=http%3A%2F%2Fwww %2Eelectronics-project-design%2Ecom%2FX10HomeA. ISBN: 978-1-60932-125-3. 22. PIC16F87XA. Microchip. [Online] 28 July 2003. [Cited: 24 March 2011.] www.microchip.com/downloads/en/DeviceDoc/41262d.pdf. DS39582B. 23. Doug Cox. Interfacing to AC Power Lines. Microchip. [Online] 1 March 2002. [Cited: 24 March 2011.] http://ww1.microchip.com/downloads/en/AppNotes/00521c.pdf. DS00521C. 24. LMB162GBY LMB162GBY. Topway Display. [Online] 1 April 2009. [Cited: 28 March 2011.] http://www.mobicon.co.za/Datasheets/Products/LMB162GDC.pdf. 25. Condit, Reston. Transformerless Power Supplies: Resistive and Capacitive. Microchip. [Online] 24 August 2004. [Cited: 28 March 2011.] http://ww1.microchip.com/downloads/en/AppNotes/00954A.pdf. 26. Mohan Kumar. Capacitor Power Supply. ElectroSchematics. [Online] 9 May 2010. [Cited: 2 March 2011.] http://electroschematics.com/5678/capacitor-power-supply.

26 | P a g e

Appendix A
The following Table A1 shows the relationship between the impedance of the humidity sensor and relative humidity of the environment. The humidity is also dependant on temperature.
Table A1 Relative Humidity Look-up Table

I|Pa ge

Appendix B
The following is the source code used sensor unit design. #include <htc.h> #pragma config CCP2MX = OFF; #include <math.h> __CONFIG(1,XT); int counter1=0;//Overflow counter int counter=0;//Overflow counter int a=0; int values[6]; void WriteSegment(int num,int display ); //FUNCTION PROTOTYPE void ADCInit(); unsigned int ADCRead(unsigned char ch); //Connection of Seven segment display

#define SEVEN_SEGMENT_LAT PORTD #define SEVEN_SEGMENT_TRIS TRISD

unsigned int val; //ADC Value unsigned int h; //ADC Value unsigned int t; int i=0; //Temperature

//Function to Initialise the ADC Module void ADCInit() { //We use default value for +/- Vref

//VCFG0=0,VCFG1=0 //That means +Vref = Vdd (5v) and -Vref=GEN

//Port Configuration //We also use default value here too //All ANx channels are Analog

II | P a g e

/* ADCON2

*ADC Result Right Justified. *Acquisition Time = 2TAD *Conversion Clock = 32 Tosc */

ADCON2=0b10001010; }

unsigned int ADCRead(unsigned char ch) { if(ch>13) return 0; //Invalid Channel

ADCON0=0x00;

ADCON0=(ch<<2); //Select ADC Channel

ADON=1; //switch on the adc module

GODONE=1;//Start conversion

while(GODONE); //wait for the conversion to finish

ADON=0; //switch off adc

return ADRES; } void WriteSegment(int num,int display ) { RE0=0; RE1=0; RE2=0; RC0=0; RC3=0; III | P a g e

RC4=0;

switch (num) { case 0: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B00000001; break;

case 1: //-GFEDCBA

SEVEN_SEGMENT_LAT = 0B01001111; break;

case 2: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B00010010; break;

case 3: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B00000110; break;

case 4: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B01001100; break; IV | P a g e

case 5: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B00100100; break;

case 6: //-ABCDEFG SEVEN_SEGMENT_LAT = 0B00100000; break;

case 7: //-ABCDEFG SEVEN_SEGMENT_LAT = 0B00001111; break;

case 8: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B00000000; break;

case 9: //-ABCDEFG

SEVEN_SEGMENT_LAT = 0B00000100; break;

} switch (display) { // RE0,RE1,RE2,RC0,RC3,RC4

V|Pa ge

case 0: RC3=1; break;

case 1: RC4=1; break;

case 2: RE2=1; break;

case 3: RC0=1; break;

case 4: RE0=1; break;

case 5: RE1=1; break; } } void main() {

TRISC=0x00; TRISB=0x00; TRISD=0x00; TRISE=0x00; PORTE=0x00; PORTC=0x00; //Setup Timer0 VI | P a g e

T0PS0=0; T0PS1=0; T0PS2=0;

ADCInit(); RC5=1; PSA=1; //Timer Clock Source is from Prescaler

T0CS=0;

//Prescaler gets clock from FCPU (5MHz)

T08BIT=1;

//8 BIT MODE

TMR0IE=1; PEIE=1; GIE=1;

//Enable TIMER0 Interrupt //Enable Peripheral Interrupt //Enable INTs globally

TMR0ON=1;

//Now start the timer!

PR2 = 0b00000000 ; T2CON = 0b00000111 ; CCPR1L = 0b00000000 ; CCP2CON = 0b00011100 ; while(1); } //Sit Idle Timer will do every thing!

//Main Interrupt Service Routine (ISR) void interrupt ISR() { //Check if it is TMR0 Overflow ISR if(TMR0IE && TMR0IF) { //TMR0 Overflow ISR counter++; counter1++; if(counter1==4000) { VII | P a g e //Increment Over Flow Counter

val=ADCRead(0); //Read Channel 0 t=round(val*0.48876)-14;//Convert to Degree Celcius values[0]=(t/10); values[1]=(t%10); h=65; if (t>35) { h=70; } if (t<25) { h=60; } values[2]=(h/10); values[3]=(h%10); counter1=0; } WriteSegment(values[a],a); a++; if (a==4) a=0; //Reset Counter

//Clear Flag TMR0IF=0; } }

VIII | P a g e

You might also like