View/Open - Sacramento

advertisement
REMOTE POWER CONTROL USING EMBEDDED
BOARD AND ZIGBEE
Namrata Agarwal
B.Tech, College of Engineering Roorkee, India, 2007
PROJECT
Submitted in partial satisfaction of
the requirements for the degree of
MASTER OF SCIENCE
in
ELECTRICAL AND ELECTRONIC ENGINEERING
at
CALIFORNIA STATE UNIVERSITY, SACRAMENTO
FALL
2010
REMOTE POWER CONTROL USING EMBEDDED
BOARD AND ZIGBEE
A Project
by
Namrata Agarwal
Approved by:
__________________________, Committee Chair
Jing Pang, Ph. D.
__________________________, Second Reader
Preetham Kumar, Ph. D.
___________________________
Date
ii
Student: Namrata Agarwal
I certify that this student has met the requirements for format contained in the University
format manual, and that this project is suitable for shelving in the Library and credit is to
be awarded for the Project.
__________________________, Graduate Coordinator
Preetham Kumar, Ph. D.
Department of Electrical and Electronic Engineering
iii
______________
Date
Abstract
of
REMOTE POWER CONTROL USING EMBEDDED
BOARD AND ZIGBEE
by
Namrata Agarwal
We all dream of having an intelligent home that understands our needs and provides us
with exactly what we want. Human life could be much more comfortable with an
automated work-place or home or re-creation center. There are a lot of products available
in market that provides us with a complete automated home experience. In addition,
many of these products offer added advantage and feature of consuming minimal power
and also accustoming to power need of a device by constantly monitoring its power
usage; and thereby increasing energy efficiency of the given device.
This project deals with maximizing the power efficiency in home automation systems.
Power efficiency is perhaps one of the most sought after asset in today’s world, where the
whole world is facing shortage of energy resources. The focus of this project is to design
a remote power On/Off control and a power measurement for electric outlets, based on
both an embedded board and on ZigBee communication. The design consists of two
parts: the ZigBee Control module and the Server module. The control module contains
several controllable outlets, a current measurement circuit, the ZigBee receiving and
iv
transmission circuit and a microcontroller unit. The measurement circuit senses the power
and sends back a signal to the server module through the ZigBee. The measurement data
of the power is stored in the embedded board.
I have focused on the bidirectional communication between the processor and the Sever
module using a low cost, low power ZigBee transceiver to control the power
consumption. The power is controlled by the server module; and the power measurement
values are received by processor. These values are then sent to the server, where it can be
displayed in a meaningful format.
__________________________, Committee Chair
Jing Pang, Ph. D.
_______________________
Date
v
ACKNOWLEDGEMENT
This space provides me with a great opportunity to thank all the people without whom
this project would have never been possible. I would take this opportunity to convey my
sincere thanks to all of you.
First of all, I would like to thank Dr. Jing Pang, who is my first reader, for providing me
all the guidance and the support during the project. She was the one who suggested me to
take this as my Master’s project and encouraged me to be innovative and original. She
was very patient throughout the period of my project and helped whenever I got stuck.
She took the time out of her busy schedule to provide me with the valuable suggestions
regarding project as well as for the project report.
I would also like to thank Dr. Preetham Kumar, Graduate coordinator, for his valuable
suggestions and support throughout the span of the project. Though he is very busy, he
agreed to be my second reader and gave me valuable suggestions for report writing.
I also want to thank all my project partners and my friends, without whom, I would have
never been able to complete my project on time. They were always there to help me and
guide me whenever I had any doubts. Their constant support and encouragement helped
me to work even harder. Without their continuous support, it would have been really
difficult for me to complete the project on time.
vi
TABLE OF CONTENTS
Page
Acknowledgement………………………………………………………………………..vi
List of Tables……………………………………………………………………………...x
List of Figures…...………………………………………………………………………..xi
Chapter
1. INTRODUCTION AND MOTIVATION ...................................................................... 1
1.1
Overview .............................................................................................................. 1
1.2
Motivation ............................................................................................................ 2
2. ZIGBEE TECHNOLOGY .............................................................................................. 3
2.1
History .................................................................................................................. 3
2.2
ZigBee Vs other Technologies ............................................................................. 4
2.3
ZigBee Features and Communication .................................................................. 8
2.3.1
Physical Layer ............................................................................................... 9
2.3.2
MAC Layer ................................................................................................. 11
2.3.3
Network Layer ............................................................................................ 12
2.3.4
Application Layer ....................................................................................... 12
2.4
Applications of ZigBee Technology .................................................................. 13
2.4.1
Home Automation and Control ................................................................... 13
2.4.2
Medical/Patient Monitoring ........................................................................ 14
vii
2.4.3
Commercial Building Automation and Control .......................................... 14
2.4.4
Energy Management ................................................................................... 15
2.4.5
Asset Tracking ............................................................................................ 15
3. PROJECT SPECIFIC DETAILS .................................................................................. 17
3.1
Objective ............................................................................................................ 17
3.2
Hardware Resources ........................................................................................... 19
3.2.1
ATMEL 89C52 Microprocessor ................................................................. 19
3.2.2
ZigBee Transmitter and Receiver ............................................................... 24
3.2.3
Light Dependent Resistor (LDR) ................................................................ 25
3.2.4
RS 232 UART ............................................................................................. 26
3.2.5
Relays .......................................................................................................... 28
3.3
Circuit Description and Working ....................................................................... 28
4. CODE DESCRIPTION ................................................................................................. 32
4.1
Code Details ....................................................................................................... 32
4.1.1
Delay Function ............................................................................................ 32
4.1.2
Transmit_Byte Function ............................................................................. 32
4.1.3
Convert_Display Function .......................................................................... 33
4.1.4
SCI_Receive Byte ....................................................................................... 34
4.1.5
Serial 0 Interrupt ......................................................................................... 34
4.1.6
Main Function ............................................................................................. 36
5. CONCLUSION AND FUTURE WORK ..................................................................... 37
5.1
Key Challenges .................................................................................................. 37
viii
5.2
Conclusion.......................................................................................................... 38
5.3
Future Work ....................................................................................................... 39
Appendix ........................................................................................................................... 40
Bibliography ..................................................................................................................... 44
ix
LIST OF TABLES
Page
1. Table 1. Comparison between different technologies............................................. 5
2. Table 2. Comparison between Bluetooth and ZigBee ............................................ 7
3. Table 3. AT 89C52 Pins........................................................................................ 23
x
LIST OF FIGURES
Page
1. Figure 1. ZigBee Protocol Stack ............................................................................. 9
2. Figure 2. PHY Packet Fields ................................................................................. 11
3. Figure 3. ZigBee Control Module ......................................................................... 18
4. Figure 4. ZigBee Module and Server .................................................................... 19
5. Figure 5. Pin Diagram of AT 89C52 .................................................................... 21
6. Figure 6. Pin Configuration of ZigBee Transmitter.............................................. 25
7. Figure 7. Symbol of LDR ..................................................................................... 26
8. Figure 8. RS232 DB9 Pin Out .............................................................................. 27
9. Figure 9. Serial to USB Cable............................................................................... 27
10. Figure 10. Relays .................................................................................................. 28
11. Figure 11. Block Diagram of System [2] .............................................................. 29
12. Figure 12. Circuit Layout ...................................................................................... 31
xi
1
Chapter 1
INTRODUCTION AND MOTIVATION
From past many years, we hear people talking about a home that is intelligent, that
understands what its user desires and accordingly fulfils their need. This concept is called
a “smart house”. It is a place that understands what its user want and respond
accordingly. It can be used for managing the day to day activities like light control, open
and close blinds, or for security purposes like raising alarms for any suspicious activities.
By carefully monitoring what a person wants and automating it in the home system,
automated systems can make one’s home a much more comfortable and secure place to
live.
1.1
Overview
Just imagine how it would feel like, to live in a house that can understand your needs and
your moods. Even before you reach home, it has the temperature that is maintained; lights
adjusted, your favorite music playing on the player [1]. When you go out, it automatically
turns off the lights, the heater and gas, and turns on the security alarms. Imagine how
easy our life can be with these services. Nowadays more and more people want to have
their homes completely automated and they are looking for options to make their life
easier, comfortable and secure.
As more and more digital appliances colonize our home, managing them to form a home
automation system is not only an option, but almost a necessity [2]. By automation, we
mean organizing all the main systems in the house into one common system, thus making
2
the tough job of handling them easy. From a long time, automating homes has been
considered as a desirable, but difficult to acquire attribute. Earlier, having an automated
home was possible just for people like Bill Gates, who had millions of Dollars to spend.
But today, even a common man can live this dream. Although home automation
technology is relatively a new field, its increasing demand has lured many companies to
come up with more affordable products. Different technologies are being used to achieve
this target. Some of the wireless technologies used are Bluetooth, ZigBee, and Infrared.
Until now, Bluetooth was the favorite wireless technology amongst manufacturers, but
now its market dominance has been threatened by a new technology called ZigBee.
ZigBee provides an efficient remote device control over large distances, with minimum
power consumption. This project focuses on implementation of a wireless power control
system using embedded board and ZigBee technology.
1.2
Motivation
Being an engineer, I have always been intrigued by the technologies that can make
people’s life easier. Home automation is one such emerging technology. Controlling and
managing all the appliances in home from a remote place saves time and energy. I feel
that this has a lot of potential in coming future. Though there are lots of different tools for
achieving this, I found ZigBee most interesting because of its low power consumption
feature as power conservation is on everyone’s agenda at this time and it is going to be
even more important in times to come.
3
Chapter 2
ZIGBEE TECHNOLOGY
As mentioned in the previous chapter, ZigBee provides a low cost and low power
wireless communication. It is an integral part of the project. This chapter discusses in
detail, the various aspects of ZigBee, including how it works and why we should use
ZigBee.
2.1
History
“ZigBee is an IEEE 802.15.4 standard for data communications with business and
consumer devices. It is designed around low-power consumption allowing batteries to
essentially last forever. The ZigBee standard provides network, security, and application
support services operating on top of the IEEE 802.15.4 [3]” ZigBee technology’s
development started in 1998, when engineers realized that the existing solutions like WiFi and Bluetooth were deficient in fulfilling the demands that were anticipated in near
future. Its main purpose was to provide a low power and low cost solution for wireless
communications. A standard was developed by the IEEE in 2003, called 802.15 having
the purpose of exploring a low data rate solution with large battery life and very low
complexity.
A consortium called ZigBee Alliance was formed later on to build their specifications
over 802.15. Many companies came together to form this Alliance. These companies aim
at achieving a solution that is cheap, easy to use and implement, flexible and mobile.
4
Undoubtedly, ZigBee is nowadays amongst the most used technologies because of its
virtues.
2.2
ZigBee Vs other Technologies
Today’s market is full of technologies that aim the mid to high data rates for voice, PC
LANs, video, etc. What is missing in all these technologies is the unique need for the
sensors and control devices. Sensors and controls need very low energy consumption
ability so as to have long battery lives even though high bandwidth is not required.
ZigBee Alliance focuses on this part of the market and thus provides a standardized set of
solutions for wireless communication for such devices. The main advantage of having a
standard is that it provides a cost effective solution as compared to creating a new
solution from scratch every time.
As mentioned in Chapter 1, there are a lot of other wireless technologies that are present
in market for the whole sole purpose of remotely controlling and managing systems.
Table below shows a detailed comparison of various technologies.
5
Wi-Fi
BLUETOOTH ZIGBEE
FEATURES
(IEEE 802.11b)
(IEEE
802.15.1)
(IEEE
802.15.4)
Power
Profile/Battery life
Hours
Days
Years
Network Size
32
7
64000
Operating
Frequency
2.4 and 5 GHz
2.4 GHz
868 MHz
(Europe)
900-928 MHz
(NA), 2.4 GHz
(worldwide)
Complexity
Very Complex
Complex
Simple
Range
50-100m
10m
70m-300m
Data rate
11Mbps
1Mbps
250Kbps
Application Focus
Web, Email
Cable
Replacement
Monitor and
control
Success Metrics
Speed
Cost
Power, Cost
Table 1. Comparison between different technologies
6
The ZigBee properties can be summarized as follows [2]:

Simple and reliable

Very low cost and easy maintenance

Reliable communication

Low power requirements allowing a long battery life

Simple network configuration which allows devices to be added to existing
networks with very little work

Secure communication
It is clearly visible from the Table-1 that ZigBee is much better than Wi-Fi and Bluetooth
technologies. The major attraction is the increased battery life. Whereas some
technologies just give a life of 1-7 days, ZigBee shows a battery life of almost 1000 days.
This is because of its low power consumption capabilities.
Though there are so many technologies, Bluetooth is one of the major competitors of
ZigBee. They both share some very attractive and desirable qualities like both of them
have almost same operating ranges and same ISD ranges. But they differ widely in their
data ranges and network sizes. Also, communication using Bluetooth is quite complex as
compared to that using ZigBee. More detailed comparison is provided in the table below.
7
CHARACTERISTICS
Data Rate
Power Profile
Range
BLUETOOTH
1 Mbps
Days
10 meters
Security
64 bit, 128 bit
Operating frequency
Data Rate
Scalability
Flexibility
Reliability
2.4 GHz ISM
1Mbps
Low
Medium
Low
Cable
Replacement
Application
ZIGBEE
20-250Kbps
Years
10-100meters
128 bit AES and Application
layer user definable
868 MHz, 902-928 MHz, 2,4
GHz ISM
250Mbps
Very High
Very High
High
Control and sensors
Table 2. Comparison between Bluetooth and ZigBee
One of the most important characteristic of ZigBee that makes it the perfect choice for
wireless automation is its ability to quickly attach, exchange information, detach, and
then go in hibernation. This leads to a very long battery life. Bluetooth devices require
about 100 times the energy for this operation. This is the reason, that their application
areas are completely different. Bluetooth is more suitable for data transfer between
devices (machine to machine), for e.g., Synchronization of cell phone to PDA, Handsfree audio, PDA to printer, where as ZigBee is more suitable for remote sensing and
control for small data packets and lots of devices. One thing is for sure, that the
applications targeted by ZigBee are not addressable by Bluetooth or any other wireless
standard. One can also say that, ZigBee and Bluetooth complement for a broader
solution.
8
2.3
ZigBee Features and Communication
ZigBee is a universal wireless language connecting radically dissimilar devices to work
together and enhance everyday life. ZigBee standard is mainly for wireless sensor
networks, like Bluetooth is for short distance communications and Wi-Fi is for internet.
ZigBee Alliance provides a simple, low cost and low power wireless control standard for
remote monitoring and controlling, based on IEEE standard 802.15.4. Some of the
characteristics of IEEE 802.15.4 are as follows [4]:

Simple Design and low cost

Low power, that means large battery life ranging from many months to years

Large number of devices

Data rates of 250 kbps, 40 kbps, and 20 kbps

Star topology, peer to peer possible

Extremely low duty-cycle (<0.1%)

CSMA-CA channel access

Optional Guaranteed Time Slot

Full handshake protocol for transfer reliability

Dual PHY (2.4GHz and 868/915 MHz)

Range: 10m (1-100m based on settings)
The scale of this IEEE standard is to define the physical layer (PHY) and the media
access controller (MAC). It includes layers up to and including Link Layer Control. A
9
graphical representation of the areas of responsibility between the IEEE standard, ZigBee
Alliance, and User is presented in Figure 1 below.
APPLICATION/PROFILES
ZIGBEE
APLLICATION
FRAMEWORK
NETWORK LAYER
ZIGBEE ALLIANCE
PLATFORM
MEDIUM ACEESS
CONTROL LAYER
IEEE
802.15.4
PHYSICAL LAYER
Figure 1. ZigBee Protocol stack
Let’s go over each layer in detail:
2.3.1
Physical Layer
IEEE 802.15.4 defines the Physical Layer (PHY) as responsible for the following tasks
[5]:

Activation and deactivation of the radio transceiver

ED within the current channel

LQI for received packets

CCA for CSMA-CA
10

Channel frequency selection

Data transmission and reception
Data and The PHY provides two services: the PHY data service and PHY management
service interfacing to the physical layer management entity (PLME). The PHY data
service enables the transmission and reception of PHY protocol data units (PPDU) across
the physical radio channel. The standard offers two PHY options based on the frequency
band. The data rate is 250kbps at 2.4GHz, 40kbps at 915MHz and 20kbps at 868MHz
[6].
PHY Packet Fields:

Preamble (32 bits) – synchronization

Start of Packet Delimiter (8 bits)

PHY Header (8 bits) – PSDU length

PSDU (0 to 1016 bits) – Data field
11
PREAMBLE
START OF PACKET
PHY HEADER
DELIMITER
PHYSICAL SERVICE DATA UNIT
6 octets
0-127 octets
Figure 2. PHY Packet Fields
2.3.2
MAC Layer
The MAC layer is responsible for handling all the accesses to the physical radio channel.
It provides an interface between the Application layer and the Physical layer.
It is also responsible for [5]:

Generating and synchronizing the network beacons

Device security

PAN association and disassociation

Employing the CSMA-CA mechanism for channel access

Providing a reliable link between two MAC entities

Each MAC frame consists of the following basic components:

MHR, which comprises frame control, sequence number, and address information

A MAC payload of variable length, which contains information specific to the
frame type. Acknowledgement frames do not contain a payload.

A MFR, which contains FCS.
12
2.3.3
Network Layer
The main function of a network layer is to provide an end to end path across a network. It
helps in building a network. It also manages the discovery and maintenance of paths
between them. Another objective of network layer is to store the information about the
neighbor devices. Some of the other responsibilities include [7]:

Starting a new network

Joining and leaving a network

Configuring a new device

Addressing the devices joining the network.

Topology specific routing

Neighbor discovery

Routing Discovery
2.3.4
Application Layer
It consists of Application Support Sub layer (APS), ZigBee Device Object (ZDO) and
Application Framework containing manufacturer defined application objects. Application
support sub layer (APS) provides an interface between the network layer (NWK) and the
application layer (APL) through a general set of services. Application Framework
provides an environment for hosting manufacturer defined application objects on ZigBee
devices. ZigBee Device Objects provide common function for applications. It offers
services like device-/service-discovery, binding and security management. It also
assembles information about the network [7].
13
2.4
Applications of ZigBee Technology
“Since its inception, the ZigBee Alliance has worked with a singular focus: create a
much needed global wireless language capable of giving “voices” to the myriad of
everyday devices which surround us as we go about our daily lives [8].” To achieve this
goal, ZigBee Alliance members have created a wireless standard that can be used in any
country around the world. It offers extraordinary control, expandability, security, ease-ofuse and the ability. Most importantly, it offers a low power solution, leading to very high
battery life, thus making it an obvious choice for applications that have limited power
resources. Today, many companies are using ZigBee to provide wireless, low cost, low
power services to people. It proves to be an apt solution for networks that require small
data rates and have relatively long times between transmissions. Some of the major
applications of ZigBee are described below.
2.4.1
Home Automation and Control
Perhaps the most popular application of ZigBee is the home automation. It provides a
fully automated home, removing all the barriers and boundaries faced by other
technologies. ZigBee products offer wireless solutions using hand-held remote
controllers, security and lighting systems, keypads, climate control, audio-video
capabilities via the computer or standard (SDTV) or high-definition (HDTV), and more
[1]. A ZigBee automated home provides an extra feature of increased security to its
consumers. It provides remote monitoring of devices such as smoke detectors, fire
alarms.
14
2.4.2
Medical/Patient Monitoring
As the population of world is increasing by leaps and bounds, so is the death rate. At such
times we need an efficient health care system that is easily affordable for people. The
healthcare domain presents opportunities for a significant number of applications of
wireless sensor technology. So the question is why to select ZigBee over other
technologies. ZigBee provides a method for wireless LAN and PAN with low-power
requirements. It monitors and senses for activity and health, or chronic or acute disease
states. It helps in collecting the data and passing it by means of Internet. It also maintains
an EHR, i.e., an electronic health record.
Some of the areas where ZigBee is widely used are:

Chronic Disease Monitoring

Personal Wellness Monitoring

Personal Fitness Monitoring
2.4.3
Commercial Building Automation and Control
ZigBee based commercial buildings allows everyone to customize and control their own
space while allowing business owners to receive considerable technology benefits and
cost advantages for their investments. It allows for [9]:

Saves energy related expenses and enables allocation of costs based on actual
consumption.

Easy management of lighting systems so as to create adaptable workspaces. It
also allows for upgrades of building infrastructure with nominal effort.
15

Control that helps in complete and easy management of lighting, heating, cooling
and security.

Safety through a network where integrated data from multiple access points
enables capabilities such as a re extinguisher that indicates blockages, etc., or a
wireless monitoring system that enhances perimeter protection to secure the
building.

Simultaneous control of many systems to improve energy conservation, flexibility
and security.
2.4.4
Energy Management
Today, the Energy consumption of the World has increased by leaps and bounds. And by
looking at the trend and the developments taking place all around, one can guess that it
will increase even more in the coming future. To manage such a huge demand, we need
to start using the energy carefully from today, so as to meet the demands in future. That’s
where ZigBee comes in picture. It allows the user to keep an eye on their energy
consumption. Customers get real time information about their energy usage. Apart from
that, it also allows the power of controlling the on/off of devices, maintaining the voltage
levels, current controlling and spontaneous reading.
2.4.5
Asset Tracking
Companies that have extremely valuable on-the-go assets have a vested interest in
knowing exactly where those assets are at all times. Tracking these mobile containers can
be an expensive proposition that companies have no choice but to accept. ZigBee
16
Technology provides a low cost solution for asset tracking to all the companies. It allows
for a low power consumption implementation that requires very less maintenance.
ZigBee have the capabilities of data collection, which improves the supply chain
performance, reduces the tracking costs and the container loss and damages.
17
Chapter 3
PROJECT SPECIFIC DETAILS
This Chapter deals with the Project specific details. It includes the basic working of the
home automation kit and the main components that were used to develop this hardware.
A block diagram of the hardware showing all the connections is also included.
3.1
Objective
The objective of this project is to make a low power remote control model for controlling
the on/off of LEDs using ZigBee communication. It consists of two parts: the ZigBee
control module and the server module. The ZigBee control module contains several
controllable outlets, a current measurement circuit, the ZigBee receiving and transmission
circuit and a microcontroller unit. One of the ZigBee modules is connected to the circuit
and other one is connected to a master system (desktop, laptop). Master system gives the
ON/OFF commands that are transmitted and received by ZigBee modules. A
Microprocessor attached to kit takes the signals from ZigBee and hence control the
LEDs.
18
Figure 3. ZigBee Control Module
As ZigBee offers a bidirectional communication, messages from microprocessor can also
be transmitted to the Master system. This property of ZigBee is used to make the system
power efficient. A Light dependent circuit, which is a part of measurement circuit, is
attached to the microprocessor. It detects the light pulses that fall on it and sends them to
the processor, from which processor calculates the total power consumption and sends
that data to the server module, again using ZigBee. The measurement data is stored in the
embedded board. Using this model, one can control the lights and also keep track of the
total power consumption. This whole model has been designed keeping home automation
system in mind. Figure 4 gives an overlook of the ZigBee Module and Server Module.
19
ZIGBEE
LED 1 ON
LED 1 OFF
LED 2 ON
LED 2 OFF
LED 3 ON
LED 3 OFF
SERVER MODULE
DISPLAY
ZIGBEE
LED2
LED1
LED 3
ZIGBEE MODULE
Figure 4. ZigBee Module and Server
3.2
Hardware Resources
3.2.1
ATMEL 89C52 Microprocessor
The AT89C52 is a low-power, high-performance CMOS 8-bit microcomputer with 8K
bytes of Flash programmable and erasable read only memory (PEROM). The device is
manufactured using Atmel’s high-density nonvolatile memory technology and is
compatible with the industry-standard 80C51 and 80C52 instruction set and pin out. The
20
on-chip Flash allows the program memory to be reprogrammed in-system or by a
conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with
Flash on a monolithic chip, the Atmel AT89C52 is a powerful microcomputer which
provides a highly-flexible and cost-effective solution to many embedded control
applications [10].
The AT89C52 processor provides following standard features:

8K bytes of Flash

256 bytes of RAM

32 I/O lines

3 16-bit timer/counters

8 Interrupts

A six-vector two-level interrupt architecture,

A full-duplex serial port

On-chip oscillator

Clock circuitry
21
Figure 5. Pin Diagram of AT 89C52
Let’s take a look at the pins of the processor [10]:

Vcc is the main supply voltage.

GND is the Ground.

Port 0 is an 8-bit open drain bi-directional I/O port. When 1s are written to port 0
pins, the pins can be used as high impedance inputs. Port 0 can also be configured
to be the multiplexed low order address/data bus during accesses to external
program and data memory. In this mode, 0 has internal pull ups. Port 0 also
receives the code bytes during Flash programming and outputs the code bytes
during program verification. External pull ups are required during program
verification.
22

Port 1 is an 8-bit bi-directional I/O port with internal pull ups. The Port 1 output
buffers can sink/source four TTL inputs. It receives the low-order address bytes
during Flash programming and verification. Port 1.0 can be configured to be used
as timer/counter 2 external count input (P1.0/T2) while port 1.1 can be used as
timer/counter 2 trigger input.

Port 2 is an 8-bit bi-directional I/O port with internal pull ups. It emits the highorder address byte during fetches from external program memory and during
accesses to external data memory that use 16-bit addresses. It also receives the
high-order address bits and some control signals during Flash programming and
verification.

Port 3 is an 8-bit bi-directional I/O port with internal pull ups. It also serves the
functions of various special features of the AT89C51, as shown in the Table-3
below.
23
PORT PIN
ALTERNATE FUNCTIONS
P3.0
RXD (Serial Input Port)
P3.1
TXD (Serial output port)
P3.2
INT0 (External interrupt 0)
P3.3
INT1 (External interrupt 1)
P3.4
T0 (Timer 0 external input)
P3.5
T1 (Timer 1 external input)
P3.6
WR (External data memory write strobe)
P3.7
RD (External data memory read strobe)
Table 3. AT 89C52 Pins

RST is the reset input. A high on this pin for two machine cycles while the
oscillator is running resets the device.

ALE/PROG: Address Latch Enable is an output pulse for latching the low byte of
the address during accesses to external memory. This pin is also the program
pulse input (PROG) during Flash programming. If desired, ALE operation can be
disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only
during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high.

PSEN is the Program Store Enable for external program memory. When the
AT89C52 is executing code from external program memory, PSEN is activated
twice each machine cycle, except that two PSEN activations are skipped during
each access to external data memory.
24

EA/VPP is the External Access Enable. EA must be strapped to GND in order to
enable the device to fetch code from external program memory locations starting
at 0000H up to FFFFH. EA should be strapped to VCC for internal program
executions.

XTAL1 is the Input to the inverting oscillator amplifier and input to the internal
clock operating circuit.

XTAL2 is the Output from the inverting oscillator amplifier.

INT0, INT1 are the external interrupts. Apart from these, it has 3 timer interrupts
(timer 0, 1 and 2) and 1 serial port interrupts.
3.2.2
ZigBee Transmitter and Receiver
It has following features [2]:

Input supply 5V to 12V

254 Controlled Devices

2.4 GHz Carrier Frequency

Very Low Power Consumption

RS232 UART interface available

Power LED indicator

Transfer rate of 250 Kbps

Compact size

Easy to use and install

Variable Packet Length is allowed
25

User Friendly GUI for setting up RF Module and Test Module
Figure 6. Pin Configuration of ZigBee Transmitter
3.2.3
Light Dependent Resistor (LDR)
A light-dependent resistor, alternatively called an LDR, is a component that is sensitive
to light. It is a variable resistor whose value decreases with increasing incident light
intensity. These are often used in circuits where it is necessary to detect the presence or
the level of light. Resistance of the LDR changes as the level of light increases.
An LDR is made of a high resistance semiconductor material. As the light rays fall on the
semiconductor, the light photons get absorbed by the semiconductor lattice and some of
their energy gets transferred to the electrons. This gives some of them sufficient energy to
26
break free from the crystal lattice so that they can then conduct electricity. This results in
lowering of the resistance of the semiconductor, thus reducing the overall LDR
resistance. As the light intensity increases, more and more electrons are released, hence
reducing the resistance eve more.
Figure 7. Symbol of LDR
Main features of LDR are:

Low cost

Wide ambient temperature range

Wide Spectral Response
3.2.4
RS 232 UART
The RS232 is used for establishing a serial communication between a Microcontroller of
embedded system and the peripherals. Data is sent bit by bit on a physical channel. The
data sent can be of variable length, though transmitter and receiver use the same number
of bits. It uses 4 types of Bits for transfer: start bit, stop bit, parity bits and data bit. The
data transfer takes place at a fixed, predefined frequency, known as baud rate. Both the
transmitter and receiver work on same bit frequency. After receiving the first bit, the
receiver calculates the moments at which other data bits arrive. Voltage levels at those
27
instances are checked by receiver. The figure 8 below shows a pin description for a 9 pin
RS232, known as DB9.
Figure 8. RS232 DB9 Pin Out
Figure 9. Serial to USB Cable
28
3.2.5
Relays
Relay is a switch that operates electrically. It is basically a simple electromechanical
switch made up of an electromagnet and a set of contacts. Relays are used to isolate one
electrical circuit from another. It allows a low current control circuit to make or break an
electrically isolated high current circuit path.
The main part of a relay is the coil at the centre. A magnetic field is created when small
current flows through the coil. It pulls one switch contact against or away from another,
which leads to on or off of the relay. Relays are used to control a high-voltage circuit
with a low-voltage signal or to control a high-current circuit with a low-current signal.
Figure 10. Relays
3.3
Circuit Description and Working
Whole model is divided into two parts: ZigBee control module and a server module. The
server module (desktop, laptop) is connected to a ZigBee module through a USB to serial
cable. Another ZigBee module is connected to the microprocessor.
Processor is
connected to load through relays. Also, an LDR circuit is connected to the processor,
which becomes active when a strong light falls on it.
29
To start the communication, server module sends the on/off control signals for the loads.
As there are 3 LEDs used as load, signal specific for each led is sent. This signal is
transferred to the ZigBee module connected to the server. This ZigBee acts as a
transmitter, and sends the data to the other ZigBee module, that is connected to the
processor. This ZigBee acts as a receiver and receives the data. It transfers the data to the
processor, which, in turn gives the signals to the relays for the on or off of a particular
led. The LEDs react according to the signal received.
Figure 11. Block Diagram of System [2]
Second part of this project is the power measurement. LDR detects the light falling on it
and sends the signal to the microprocessor as pulses. The processor calculates the power
by counting the pulse. It then changes the value from hex format to decimal form and the
sends the value to server module. This time, the ZigBee connected to processor acts as a
transmitter and the one connected to server module acts as receiver. The value is received
by the server module and is displayed on the monitor. These values help us to keep a
check on the total power consumption and thus aids in power conservation.
The whole model is created to represent a home automation system. The advantage of
this model is that it is a low power wireless system. Another advantage is that it is quite
30
cheap because of the low cost of ZigBee. This model shows us the advantages of using a
ZigBee module for automation purposes.
31
Figure 12. Circuit Layout
32
Chapter 4
CODE DESCRIPTION
The primary aim of this chapter is to give an overview of the code used by the
microcontroller. The chapter dwells in detail of each method used for achieving desired
functionality with Atmel AT89C52.
4.1
Code Details
The basic code is divided in the different functions to increase the code reuse and
flexibility in the coding.
4.1.1
Delay Function
void DELAY()
//
Delay function
{
unsigned int X=600000,Y=800000;
while(X--);
while(Y--);
}
This function is used for generating the delay. The values used her for the delay are
configurable and can be adjusted according to the ones need.
4.1.2
Transmit_Byte Function
void transmit_byte(unsigned char byte)
{
SBUF=byte;
//Transmit the data to serial
while(!TI); //SBUF: serial buffer register;data to be transferred
//via TxD line must be placed in SBUF
TI=0; //TI: SCON.1=transmit interrupt flag. Set by hardware at
//beginning of stop bit in mode 1. Must be cleared by software
}
//when 8051 finishes the transfer of the 8-bit character; it sets the TI
flag to indicate that it is ready to transfer another byte
33
This function accepts input from the Transmit function in the form of a single character
puts the value in SBUF of AT89C52. After finishing the transmission it resets the TI
(Transmit Interrupt) flag back to 0.
4.1.3
Convert_Display Function
void CONVERT_DISPLAY(unsigned int d)
{
unsigned char dig1,dig2,dig3,dig[3];
unsigned char x;
unsigned char temp;
temp=d;
temp=temp/10;
dig1=d%10;
//Convert hex to decimal
dig2=temp%10;
dig3=temp/10;
dig[0]=dig3;
dig[1]=dig2;
dig[2]=dig1;
IE=0;
for(x=0;x<3;x++)
{
temp=dig[x]|0x30;
transmit_byte(temp);
DELAY();
DELAY();
DELAY();
DELAY();
}
}
This function converts the hexadecimal values from the microcontroller to decimal values
to be displayed on the screen. It accepts an unsigned integer value and converts it into
equivalent decimal values to be displayed on the screen.
34
4.1.4
SCI_Receive Byte
unsigned char SCI_ReceiveByte( void )
{
unsigned char byte;
while(RI!=1);
//RI:SCON.0=recieve interrupt flag.Set by //h/w at
//beginning of stop bit in mode //1.must be cleared by s/w
byte = SBUF;
//Receive serial data
RI=0; //When 8051 receives data serially via RxD, //it places //the
//byte in the SBUF register. //then raises the RI flag //bit to
//indicate that a byte has been received and //should //be
//picked up before it is lost
return byte;
}
This function is used for receiving the byte. This function continuously pings the RI pin
of the microcontroller until its 0. Once the flag is set to 0 it indicates a value is present in
the buffer. It receives the value from the buffer and then transmits it back to the calling
function.
4.1.5
Serial 0 Interrupt
void serial0(void) interrupt 4 //Serial Interrupt
{
rec=SCI_ReceiveByte();
IE=0;
// Disable Serial Interrupt
if(rec=='m')
{
CONVERT_DISPLAY(count);
}
if(rec=='1')
{
relay1=1;
}
if(rec=='2')
{
relay1=0;
}
if(rec=='3')
{
relay2=1;
35
}
if(rec=='4')
{
relay2=0;
}
if(rec=='5')
{
relay3=1;
}
if(rec=='6')
{
relay3=0;
}
RI=0;
TI=0;
IE=0x90;
//Enable Serial Interrupt
}
This function continuously pings the Serial Interrupt to check if there is any data present
on the buffer. Depending upon the data that is received in the serial buffer it calls and/or
sets the various variables. After receiving the value it disables the Serial Interrupt until
the value is fully processed. After the successful interpretation of the value it set the RI
and TI to 0 and re-enables the Serial Interrupt. When the value on the serial buffer is “m”
it calls the “Convert_Display” function. When value is 1 then it set the relay1 flag to 1
and when the value is 2 it resets the value back to 0. The function does the same for
relay2 and relay3 when the values are 3, 4 and 5, 6 respectively. Relay1, Relay2 and
Relay3 are the 3 relays connected to pins P2.0, P2.1 and P2.2 Address ports.
36
4.1.6
Main Function
void main()
{
TMOD=0X20;
TH1=0XFD;
SCON=0X50;
TR1=1;
relay1=0;
relay2=0;
relay3=0;
count=0;
mybit=0;
//tmod: timer mode register(8bit). It selects mode //2
of T1 which is 8 bit auto reload
//Serial Initialisation,to set baud rate to 9600 //bps
for a crystal of 12 MHz.
//scon: serial control register
// Set the value of TR1 = 1 to start the Timer 1
//Set all the relay at off condition
//Set counter to 0
}
This is main entry point of the program execution. It is initially set the value of TMOD to
set it to 8 bit automatic reload, TH1 to have baud rate to 9600 bps and value of TR1 to 1
to start Timer 1. It also initializes the value of all Relays to 0 (Off condition).
37
Chapter 5
CONCLUSION AND FUTURE WORK
This Chapter provides an overview of the learning acquired in developing and
documenting this Master’s Project. It also includes the future prospects of the project. I
have also mentioned the key challenges faced during the development and
implementation of the home automation module using ZigBee Technology.
5.1
Key Challenges
During the span of the Master’s project, one of the major difficulties faced was to decide
the components to be used to develop the hardware model. Due to the growing demand of
home automation, more and more technologies are being introduced to make this process
as efficient as possible. To decide which technology to use for the communication
process, amongst all technologies, was a challenging process. It needed collection of all
the available data about all the technologies and to compare them.
Other challenge faced was the coding portion for the microprocessor. It took several days
to gain the appropriate level of knowledge required to program the microprocessor. It
included detailed study about the signals of the Atmel processor. As I am new to the
embedded C language, it took me some time to grasp this programming language and to
use it to code the processor.
Verifying the communication was another challenge. It was difficult to validate that the
messages sent and received by both the modules were correct or not.
38
5.2
Conclusion
The most important conclusion to be drawn from the project is the potential power saving
it offers over several other existing technologies for home automation. The use of ZigBee
technology reduces the power consumption, thus increasing the life of batteries to almost
one year, as compared to some of the other technologies, that lasts for just few days or
months. Also, it reduces the total cost of implementation of automation, as the cost of
ZigBee is far less than that of other technologies.
This project makes people sit and realize the enormous potential of home automation
system. It presents to the world, a huge range of possibilities that can be exploited to
make our life as comfortable as possible, and with minimum efforts. One can control the
on/off of all the lights in whole house, while sitting in at any place.
Apart from making our homes more comfortable, home automation also provides us a
way to monitor the power consumption. It allows us to keep track of power for each
hour, each day, each month or year. This helps people in making wise decisions about the
power utilization. It is a huge thing, as reducing power consumption is on everyone’s
agenda.
While working on the Master’s project, I got the opportunity to learn and work on various
new things which I was not able to do before. It helped me to broaden my skill set. I
learned the embedded C programming language used to code the processor. I also got a
chance to work on real hardware, to design one according to the block diagram.
39
5.3
Future Work
The main aim of this project is to implement a low cost, wireless, power control system
using ZigBee technology. It exploits just a small portion out of the enormous abilities of
ZigBee. In this project, just the wireless on/off of lights and the power consumption part
is modeled. A possible extension of this project is to utilize the sensor related properties
of ZigBee. Like a ZigBee-enabled sensor network can detect an occupant’s presence in
the room and then can turn on the light to a pre-set lighting level for the time of day, set
the temperature of the room again according to the temperature outside. A main control
panel could also be added that gives the information about the house including
temperature readings, reminders to open or close windows; current price of energy from
the utility company.
Another possible addition to this could be security aspect of home. It is possible to add a
wireless, Internet-based security system that can be pre-programmed or remotely
activated to perform a variety of activities like turn on/off a security system, release door
locks or open or close windows. To make it more efficient and easy to use, a hand-held
remote can be included to identify security breaches and safety issues.
40
APPENDIX
Code
#include <reg51.h>
#include"string.h"
//header file
// special function register declarations
// for the intended 8051 derivative
//***************************************************************//
void transmit_byte(unsigned char byte);
unsigned char SCI_ReceiveByte( void );
void TRANSMIT(unsigned char *string);
funtion
void CONVERT_DISPLAY(unsigned int);
void DELAY();
//function prototype to call
//***************************************************************//
unsigned char rec;
unsigned char count=0;
sbit mybit=P3^4; // Pulse input connected to Pin3.4; T0(timer 0
external input) (refer AT89C52 pin diagram)
sbit relay1=P2^0;
sbit relay2=P2^1; // 3 relays are connected to P2.0,P2.1,P2.2(addresss
ports) (refer AT89C52 pin diagram)
sbit relay3=P2^2;
void main()
{
TMOD=0X20; //tmod: timer mode register(8bit). It selects mode 2
of T1 which is 8 bit auto reload
TH1=0XFD;
//Serial Initialisation,to set baud rate to
9600 bps for a crystal of 12 MHz.
SCON=0X50;
//scon: serial control register
TR1=1;
// Set the value
//of TR1 = 1 to start the Timer 1
relay1=0;
relay2=0;
relay3=0;
count=0;
mybit=0;
while(1)
//Set all the relay at off condition
//Set counter to 0
41
{
IE=0x90;
//Enable serial interrupt
while(mybit==1);
// Wait to //recieve a pulse //from
Timer
{
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
//Call Delay Func
}
if(TL0>0x05)
//Compare timer 0 //lower 8 bits to //0000 0101
{
relay1=0;
relay2=0;
relay3=0;
}
else
{
count++; //Increment
//counter
}
}
}
//***************************************************//
void DELAY()
//
Delay function
{
unsigned int X=600000,Y=800000;
while(X--);
while(Y--);
}
//***************************************************//
void transmit_byte(unsigned char byte)
{
SBUF=byte;
//Transmit the data to serial
while(!TI); //SBUF: serial buffer register;data to be
//transferred via TxD line must be placed //in sbuf
TI=0; //TI: SCON.1=transmit interrupt flag.Set
//by h/w at beginning of stop bit in mode //1.must be
//cleared by s/w
}
//when 8051 finishes the transfer of the 8-bit character,it
//raises the TI flag to indicate that it is ready to
//transfer another byte
42
//***************************************************//
void CONVERT_DISPLAY(unsigned int d)
{
unsigned char dig1,dig2,dig3,dig[3];
unsigned char x;
unsigned char temp;
temp=d;
temp=temp/10;
dig1=d%10;
dig2=temp%10;
dig3=temp/10;
//Convert hex to decimal
dig[0]=dig3;
dig[1]=dig2;
dig[2]=dig1;
IE=0;
for(x=0;x<3;x++)
{
temp=dig[x]|0x30;
transmit_byte(temp);
DELAY();
DELAY();
DELAY();
DELAY();
}
}
//***************************************************//
unsigned char SCI_ReceiveByte( void )
{
unsigned char byte;
while(RI!=1);
//RI:SCON.0=recieve interrupt flag.Set by h/w
//at
beginning of stop bit in mode 1.must be
//cleared by s/w
byte = SBUF;
//Recieve serial data
RI=0; //When 8051 receives data serially via RxD, it //places the
//byte in the SBUF register then //raises the RI flag bit //to
indicate that a //byte has been received and should be //picked
//up before it is lost
return byte;
43
}
//***************************************************//
void serial0(void) interrupt 4
{
//Serial Interrupt
rec=SCI_ReceiveByte();
IE=0;
// Disable Serial Interrupt
if(rec=='m')
{
CONVERT_DISPLAY(count);
}
if(rec=='1')
{
relay1=1;
}
if(rec=='2')
{
relay1=0;
}
if(rec=='3')
{
relay2=1;
}
if(rec=='4')
{
relay2=0;
}
if(rec=='5')
{
relay3=1;
}
if(rec=='6')
{
relay3=0;
}
RI=0;
TI=0;
IE=0x90;
}
//Enable Serial Interrupt
44
BIBLIOGRAPHY
[1] ZigBee Alliance, “ZigBee™ Vision for the Home”, November 2006.
http://www.zigbee.org/
[2] Ying-Wen Bai and Chi-huang Hung, “Remote Power On/Off Control and Current
Measurement for Home Electric Outlets based on a Low-Power Embedded Board and
Zigbee Communication”, IEEE International Symposium on Consumer Electronics,
2008.
[3] Riaz Ahamed, “The Role of ZigBee Technology in Future Data Communication
System”, 2005.
[4] IEEE 802.15 WPAN Task Group 4, January 2010.
http://grouper.ieee.org/groups/802/15/pub/TG4.html
[5] Atmel Corporation, “IEEE 802.15.4 MAC”, User guide, November 2006.
[6] LAN-MAN Standards Committee of the IEEE Computer Society, “Wireless Medium
Access Control (MAC) and Physical Layer (PHY) Specifications for Low-Rate Wireless
Personal Area Networks (LR-WPANs)”, IEEE, 2003
[7] Dusan Stevanovic, “Zigbee / IEEE 802.15.4 Standard”, June 2007,
http://www.cse.yorku.ca/~dusan/Zigbee-Standard-Talk.pdf
[8] ZigBee Alliance, “ZigBee Wireless Sensor Applications for Health, Wellness and
Fitness”, March 2009.
www.zigbee.org/imwp/download.asp?ContentID=15585
[9] ZigBee Alliance, “ZigBee Enables Smart Buildings of the Future Today”, April 2007.
45
[10] Atmel Corporation, “8-bit Microcontroller with 8K Bytes Flash – AT89C52”, April
1999.
46
Download