46
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

208502448P3

Embed Size (px)

Citation preview

Page 1: 208502448P3

Building Environment Controller

By

I BassaGroup 5

208502448

Supervisor

Dr A L L Jarvis

Electronic Design 3 Phase 3 Report

School of Electrical, Electronic and Computer Engineering

Page 2: 208502448P3

AbstractThis 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 module is 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

Page 3: 208502448P3

DeclarationI 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

Page 4: 208502448P3

Table of ContentsAbstract................................................................................................................................................. ii

Declaration........................................................................................................................................... iii

1. Introduction...................................................................................................................................1

2. Module Allocation.........................................................................................................................2

3. Integration of ‘X-10’ Modules........................................................................................................3

4. Top-Down Design..........................................................................................................................4

5. Sensor Unit....................................................................................................................................5

5.1. X-10 Communication Protocol...............................................................................................5

5.1.1. Zero-Crossing Detector..................................................................................................5

5.1.2. 120 kHz Carrier Generator.............................................................................................5

5.1.3. ‘X-10’ Addressing...........................................................................................................6

5.2. Temperature Sensing.............................................................................................................8

5.3. Humidity Sensing...................................................................................................................8

5.4. Display.................................................................................................................................10

5.5. Microcontroller....................................................................................................................11

5.6. IR Beam People Counter......................................................................................................12

5.6.1. Transmitter Circuit.......................................................................................................12

5.6.2. Receiver Circuit............................................................................................................13

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

5.7.1. Original Design.............................................................................................................14

5.7.2. Transformer Power Supply Design...............................................................................14

6. Other X-10 Modules....................................................................................................................16

6.1. Central Control Unit.............................................................................................................16

6.2. Fire Detection Unit...............................................................................................................16

6.3. Load Appliance Controller...................................................................................................16

7. Sensor Module Schematic...........................................................................................................17

8. Printed Circuit Board Design........................................................................................................18

9. Prototyping..................................................................................................................................19

9.1. Temperature........................................................................................................................19

9.2. Humidity..............................................................................................................................19

9.3. People Counter....................................................................................................................20

9.4. ‘X-10’ Communication.........................................................................................................20

10. Software Design.......................................................................................................................21

11. Future Enhancements..............................................................................................................23

12. Conclusion...............................................................................................................................24

References...........................................................................................................................................25

Appendix A............................................................................................................................................. I

iv | P a g e

Page 5: 208502448P3

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

v | P a g e

Page 6: 208502448P3

1. IntroductionThe 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 the complete 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 | P a g e

Page 7: 208502448P3

Table 1 Module Allocations

Module Allocation Group Member

Central Control Module Ayesha Saeed

Sensor Module Irshad Bassa

Fire Detection ModuleImraan Vawda

Load Appliance Module Wayne Frederick

2 | P a g e

Page 8: 208502448P3

2. Integration of ‘X-10’ ModulesThe 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 | P a g e

Page 9: 208502448P3

3. Top-Down DesignThe Sensor Unit is responsible for measuring temperature and humidity. It also measures how many people are present in a room at any particular time by the use of IR beam sensors. It then relays the information to the main controller via the X-10 communication system. The top-down design of the sensor unit is shown below.

Figure 3 Top-Down Design of Sensor Module

4 | P a g e

Sensor Module

MicrocontrollerPIC 16F877XA

Display

4 Multiplexed Seven Segment

Display

People Counter

IR Beam

Humidity

HCZ-H8 Sensor

Temperature

LM 35 Sensor

Power Supply

Transformerless Power Supply

CommunicationProtocol

X-10 Protocol

120kHz CarrierDetector

120kHz CarrierGenerator

Zero-CrossingDetection

Page 10: 208502448P3

4. Sensor Unit

4.1.X-10 Communication ProtocolThe “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 zero-crossing 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 DetectorThe 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=30µA 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:

Rac=V PeakIPeak

Eq. 1

Rac=√2×220V30 μA

Rac ≈10MΩ

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 GeneratorThe 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 100µF which is X2 rated was chosen for 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 | P a g e

Page 11: 208502448P3

Q1

BC547C

C1

100uF

R1

1MΩ

VCC5V

R2

50Ω

VCC 1

R3

200Ω

3

V1

220 Vrms 50 Hz 0°

2

0

4CCP2

Figure 4 120 kHz Carrier Generator Circuit

4.1.3. ‘X-10’ AddressingAddressing is an extremely 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.

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 in Table 2.

6 | P a g e

Unit Address Function Code

Suffix(1 bit)

Key Code(4 Bits)

House Code(4 bits)

Start Code (4 bits)

Unit Address

Page 12: 208502448P3

Table 2 Addressing of various modules

Message Type House Code Key Code Suffix

Unit Address Function Code

Central Control Unit Address 0 1 1 0 0 1 1 0 - - - - 0

Load Appliance Address 1 1 1 0 0 1 1 0 - - - - 0

Fire Detector Address 0 0 1 0 0 1 1 0 - - - - 0

Sensor Module Address 1 0 1 0 0 1 1 0 - - - - 0

Load On Command 1 1 1 0 - - - - 0 0 1 0 1

Load Off Command 1 1 1 0 - - - - 0 0 1 1 1

Load Brighter Command 1 1 1 0 - - - - 0 1 0 1 1

Load Dimmer Command 1 1 1 0 - - - - 0 1 0 1 1

Fire Detected Command 0 1 1 0 - - - - 0 0 0 0 1

Empty Room: Lights off Command 0 1 1 0 - - - - 0 0 0 0 1

Entered Room: Lights on Command 0 1 1 0 - - - - 0 0 0 1 1

Switch on AC 0 1 1 0 - - - - 0 0 1 0 1

Switch off AC 0 1 1 0 - - - - 0 0 1 1 1

7 | P a g e

Page 13: 208502448P3

4.2.Temperature SensingTemperature 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.25°C 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.

U1

LM35

VsGND Vout

VCC5V

VCC0 1

AN0

Figure 5 LM35 Temperature Sensor Circuit

4.3.Humidity SensingHumidity 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 | P a g e

Page 14: 208502448P3

V1

1kHz 5 V

XSC1

A B

Ext Trig+

+

_

_ + _U1

741

3

2

4

7

6

51

VCC5VVCC

R1

2kΩR2

10kΩ

R3

2kΩ

3

VEE-5V

VEE

4

1

GNDGND

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

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 10µF. 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.

I 1=V 2−V 1RSeries

The resistance of the sensor RSensor can then be measured:

9 | P a g e

Page 15: 208502448P3

RSensor=V 2I 1

GND

Rseries

100kΩ Rsensor

50%

GND

V1 V2

1kHz ACSignal 2Vpp

I1

3

AN2AN1

C1

10uF

21

Figure 9 Humidity Sensor Circuit

4.4. DisplayThe 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.

Figure 10 Multiplexed Seven Segment Displays

10 | P a g e

Page 16: 208502448P3

4.5.MicrocontrollerThe 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 Value

Operating Voltage 5V

External Interrupt 3

Digital Outputs 14

Timers 4

PWM Output 2

Analogue Inputs 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

MicrocontrollerOperating

VoltageExternal

InterruptsI/O Pins ADC Timers PWM Price1

PIC 16F877A 5V 1 3310

Channel 3 1 R47.95

PIC 16F887 5V 1 3310

Channel 3 1 R35.95

PIC 18F4520 5V 3 3313

Channel 4 2 R46.70

PIC 18F458 5V 3 338

Channel 4 2 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 11 below.

1 Price from Mantech Electronics as of 28th March 2011

11 | P a g e

Page 17: 208502448P3

Figure 11 Pin Diagram of PIC 18F4520 [10]

4.6.IR Beam People CounterThe 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.

Figure 12 IR Beam Sensors

The IR Beam Sensor consists of two circuits, a transmitter and receiver circuit.

4.6.1. Transmitter CircuitThe 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

Page 18: 208502448P3

Rout=5−1.35I out

Rout=3.65V0.18 A

Rout ≈22Ω

1.5kΩR1

18kΩR2

1nFC

7

4

5VVs

VCC

VCC

OUT

555_TIMER_RATEDTimer

GND

DIS

RST

THR

CON

TRI

Rout

22Ω

1

LED1 LED2

2

0

Figure 13 Transmitter Circuit

4.6.2. Receiver CircuitThe TSOP4838 IR Receiver Sensor is used to implement the receiver circuit. The sensor receives the 38 kHz 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.

Figure 14 Block Diagram of Receiver Sensor [13]

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

Page 19: 208502448P3

Figure 15 IR Beam Circuit [13]

4.7.Power Supply

4.7.1. Original DesignSince 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 Power Supply

4.7.2. Transformer Power Supply DesignThe 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

Page 20: 208502448P3

Figure 17 Transformer Power Supply

15 | P a g e

Page 21: 208502448P3

5. Other X-10 Modules

5.1.Central Control UnitThe 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 Receiver Circuit

5.2.Fire Detection UnitThe 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 SMS notification would be sent to the user via a GSM module.

5.3.Load Appliance ControllerThe 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

Page 22: 208502448P3

17 | P a g e

Page 23: 208502448P3

6. Sensor Module SchematicThe 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.

18 | P a g e

Page 24: 208502448P3

U1PIC18F4520

1234567891011121314151617181920 21

22232425262728293031323334353637383940

U2

A B C D E F G

CA

U3

A B C D E F G

CA

U4

A B C D E F G

CA

U5

A B C D E F G

CA

Q2

BC558B Q3

BC558B

Q4

BC558B

Q1

BC558B

VCC5V

U6

A B C D E F G

CA

U7

A B C D E F G

CA

Q5

BC558B

Q6

BC558B

RD6RD5RD4

RD3RD2

RD1

RD0

RC4RC3

RC0

RE2

RE1

RE0

1918

12

1110

8

12

34

57

6

913

14

15

16

17

Display

U8

LM35

VsGND Vout

AN0 20

TemperatureC1

470uF

Rseries

100kΩ Rsensor

50%

V1V2

I1 AN2AN1

2322

Humidity

U9

LM7660

1234 5

678C2

10uF

24

25

C31uF

-5V

Negative Rail

J1

HDR1X4

V1

311 Vrms 50 Hz 0°

R1

10MΩ

28

2930

31U10

741

3

2

4

7

6

51

R24kΩ

R3

10kΩ

R4

2kΩ

32

26

21

AC Signal

33

Zero-Crossing

Q7

BC547C

C4

100uF

R5

1MΩ

R6

50Ω

R7

200Ω

CCP236

35

38

27VCC

0

120kHz Generator

Sensor Module

J2

HDR1X3J3

HDR1X3

34

37

C54.7uF

39

40

INT1

INT2

IR BEAM A

IR BEAM B

IR Beam Sensor

Figure 19 Sensor Module Schematic

19 | P a g e

Page 25: 208502448P3

7. Printed Circuit Board DesignThe 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

20 | P a g e

Page 26: 208502448P3

8. PrototypingBefore 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.TemperatureThe 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 3°C. This was measured by a thermometer. This error was corrected in programming by offsetting the measured value.

8.2.HumidityThe 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.

21 | P a g e

Page 27: 208502448P3

Figure 23 PWM output from CCP1

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 CounterThe 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’ CommunicationThe ‘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.

22 | P a g e

Page 28: 208502448P3

9. Software DesignThe programming language chosen to implement the sensor module was C programming language, 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 .

While (1)

Initialise Registers

Start

Figure 25 Main Program Flow Chart

Current Display=i+1

CurrentDisplay=6?

(i=6)

Start

Current Display=1T

F

Display Value

Figure 26 Timer 0 Interrupt for Seven Segment Displays

23 | P a g e

Page 29: 208502448P3

Figure 27 INT0 Flowchart

F

j=j+1

Buffer[j]=1

Buffer_Empty=1

Start

T End

T Output PWM 1ms

Figure 28 Function Send_Data()

24 | P a g e

Page 30: 208502448P3

10. Future EnhancementsBy 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.

25 | P a g e

Page 31: 208502448P3

11. ConclusionThe 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.

26 | P a g e

Page 32: 208502448P3

References1. 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/amended-occupational-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=en011013.

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. Unknown. 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.frontline-electronics.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. Unknown. 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.

27 | P a g e

Page 33: 208502448P3

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.

21. Burroughs, Jon. X10 Home Automation. Electronics Project Design. [Online] 1 May 2010. [Cited: 23 February 2011.] http://www.electronics-project-design.com/cgi-bin/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.

28 | P a g e

Page 34: 208502448P3

Appendix AThe 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 | P a g e

Page 35: 208502448P3

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; //Temperature

int i=0;

//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

II | P a g e

Page 36: 208502448P3

//All ANx channels are Analog

/*

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;

III | P a g e

Page 37: 208502448P3

RC0=0;

RC3=0;

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

IV | P a g e

Page 38: 208502448P3

SEVEN_SEGMENT_LAT = 0B01001100;

break;

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 | P a g e

Page 39: 208502448P3

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;

VI | P a g e

Page 40: 208502448P3

PORTC=0x00;

//Setup Timer0

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; //Enable TIMER0 Interrupt

PEIE=1; //Enable Peripheral Interrupt

GIE=1; //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++; //Increment Over Flow Counter

counter1++;

VII | P a g e

Page 41: 208502448P3

if(counter1==4000)

{

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; //Reset Counter

}

WriteSegment(values[a],a);

a++;

if (a==4) a=0;

//Clear Flag

TMR0IF=0;

}

}

VIII | P a g e