Vous êtes sur la page 1sur 75

Wireless Sensor Network

Author: Law Che Hang Anthony

Student I.D.: 03645542

Supervisor: Professor K.K. Cheng

Associate Examiner: Professor K.N. Leung

A project report presented to the


Chinese University of Hong Kong
in partial fulfillment of the
Degree of Bachelor of Engineering

Department of Electronic Engineering


The Chinese University of Hong Kong
April 2007
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Abstract

Wireless Sensor Network has become one of the hot topics nowadays. Indeed, it

has been already applied in the use of many different areas. Such as the Home

Automation, it is very common to find its use on the lighting control and security

alarming. It does improve a lot on the people’s living quality with a more

convenient environment.

In order to understand how this “Smart Innovative Technology” works, a study of

the Wireless Sensor Network has been carried out in this project. And the Study

is divided into two main parts, which are:

1. The Study on a Wireless Communication Network: To understand how a

wireless communication network works. A communication method of using a

pair of simple transmitter and receiver is to be studied and built.

2. The Study on Sensor: To understand how a sensor functions. An Occupancy

Sensor (PIR Movement Sensor) is built and on studying in this project.

In this report, it is going to illustrate the results of the studies mentioned above

and to suggest a simple application of the Wireless Sensor Networks on Home

Automation.

1
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Acknowledgement

I would like to take this opportunity to sincerely show my gratitude to my

supervisor, Prof. K.K. Cheng, Department of Electronic Engineering, for giving

me guidance and support. He has given me valuable suggestions on the

development of my system in this project.

Also, I would like to thank my project associate examiner, Prof K N Leung,

Department of Electronic Engineering, for assessing my project.

Besides that, I would also like to thank the technician of Microwave Laboratory,

Mr. Leo Fung, for his help on ordering the RF kit for the project in the previous

semester.

Moreover, I would like to thank my fellow classmates Mr. Tang Kwok Kai and Mr.

Hui Cheung Ling for giving me advice and technical supports on building the

PCB Layouts. Finally, I would like to thank all the fellow classmates those who

work with me in the laboratory throughout the days and nights in these few

months for their spiritual supports.

2
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Contents

1. Introduction…………………………….…………………………………………. 6

1.1 What is Wireless Sensor Network? ……………………………………….…….6

1.1.1 Living in Smart Environment …………………………………………………..6

1.1.2 Realization of Smart Environment ………………………………………......6

1.1.3 Wireless Sensor Network actually is ………………………………………...7

1.2 Where Wireless Sensor Network can be found? …………………………….8

1.3 Specification of the System Design ……………………………………………..9

1.3.1 Brief Introduction of the System ……………………………………………….9

1.3.2 Brief Descriptions of System Components ………………………………..10

2. Background Theory ………………………………………………………….….11

2.1 Wireless Communication Network ……………………………………………..11

2.1.1 What should be considered?.................................................................. 11

2.1.2 What should be adopted? …………………………………………………..13

2.2 Occupancy Sensor ………………………………………………………………13

2.2.1 What is Occupancy Sensor? …………………………………………………13

2.2.2 Method of Operation …………………………………………………………14

2.2.3 What is passive infrared sensing? …………………………………………14

2.2.4 How passive infrared sensing works? ……………………………………..15

3
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3. Paper Design …………………..................................................................... 19

3.1 Wireless Communication ………………..………………………………….…. 19

3.1.1 Transmitting Unit (Sensor Node) ………...…………………………………. 19

3.1.1 Component 1 – Microprocessor ….………………………………………… 21

3.1.1 Component 2 – RF Transmitting module ………………………….………. 24

3.1.1 Component 3 – LCD Display (optional)…………………………….………. 29

3.1.2 Receiving Unit (Coordinator)………………………………………………… 29

3.1.2 Component 1 – Microprocessor …..…...…………………………………… 31

3.1.2 Component 2 – RF Receiving module……………………………….…….. 32

3.1.2 Component 3 – LCD Display module ...……………………………………. 37

3.1.3 Whole Implementation ……………………………. ………………...……… 37

3.1.4 Remarks ……………………………….. ……………………………………. 38

3.2 PIR Movement Sensor……………………………………………….………… 39

3.2.1 PIR sensor (RE200B)………………………………………………………… 39

3.2.2 Control Unit (KC788B) ………………………………………………………..40

3.2.3 Control and Output Circuit Description ……………………………………..45

3.2.4 Required Components for Modified Circuit…………………………….….. 47

4
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4. Experimental Results ………………………………………………………….. 48

4.1 Testing with Wireless Communication ………………..……………………….48

4.1.1 Testing on Transmitting Unit …...…………………………………………….48

4.1.2 Testing on Receiving Unit …………………………………………………... 51

4.2 Testing the PIR Movement Sensor …………………………………………… 53

4.2.1 Testing Case 1 with Daylight ……….………………………………………. 54

4.2.2 Testing Case 2 with Daylight .............................................................…... 55

4.2.3 Testing Case 3 at Night …………………………...………………………… 56

4.2.4 Testing Results form the previous 3 situation ………………………..…… 57

5. Cost Summary …..………………...….………………………………………… 58

6. Discussion ………………….. …………………………….……………………. 59

6.1 Wireless Communication .....................................................................…... 59

6.2 PIR Movement Detector ……………………………………………………….. 62

7. References ……………………………..........…………………………….……. 63

8. Appendices – Software Coding ……………………………………………… 64

5
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

1. Introduction

1.1 What is Wireless Sensor Network?

1.1.1 Living in Smart Environment

Have you ever dreamt of living in a Smart Environment, which it enhances your

living qualities with all kinds of intelligent automation devices or services? If “Yes”,

then your next question will surely be “How can we get it to be realized?” To

answer this question, very strict forward, I would say that the application of

Wireless Sensor Network is a solution to the realization of Smart Environment.

1.1.2 Realization of Smart Environment

In fact, like any responsive organism, the Smart Environment [1] relies first on

the sensory data from the actual world. Sensory data are obtained from

numerous different sensors of distributed locations. The Smart Environment

does need information about its surroundings in order to generate the

corresponding output regarding to respective changes. The wireless Sensor

Network has exactly taken this sensing role to fulfill the needs of information for

this purpose. It acts as the first stage to realize the development of Smart

Environment. So, your following question will be “What the Wireless Sensor

Network actually is then?”

6
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.1

1.1.3 Wireless Sensor Network actually is

Have you ever imagined thousands of sensors are installed in a specified area

and they are all well coordinated in a network without the data transmission jam?

Indeed, it is the exact case for Wireless Sensor Network. These sensors of

different modalities detect the physical changes, like temperature, humidity and

light intensity, and generate corresponding data signal. The data are then sent,

through the network, to the coordinator for processing. The coordinator manages

and controls the sensing data flow in the communication network. Therefore, the

data received at coordinator can then be used for further applications.

7
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

1.2 Where Wireless Sensor Network can be found?

Actually, Wireless Sensor Network has already been widely used in different

areas for current development. Applications [2] include:

1 Habitat monitoring: such as the monitoring of water/ air pollution and the

temperature/ humidity measurement.

2 Military use: like the monitoring the actual battle condition by installing the

sensor on the army and weapons.

3 Biomedical use: such as collecting the physiological data from human body

or medical diagnosis.

4 Home automation: for example, lighting control and security alarming

5 Other Commercial applications: like product quality control on the

manufacturing production.

8
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

1.3 Specification of the System Design

1.3.1 Brief Introduction of the System

In this project, it is aimed to demonstrate the application in the area of Home

Automation. Among the applications in this area, a simple function of lighting

control is going to be implemented. The system work flow is as following:

1. To sense if there are anybody presence or absence in a specified area.

2. To transmit the sensing data back to the coordinator through a network.

3. Coordinator processes the received data and identifies if matched with the

predefined criteria according to the needs of user.

4. If the criteria are matched, for instance, a body presence in the area,

coordinator will send command to the lighting control unit to switch light on.

5. On the other hand, if nobody presence in the area for a period of time,

coordinator will send command to the lighting control unit to switch light off

Therefore, the system can perform a lighting control function where the light on

whenever anybody presence, while the light off if nobody presence for a period

of time so as to save the power consumption.

9
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

1.3.2 Brief Descriptions of System Components

There are three main components in the system to build the application of

wireless sensor network up to the current development stage of the project,

which are:

1. Occupancy Sensor: The sensor unit of the system. It is responsible to sense

if there are anybody presence or absence in a specified area and generate

sensing data ready for the coordinator to process and further application.

2. Wireless Communication Network: The communication channel between

devices of the system. It is responsible to transmit the sensing data or the

commands to and from different devices in the system.

3. Coordinator: The headquarter unit of the system. It is responsible to control

and monitor the data transmission in between devices of the system. It also

processes the received sensing data from the sensing unit and, regarding to

the processed result, outputs correspondingly, like light on/ off.

There should also be the lighting control unit, the application use, in the system.

However, it is not yet built up to the current development stage and may be built

in future development if possible.

10
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

2. Background Theory

Before going into any details of the system design, some background principles

and consideration of the components of the system will be discussed in this

section.

2.1 Wireless Communication Network

2.1.1 What should be considered?

Obviously, there are plenty of wireless communication standards available in the

current market, such as Bluetooth, Wi-Fi, which are the most common ones.

However, are they suitable for building the communication network of Wireless

Sensor Network? There are indeed some specific requirements for the wireless

sensor network. Let’s consider the following factors first and see if the mentioned

standards are suitable or not.

1. Scalability [3]: The network has to be scalable, which means it can

support up to as much larger number (thousands, hundreds of

thousands) of entities. Therefore, numerous sensors can be installed in

the network and be able to monitor the region more efficiently.

11
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

2. Energy Consumption [3]: The battery of the sensor node (sensing units)

is usually not rechargeable. Thus it is important to minimize the power

consumption and prolong the sensor lifetime as the system cannot

function properly without the sensing units.

3. Simplicity[3]: As the sensor nodes (sensing units) are small and power

supply is so limited, the operating and networking software must be kept

orders of magnitude simpler as compare to today’s desktop computers.

With the factors mentioned above, let’s consider the comparison of current

available wireless communication standards as listed below:

Figure.2

12
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

2.1.2 What should be adopted?

It is observed that neither the Bluetooth nor Wi-Fi would be suitable to be used in

Wireless Sensor Network. Comparing with the Zigbee standard in the above

table, regarding to their performance on scalability, power consumption and

simplicity, they are far worse than that of the Zigbee standard. Indeed, the

Zigbee has become the most commonly adopted network communication

standard in the wireless sensor system on the current development or research.

However, this project is not implementing the Zigbee. Instead, it establishes a

system with similar property of power conservation as what it is in the standard.

2.2 Occupancy Sensor

2.2.1 What is Occupancy Sensor?

Occupancy sensor [4] is a device that responds to the presence and absence of

anybody in the sensor's field of view. The system consists of a motion detector,

an electronic control unit, and a controllable switch, where, in the system, there

is a wireless communication network in between the control unit and controllable

switch. The motion detector senses motion and sends the appropriate signal to

the control unit. The control unit then processes the input signal and output a

corresponding signal to either switch the responsive device on/ off.

13
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

2.2.2 Method of Operation[5]

In today’s markets, there are two commonly used methods / approaches for the

operation of Occupancy Sensor. They are the Passive Infrared sensing method

and the Ultrasonic wave detection method. This project will focus on the Passive

Infrared sensing method.

2.2.3 What is passive infrared sensing?

Passive infrared (PIR) sensors [6] react to the infrared heat energy emitted by

the human body. PIR sensors are passive devices in that they only detect

radiation and do not emit it. They are designed to be maximally sensitive to

objects which emit heat energy at a wavelength of around 10 microns (the peak

wavelength of the heat energy emitted by humans).

PIR sensors are strictly line-of-sight devices. They cannot "see" around corners

and a person will not be detected if there is an obstruction, such as a partition,

between the person and the detector.

14
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

2.2.4 How passive infrared sensing works?

PIR sensors employ a pyroelectric transducer [6] to detect infrared radiation. The

device converts the IR energy into a voltage signal. (See the figure below)

Figure.3

1. An infrared filter window at the front most position of the transducer admits IR

within the 5 to 15 microns wavelength range

2. One end of the two series-connected sensing elements connected to pin 3

which is grounded.

3 Meanwhile, the other end connects to the gate of a Field Effect Transistor

and to a very high value pull-down resistor

4 Power is applied to the FET thus to the drain pin 1

5 Output signal comes from FET source pin 2 usually connects through an

external pull-down resistor to ground and to an amplifier (See the following

figure)

15
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.4

A Fresnel lens, a focusing device, surrounds the transducer and focuses heat

energy onto the detector. The lens views the area with a multitude of narrow and

discrete beams or cones. As such, it does not view the area in a continuous

fashion. As an occupant, moves a hand, arm, or the whole body from one cone

of vision to another, a positive signal is generated and sent to the controller.

(See the figure below)

Figure.5

16
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

The detection pattern [5] of PIR sensors is fan shaped -- formed by the cones of

vision seen by each segment of the faceted lens.

Figure.6

As shown in above figure, coverage gaps occur between the cones of vision of

alternate segments of the lens. These gaps widen with distance. At 40 feet from

the sensor, for instance, coverage gaps of up to 8 feet wide may be present.

Since the sensor is most sensitive to motion that moves from one sensing cone

to another, its sensitivity decreases with distance as the gaps between sensing

cones widen.

17
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Most PIR sensors are sensitive to hand movement up to a distance of about 10

feet, arm and upper torso movement up to 20 feet, and full body movement up to

about 40 feet.

Regarding to the above data, it is surprising that the sensing range of that little

PIR sensor can be so large. Because of this reason, the PIR sensor is used to

act as the sensing unit to detect anybody presence or absence in a specified

area. Thus, a large area can be restricted to be our specified sensing region as

soon as the PIR sensor is able to detect the movement.

18
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3. Paper Design

3.1 Wireless Communication

In a Wireless Communication Network, however large it is, the Network is also

built up of basically the transmitting unit and receiving unit. Undoubtedly, it is the

same for the system in this project. For Simplicity, there will be two transmitters

(for sensor node) and one receiver (for coordinator node) in the Sensor Network

of this project.

And as mentioned in the previous “Background Theory” section, the adopted

Communication Network for Sensor network has to be power conserving, so as

to be long-lasted functioning. Thus, this concept is also included in the design of

communication network.

3.1.1 Transmitting Unit (Sensor Node)

Combining with the circuitry of Sensing unit, it acts as the sensor node of the

Sensor Network. It is responsible to transmit data from the sensing unit (motion

detector) to the coordinator for process. The Unit is mainly composed of several

components: a Microprocessor, a RF Transmitting Module and a LCD display

(optional). (See the following Schematic Diagram)

19
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Schematic Diagram of Transmitting Unit

Figure.7

20
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.1 Component 1 - Microprocessor (PIC16F877A)

The Microprocessor (PIC16F877A) is adopted for several main purposes as the

following descriptions:

- 1. Process data from the sensing unit, motion detector

The pin PIR_sense is connected to the output terminal of the circuitry of the

Motion Detector sensing unit. When this pin goes to “low”, it means that there is

an output, motion detected, from the sensing unit and vice versa.

21
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

The microprocessor then counts the time for how long the “motion detected”

state keeps continuously. The status is defined as valid if the time lasted for

more than at least 1 second and invalid if vice versa. This decision making aims

to avoid any fake-sensing from the surrounding environment.

- 2. Control power on/off of the RF Transmitting unit

The pin RF_Control is connected to the above circuitry in order to control the

power on/off of the RF Transmitting module. When this pin goes “high”, the

transistor BC547 is turned on and current flow through the transistor. The

collector voltage then equals to that of emitter which is connected to ground.

Thus, the potential at the point of RF_Power connected to the power supply of

the Transmitting unit will be low. It means to switch off the transmitting unit.

On the other hand, when this pin goes “low”, the transistor BC547 is turned off

and no current flow through the transistor. The collector voltage then equals to

22
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

that of VCC (+5V). Thus, the potential at the point of RF_Power connected to the

power supply of transmitting module is high and turn on the transmitting module.

Therefore, power can be saved for long running of the sensor node. As the

transmitter is turned on only when there is motion detected and is not always

kept as on. It builds the property of power conservation as the consideration for a

sensor network mentioned in the “Background Theory” section previously.

- 3. Output acknowledgement to RF transmitting module

The pins RC0 – RC3 are connected to the data input pins RF13 – RF10 of

transmitting unit respectively. The 4-bit acknowledgement data, 0b1010, is

output when the state is changed to “motion detected” only. And this data will

then be encoded by the transmitting module and transmitted out afterward.

- 4. Control character display on the LCD module (coding)

In order to configure and display the characters on the LCD correctly, it is

necessary to input corresponding instruction data to the LCD module. The

microprocessor is thus the unit to give the according instruction data to the LCD

module for displaying the status of the sensor node

23
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.1 Component 2 - RF Transmitting module (Operating at 315MHz) [7]

The unit mainly consists of an encoding IC PT2262. PT2262 is a remote control

encoder utilizing CMOS Technology. It encodes the preset address on its

address pins and data from microprocessor into a serial coded waveform

suitable for RF modulation before transmission. It has a maximum of 12 bits of

tri-state address pins providing up to 531,441 (or 312) address codes; thereby,

largely reducing any code collision and unauthorized code scanning possibilities

(See the internal structure and pin assignment as followings)

Figure.8

24
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.9

Pin Name I/O Description Pin No.

A0 – A7 I Code Address Pin. Each pin can be 1 - 8

set to “0”, “1” or “f” (floating).

D3 – D0 I Data pins. Each can only be set to 10 - 13

“0” or “1”.

/TE I Transmission Enable. 14

Active Low Signal

OSC1 O A resistor connected in between to 15

OSC2 I determine fundamental frequency 16

DOUT O Encoded waveform output to this pin 17

serially. Data Output pin.

VCC - + 5V Power Supply 18

VSS - GND Ground Connection 9

25
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.1 Component 2 - Function Description

PT2262 encodes the code address and data set at A0 ~ A7 and D3 ~ D0 into a

special waveform and outputs it to the DOUT when /TE is pulled to “0” (Low

State). This waveform is fed to the RF modulator for transmission. Details of the

operation are as followings:

- 1. Code Bits

A Code Bit is the basic component of the encoded waveform, and can be

classified as either an AD (Address/Data) Bit or a SYNC (Synchronous) Bit.

- Address/Data (AD) Bit Waveform

An AD Bit can be designated as Bit “0”, “1” or “f” if it is in low, high or floating

state respectively. One bit waveform consists of 2 pulse cycles. Each pulse cycle

has 16 oscillating time periods. (See the diagram below)

Figure.10

26
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

- Synchronous (Sync.) Bit Waveform

The Synchronous Bit Waveform is 4 bits long with 1/8 bit width pulse.

Figure.11

- 2. Code Word

A group of Code Bits is called a Code Word. A Code Word consists of 12 AD bits

followed by one Sync Bit. The 12 AD bits are determined by corresponding

states of A0 ~ A7 and D3 ~ D0 pins at the time of transmission.

When Data Type of PT2262 is used, the address bits will decrease accordingly.

For example: In the 3 Data Type where the address has 9 bits, the transmitting

format is:

Figure.12

PT2262 has a maximum of twelve (12) Address Bits including the six (6)

Address/Data bits, the code bits with their corresponding pins are as shown in

27
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

the following diagram:.

Figure.13

The Code Bits A0 ~ A5 and A6/D5 ~ A11/D0 are determined by the states of A0

~ A5 and A6/D5 ~ A11/D0 pins. For example, when the A0 (Pin No. 1) is set to

“1” (Vcc), the Code Bit A0 is synthesized as “1” bit. In the same manner, when it

(A0 Pin) is set to “0” (Vss) or left floating, the Code Bit A0 is synthesized as a “0”

or “f” bit respectively.

- 3. Code Frame

A Code Frame consists of four continuous Code Words. When PT2262 detects

“0” on the /TE (the /TE is active “low”), it outputs a Code Frame at DOUT.

Figure.14
If /TE is still active at the time the Code Frame transmission ends, PT2262

outputs another Code Frame. It should be noted that the Code Frame is

synthesized at the time of transmission.

28
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.1 Component 3 - LCD Display (optional)

The unit is just used for displaying the current status of the motion detector after

the data processing by the microprocessor. Without the LCD Display, the main

function of data transmission can actually still be carried out. Thus, the LCD

Display can be optional.

3.1.2 Receiving Unit (Coordinator)

The unit acts as the coordinator of the system. It receives acknowledgement

data transmitted from the sensor node (transmitting unit), then processes the

acknowledgement and displays the result accordingly from the receiving data.

This unit is mainly composed of several components: a Microprocessor, a RF

Receiving Module and a LCD display. (See the following Schematic Diagram)

29
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Schematic diagram of Receiving Unit

Figure.15

30
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.2 Component 1 - Microprocessor (PIC16F877A)

The processor PIC16F877A is adopted for several purposes as the following

descriptions:

- 1. Process Acknowledgement from receiving data

As the received data at the RF receiving module arrive at the microprocessor,

the microprocessor checks if it matches with the predefined acknowledgement

messages. It gives a positive response if the checking is matched and does not

give any responses at vice versa.

31
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

-2. Control character display on the LCD module (coding)

When there is positive response, the microprocessor displays the result on the

LCD by giving corresponding instruction data to the LCD module. For example, it

displays “I AM HERE” when there is somebody present in the area.

3.1.2 Component 2 - RF Receiving Module (Operating at 315MHz) [7]

The unit mainly consists of an encoder PT2272 utilizing CMOS Technology. It

has 12 bits of tri-state address pins providing a maximum of 531,441 (or 312)

address codes; thereby, reducing any code collision and unauthorized code

scanning possibilities. The transmitted radio frequency is received by the RF

demodulator and reshaped to the special waveform. PT2272 is then used to

decode the waveform and set the corresponding output pin(s). (See the internal

structure and pin assignment as followings)

32
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.16

Figure.17

Pin Name I/O Description Pin No.

A0 – A7 I Code Address Pin. Each pin can be 1 - 8

set to “0”, “1” or “f” (floating).

D3 – D0 O Data pins. Each can only be set to 10 - 13

“0” or “1”.

33
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Pin Name I/O Description Pin No.

OSC1 I A resistor connected in between to 15

OSC2 O determine fundamental frequency 16

VT O Valid Transmission. 17

Active High Signal

VCC - + 5V Power Supply 18

VSS - GND Ground Connection 9

3.1.2 Component 2 - Function Description

PT2272 decodes the received waveform fed into the DIN pin. The Waveform is

decoded into code word which contains the address, data and sync bits. The

decoded address bits are compared with the address set at the address input

pins (A0 - A7). If both addresses match for 2 consecutive code words, PT2272

then drives – (1) the data output pin(s) whose corresponding data bit(s) is then

decoded to be a “1” & “0” bit, and (2) the VT output to high voltage (high state).

Details of Operation are as followings.

- 1. Code Bits

A Code Bit is the basic component of the encoded waveform, and can be

classified as either an AD (Address/Data) Bit or a SYNC (Synchronous) Bit.

34
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

- 2. Address/Data (AD) Bit Waveform

An AD Bit can be designated as Bit “0”, “1” or “f”, if it is in low, high or floating

state respectively. One bit waveform consists of 2 pulse cycles. Each pulse cycle

has 16 oscillating time periods. See the following diagram:

Figure.18

- 3. Synchronous (Sync.) Bit Waveform

The Synchronous Bit Waveform is 4 bits long with 1/8 bit width pulse.

Figure.19

- 4. Code Word

A group of Code Bits is called a Code Word. A Code Word consists of 12 AD bits

followed by one Sync Bit. See the diagram below:

35
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.2 Component 2 - Valid Transmission

When PT2272 receives a transmission code word, it initially checks whether this

is a valid transmission. For a transmission to be valid, (1) it must be a Complete

Code Word, and (2) the Address Bits must match the Address Setting at the

Address Pins.

After two consecutive valid transmissions, PT2272 (1) drives the data pins

according to the data bits received, and (2) raises VT to high voltage (high state).

The timings are shown in the following diagram.

Figure.20

36
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.1.2 Component 3 - LCD Display Module

Regarding to the instruction data from the microprocessor, the LCD module

displays the characters correspondingly. Indeed, the characters are arranged in

the ASCII chart. It means that all characters are displayed according to what

ASCII code is keyed into the module.

3.1.3 Whole Implementation

After all, whenever there are anybody present in a specified area, the motion

detector will be able to detect its motion. It gives out a sensing signal “motion

detected” (bit “0”) to the transmitting unit at its output terminal. The transmitting

unit then gets the signal from its PIR_sense pin and processes. It outputs the

acknowledgement data to the RF transmitting module. PT2262 then encodes the

data into predefined waveforms. And RF module transmits the waveforms at

315MHz over a distance.

37
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

As the receiving module received the transmitted waveforms, the decoder

PT2272 then validates and decodes the data if it is valid. As soon as the

decoded data arrives at the microprocessor, the corresponding output result will

be displayed on the LCD after processing. And the user current status of the

Sensor node (transmitting unit) can be viewed at the Coordinator (receiving unit)

finally.

3.1.4 Remarks

However, the lighting control unit has not yet been developed. And the

coordinator is just consisting of receiver unit, where it is not allowed to transmit

any control signal neither to the sensor node nor any control units yet. The

coordinator cannot control the lighting control system at the moment.

In the future development, apart from the construction of light control system, the

transceivers should also be implemented in the design if possible. The system

can, therefore, be developed to be more functional and efficient.

38
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.2 PIR Movement Sensor

As mentioned in the previous “Background Theory” section, the Occupancy

Sensor consists of three main components, which are the sensing unit, control

unit and the output unit. In the design of the PIR Movement Sensor of this

system, it is also the same case as that of the normal Occupancy Sensor. A PIR

sensor (RE200B) is chosen to be the sensing unit, a Master PIR Control Chip

MPCC (KC788B) is selected for control unit, while an output terminal will act as

the Output unit of the whole sensor system.

3.2.1 PIR sensor (RE200B)

It is in a package of T0-5 with dimension shown in the figure. There are two

sensitive elements with area of 2.0mm long, 1.0mm wide and are spaced in

1.0mm apart. As shown in the figure below

Figure.21 Figure.22

39
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

It can be operated at 3 to 10 V DC with its minimal signal output voltage at

around 2.5 Vp-p. For the field of view detected by the sensor, it is shown as

below:

Figure.23

3.2.2 Control Unit (KC778B)

The chip has been designed for easy implementation of AC control functions that

use a Passive Infra-Red (PIR) motion detector. Due to its high sensitivity and

reliability, it is also widely used in security product.

Figure.24

With most of the necessary components integrated in the chip, it allows the

minimum external components. It has high sensitivity and an off delay timer.

40
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.25 The above diagram shows the internal block structure of the chip.

41
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.26. Pin assignment of the Chip:

42
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.27 Original Schematics

43
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Figure.28 Modified Schematics

44
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.2.3 Control and Output Circuit Description

The heart of the circuit is the motion detection IC. Electrical signals from the PIR

sensor have a very low frequency (0.1 to 10Hz) and bandwidth. The IC is

optimized for this. The operating voltage of the KC778B itself is 4 - 15V. With the

78L05 regulator, voltage input should be in the 9V to 12V range. There are three

sensitivity controls built into the original circuit. (See the original schematic

diagram in the previous page)

1. Sensitivity is controlled at pin 2 by trimpot P1.

When this pin equals the sensor drain potential at pin 7 (about 0.5V) sensitivity is

at a minimum. When the pin 2 is connected to ground (about 0.125V), the

sensitivity is at maximum.

2. Daylight sensitivity using trimpot P2 and the LDR.

This is adopted when the sensor is designed to be inactive during the daytime

and only active at night. If this feature is not needed, the pin 12 should be

connected to Vcc and pin 11 should be left unconnected

3. Pulse on-time trimpot P3.

This adjusts the output pulse from between 1.5 seconds upwards. For the

minimum time delay, pins 18 & 19 are connected directly with no external

capacitor or resistor.

45
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

However, only two controls will be used after modification. They are the trimpot

P1 for Sensitivity adjustment and trimpot P3 for Pulse on-time adjustment. At the

meantime, the pin 12 is connected to Vcc and pin 11 is left unconnected. (See

the modified schematic diagram in the previous page.)

Pin 17 is also connected to an LED, LED1. This IC output always goes on when

the sensor & IC detect movement. But this trigger may result in an Output signal.

For example, the Output from the unit is off during the Daytime. There is also an

inbuilt latency period of about 1.5 seconds in the Output pulse when triggered.

This latency period is essential to smooth out the multiple trigger pulses actually

sensed by the detector (as shown by LED1.) There is an internal 500R resistor

on pin 17 so a current limiting resistor is not required.

The output signal from IC pin16 goes “high” whenever movement is detected. It

switches on the BC547 and current flow through the transistor. Its collector is

then becomes grounded as the emitter is connected to ground. Thus, it turns on

LED2 in original design as there is now potential difference across LED2.

Besides, it gives “low” to the OUTPUT in the modified circuit. And this signal will

be passed to the coordinator for processing.

46
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

3.2.4 Required Components for building the Modified Circuit

Resistors: Quantity
1K brown black red R8 R9 R10 3
3K9 orange white red R3 1
10K brown black orange R2 R5 R7 1
47K yellow violet orange R1 R6 1
56K green blue orange R4 1
Potentiometers
200K Koa trimpot 204 P1 1
1M Koa trimpot 105 P3 1
Capacitors
10uF mini elcap C3 1
10uF Low leakage elcap C5 1
100uF mini elcap C1 1
100nF 104 C2 C4 C6 C8 4
220pF ceramic 221 C7 1
4n7 ceramic 472 C9 1
470nF C10
Control Unit IC
KC778B Movement IC1 1
Transistors
BC547 transistor Q1 1
Voltage Regulator
78L05 IC2 1
1N4004 diode D1
Output Units
LED 1
Sensors
RE200B PIR sensor 1
Light Dependent Resistor LDR
Fresnel Lens 1

47
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4. Experimental Results

4.1 Testing with Wireless Communication

The Wireless Communication is mainly composed of the transmitting unit and

the receiving unit as what has been discussed in previous sections. Following

tests are carried out on investigating the individual performances of the

transmitting and receiving units

4.1.1 Testing on the Transmitting Units (Sensor Node)

Test Case 1 - No RF Transmitting Module installed

Without the RF Transmitting Module being placed, the Unit just consists of the

PIR motion detector, the microprocessor and LCD Display Module

Figure 29

48
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

The unit then performs like a Detector with a Display showing its current status

Figure 30

- When motion detected, the LCD displays as the above figure.

Figure 31

- When no motion detected, the LCD displays as the above figure.

Remarks: The display “I AM HERE” means that there are motions detected in

the specified area; the display “NOT HERE” means that there are any motions

detected in the area monitoring.

49
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Test Case 2 - RF Transmitting Module installed

With the RF Transmitting Module being installed, the Unit then consists of the RF

Transmitter, certainly, the PIR motion detector, the microprocessor and the LCD

Display Module

Figure 32

The unit is expected to perform as what has been stated in the “Paper Design”

section previously. It means that LCD displays the current status of whether any

motions are detected accordingly. At the mean time, the transmitter sends out an

acknowledgement signal.

Unfortunately, the performance is not as expected. State of “motion detected” is

kept showing on the LCD Display no matter there is motion nearby or not

50
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4.1.2 Testing of the Receiving Unit (Coordinator)

As stated before in the previous description, the Receiving unit consists of the

RF receiving module, a microprocessor and a LCD display.

Figure 33

At the same time, the transmitting unit is functioning in order to send out

acknowledgement signal to the receiving unit in the testing process. Although

the performance of transmitting unit is not as stable as expected, the tests can

still be regarded as valid. There are still acknowledgement data sent by the

transmitting unit depart its instability. Besides that, the receiving unit just displays

the result when there is acknowledgement received. The test can be carried out.

51
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Case 1 - When there is “motion detected” acknowledgement received

Figure 34

The Display shows the “motion detected” status

Case 2 - When no there is no “motion detected” acknowledgement received

Figure 35

The Display shows no motion detected status

The performance of the Receiving unit is stable and as expected

52
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4. Experimental Results

4.2 Testing the PIR Movement Sensor

The figure below shows the built PIR Movement Detector Circuit Board. It is built

according to the schematic shown in the section of “Background Theory”.

Figure.36

The PIR detector will be undergone a testing with same approaches, but three

different environment. The aim of this testing is to observe how far the detector is

able to detect the motion, i.e. the detection range. After that, comparing the

testing result to the general detection range of the common PIR detector on

market and see if the performance is satisfied or not.

53
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4.2.1 Testing Case 1 with Daylight

Testing Place: Hostel Corridor (Rectangular Closed Area)

Testing Object: Human Body (Full Body / Upper Body Movement)

Testing Method: Moving away from sensor till the point where the movement

cannot be sensed

Hostel Corridor

PIR Sensor
Length

. Figure.37

Width

54
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4.2.2 Testing Case 2 with Daylight

Testing Place: SHB 6th Floor Reading Area (Large Indoor Room)

Testing Object: Human Body (Full Body Movement)

Testing Method: Moving away from sensor till the point where the movement

cannot be sensed

SHB 6th Floor Reading Area

PIR Sensor
Length

Width

Figure.38

55
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4.2.3 Testing Case 3 at Night

Testing Place: Open Area at Hostel Ground Floor (Wild Open Area)

Testing Object: Human Body (Full Body Movement)

Testing Method: Moving away from sensor till the point where the movement

cannot be sensed

Open Area at Hostel Ground

Figure.39

56
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

4.2.4 Testing Results from the previous 3 situation are as following

Testing Result from case 1 at Hostel Corridor:

Body Movement Measured Length Measured Width

Measurement (60cm per square on the floor) (60cm per square on the floor)

21 x square 3 x square
Full body Movement
= 12.6 m = 1.8 m
Upper Half Body 12 x square 3 x square
Movement = 6.8 m = 1.8 m

Testing Result from case 2 at SHB 6th floor Reading Area:

Body Movement Measured Length Measured Width

Measurement (28cm per shoes) (28cm per shoes)

48 x square 46 x square
Full body Movement
= 13.4 m = 12.88 m

Testing Result from case 3 at the Open area of Hostel Ground floor

Body Movement Measured Length View Angle (Rough

Measurement (26cm per shoes) Observation only)

46 x square 140 deg when getting


Full body Movement
= 11.96 m close to the sensor

57
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

5. Cost Summary

The estimated cost of the system for demonstration purpose is listed below

tables, where it is mainly separated into two parts; the hardware for Wireless

Communication Network and the necessary components for PIR Movement

Detector circuit building.

Table 1: Hardware for Wireless Communication Network

Item Description Item Cost

Microprocessor x 3 HK$60

Transmitting module x 2
HK$40
Receiving module x 1

All Necessary components + LCD HK$25

Total Cost HK$125

Table 2: PIR Movement Detector Circuit

Item Descriptions Item Cost

All Necessary components HK$5

Fresnel lens, PIR Sensor, HK$75


Controller IC (KC778B)

Total Cost HK$80

58
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

6. Discussion

6.1 Wireless Communication

When testing the Wireless Communication and the PIR Movement Detector

individually, their performance is perfectly stable. After combining the Wireless

module with the Movement Detector on a circuit board together with their original

arrangements, the overall performance, however, becomes very unstable.

Problem encounter

After merging the wireless communication modules and the PIR movement

detector, the performance should be as expected as what has been stated in the

previous “Paper Design” section. It means that the sensor node would give the

“motion detected” signal only if there are any body motions being sensed as in

the design. Unfortunately, the actual result is that the detector gives out such

sensing signals abnormally. It gives the “motion detected” signal even there are

not any body motions in the sensing area.

Reason for the abnormal performance

The reason for this abnormal performance is actually because the ground

potential connected to the circuitry has become unstable after the wireless

59
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

communication module is merged with the motion detection circuit. And the

instability of overall ground potential is due to the long wired “ground” connection

between ports and the ground terminal. In the long connected wire, the RF signal

generated from the wireless module will impose some unwanted parasitic

potential along the wire connected. It then affects the original ground connection

on the ports in which the ground connection is no longer at ground potential (0V),

but an unknown potential imposed by the parasitic effect of the wired connection.

Possible solution to the Problem

To solve the encounter problem, one possible solution is using a ground plane

for ground connection instead of using a wire connecting in between the port and

the ground terminal. It can greatly reduce the distance of connection in between

the ground terminal and the ports. The ground potential (0V) can then be kept

constantly as there is no longer the parasitic effect of connection wire. Indeed, it

is also a usual practice of using ground plane for ground connection instead of

wiring between ports and the ground terminal for building any RF circuitry. As

shorter the ground connection it is, lesser the parasitic effect on ground potential

it imposes.

60
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

Further Possible Improvement

In the system, those two transmitting units are the only ones which are able to

talk/send out data to the other parties; but it cannot listen to/get the data from

others. Meanwhile, the receiving unit is the only one which is able to listen to/get

the data from other parties; but it cannot talk/send out data to others. It limits the

communication between the sensor nodes and the coordinator to be a kind of

single-way communication. The coordinator cannot take control on the sensor

nodes and request for those their current status at any time. It can just wait till

those sensor nodes send out the acknowledgement data only.

A better suggestion on the communication method is to implement a two-way

communication between the coordinator and the sensor nodes. To implement

the two-way communication between them, the network should no longer use

the pair of transmitting and receiving units. Instead, it should adopt the

transceiver as the communication module in between them. As the transceiver

can act both the functions of transmitting and receiving in a single module. The

coordinator can, thereby, be able to take control on the sensor nodes at any time

it requests. The current status update of sensor nodes can then be done more

efficiently and effectively.

61
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

6.2 PIR Movement Detector

After the testing in three different situations, it is observed that the detection

range of the built sensor is about 12m long which is about 40ft by calculation.

And this data does match to the previous mentioned range (40ft) for full body

movement in the section of “Background Theory”.

However, there is a big drawback for our PIR Movement Detector. It is the

problem of line of view. Whenever there is obstacle in between, then the sensor

cannot sense the moving body. Beside that, it cannot sense the body at round

corner. To solve this problem, there can be a mixed use with ultrasonic wave

detection method. As this method is less dependent to the line of view, thus it is

able to help enlarge the detection range afterward.

62
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

7. References

[1] – F. L. Lewis. “Wireless sensor networks”. In D. J. Cook and S. K. Das,

editors, Smart Environments: Technologies, Protocols, and Applications, New

York, 2004. John Wiley.

[2] – Akyildiz, W. Su, Y. Sankarasubramaniam, and E. Cayirci. “Wireless sensor

networks: a survey. “ Computer Networks, 38(4):393–422, April 2002

[3] – Holger Karl and Andreas Willig. “A short survey of wireless sensor

networks” TKN Technical Report TKN-03-018, Technical University Berlin,

October 2003.

[4] – Lighting design lab


http://www.lightingdesignlab.com/articles/occ_sensor/method_oper.htm

[5] – light guide: occupant sensors


http://www.lightsearch.com/resources/lightguides/sensors.html

[6] – How Infrared Motion Detector Components work


http://www.glolab.com/pirparts/infrared.html

[7] – Application notes of PT2262/2272 http://www.princeton.com.tw

63
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

8. Appendices – Software Coding


//////////////////////////////////////////////////////////////////////////////////////////////////
// File Name: receive.h
// Description: It declares all pins and externs functions
///////////////////////////////////////////////////////////////////////////////////////////////////

#include <pic.h>
#include <stdio.h>

#define Sel0 RA0


#define NIL RA1
#define Sel1 RA2
#define ADR0 RA3
#define ADR1 RA4
#define ADR2 RA5

#define RX0 RC0


#define RX1 RC1
#define RX2 RC2
#define RX3 RC3
#define RX_ACK RC4

#define LCD0 RD0


#define LCD1 RD1
#define LCD2 RD2
#define LCD3 RD3
#define LCD4 RD4
#define LCD5 RD5
#define LCD6 RD6
#define LCD7 RD7

#define LCD_RS RE2


#define LCD_RW RE1
#define LCD_EN RE0

extern void InitPIC(void);


extern unsigned int count,count1;
extern unsigned char temp,temp1;
64
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

//////////////////////////////////////////////////////////////////////////////////////////////////
// File Name: LCD.h
// Description: It extern LCD Control functions in LCD.c
/////////////////////////////////////////////////////////////////////////////////////////////////

#include <pic.h>
#include <stdio.h>

extern void lcd_puts(const char *s);


extern void InitLCD(void);
extern void clear(void);
extern void pos_select(unsigned char pos);

65
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

/////////////////////////////////////////////////////////////////////////////////////////
// File Name: receive.c
// Description: It coordinates the whole process
/////////////////////////////////////////////////////////////////////////////////////////

#include "receive.h"
#include "LCD.h"

void main(void)
{
unsigned char result=0;
unsigned int stop_count;

InitPIC();
InitLCD();
clear();

pos_select(0);
lcd_puts("Node0:");

pos_select(2);
lcd_puts("Node1:");

ADR0 = 0;//Address0

while(1)
{

if (ADR0==0)
{
////////////////////////////////
//Node0 Process
////////////////////////////////

result=temp;

switch (result)
{

66
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

case 0:
pos_select(1);
lcd_puts("NOT HERE ");
count1=0;
//stop_count=10000;
while (count1<10000);
break;

case 10:
pos_select(1);
lcd_puts("I AM HERE");
count1=0;
//stop_count=50000;
while (count1<50000)
{
if (temp==10)
count1=0;
}
break;

default:
pos_select(1);
lcd_puts("I DUNNO ");
count1=0;
//stop_count=50000;
while (count1<10000);
break;
}

else if (ADR0==1)
{

///////////////////////////////////
//Node1 Process
////////////////////////////////////

result=temp1;
67
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

switch (result)
{
case 0:
pos_select(3);
lcd_puts("NOT HERE ");
count1=0;
while (count1<10000);
break;

case 10:
pos_select(3);
lcd_puts("I AM HERE");
count1=0;
while (count1<50000)
{
if (temp1==10)
count1=0;
}
break;

default:
pos_select(3);
lcd_puts("I DUNNO ");
count1=0; while (count1<10000);
break;
}
}

if ((Sel0==1)&&(Sel1==0))
ADR0=0;
else if ((Sel0==0)&&(Sel1==1))
ADR0=1;
else
ADR0=0;
}
}

68
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File Name: LCD.c
// Description: It declares functions to control LCD display
////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "receive.h"

void clear(void)
{
///////////////////////////
//Clear Display
////////////////////////////
LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
PORTD = 0x01;
count=0;
while (count<100);//wait>=1.53ms for execution
LCD_EN = 0;
}

void pos_select(unsigned char pos)


{
/////////////////////////////////////////////
// Select Display Position
/////////////////////////////////////////////
switch (pos)
{
case 0://Node0 Display

LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
PORTD = 0x80;//Upper Leftmost position
count=0;
while (count<50);//wait>=39us for execution
LCD_EN = 0;

break;

69
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

case 1://Node0 Status

LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
PORTD = 0x87; //Lower Leftmost position
count = 0;
while (count<50);//wait>=39us for execution
LCD_EN = 0;

break;

case 2://Node1 Display

LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
PORTD = 0xC0;//Lower Leftmost position
count=0;
while (count<50);//wait>=39us for execution
LCD_EN = 0;

break;

case 3://Node1 Status

LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
PORTD = 0xC7;//Lower Leftmost position
count=0;
while (count<50);//wait>=39us for execution
LCD_EN = 0;

break;

}
70
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

void lcd_puts(const char *s)


{
while(*s)
{
///////////////////////////
// Write Characters
///////////////////////////

LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 1;
PORTD = *s;
count = 0;
while (count<10);//wait>=39us for execution
LCD_EN = 0;
*s++;//Jump to Next Character
}
}

void InitLCD(void)
{
while (count<1000);//wait>=30ms for power up
////////////////////////////
//Initialize Function Set
////////////////////////////
LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
PORTD = 0x38;
//PORTD = 0x38;
count = 0;
while (count<10);//wait>=39us for execution
LCD_EN = 0;

/////////////////////////////
//Display ON/OFF Control
/////////////////////////////
LCD_EN = 1;
LCD_RS = 0;
71
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

LCD_RW = 0;
//PORTB = 0x0C;//0x0F;
PORTD = 0x0C;
count = 0;
while (count<10);//wait>=39us for execution
LCD_EN = 0;

//////////////////////////////
//Display Clear
//////////////////////////////
LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
//PORTB = 0x01;
PORTD = 0x01;
count=0;
while (count<100);//wait>=1.53ms for execution
LCD_EN = 0;
///////////////////////////
//Entry Mode Set
///////////////////////////
LCD_EN = 1;
LCD_RS = 0;
LCD_RW = 0;
//PORTB = 0x07;
PORTD = 0x07;
count=0;
while (count<10);//wait>=39us for execution
LCD_EN = 0;

72
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File Name: isr.c
// Description: It acts as timer counter and checks received data input
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "receive.h"

unsigned int count,count1;


unsigned char temp,temp1;
bit flag;

void interrupt ISR(void)


{
flag=RX_ACK;

// TIMER0
if (T0IF)
{

if (ADR0==0)
temp = PORTC&0b00001111;
else if (ADR0==1)
temp1 = PORTC&0b00001111;

count++;
count1++;
TMR0=0x29;//interrupt at 50us
T0IF=0;
}

73
ERG4910B - Thesis II (2006-2007) Wireless Sensor Network

///////////////////////////////////////////////////////////////////////////////////////////////
// File Name: init.c
// Description: It initializes all the ports and registers
///////////////////////////////////////////////////////////////////////////////////////////////
#include "receive.h"
void InitPIC(void)
{
///////////////////////////////////
// A/D & I/O PIN SELECT
///////////////////////////////////
ADCON1 = 0b00001110; //ALL PINS are Digital pins

///////////////////////////////////
// PORTS
///////////////////////////////////
TRISA = 0b00000101;
TRISC = 0x1F;
TRISD = 0x00;
TRISE = 0x00;

///////////////////////////////////
// Interrupt Init
///////////////////////////////////
PIE1 = 0X00;
PIR1 = 0x00;
PEIE = 1; //enable PERI interrupt
GIE = 1; //enable ALL interrupt

///////////////////////////////////
// TMR0 Init
///////////////////////////////////
T0CS = 0; //follow CLK
T0IF = 0; //CLR TMR0 FLAG
T0IE = 1; //enable TMR0 interrupt
TMR0 = 0x29;//initial tmr0

temp = 0;//clear variable temp


}

74

Vous aimerez peut-être aussi