Automatic Detection Of Human And Energy Saving Based On ZIGBEE Communication

The basic idea behind the project is to save electricity by switching off the electrical appliances such as lights, fans and AC’s when no one is present in the room. 
In colleges and companies and in most of the public places no one cares about the switching off the lights when they are coming out of the room, since they are not going to bear the cost. So in such places we need some automatic systems which can detect the presence of human inside the room and automatically switch on the appliances required like fans and lights, And simultaneously off them when no one is present in the room.   

Block diagram
Modules in the block diagram
1. Microcontroller
2. Zigbee
3. PIR sensor
4. Relay

The P89V51RD2 is 80C51 microcontrollers with 64kB Flash and 1024 bytes of data RAM. 
A key feature of the P89V51RD2 is its X2 mode option. The design engineer can choose to run the application with the conventional 80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice the throughput at the same clock frequency. Another way to benefit from this feature is to keep the same performance by reducing the clock frequency by half, thus dramatically reducing the EMI.
The Flash program memory supports both parallel programming and in serial In-System Programming (ISP). Parallel programming mode offers gang-programming at high speed, reducing programming costs and time to market. ISP allows a device to be reprogrammed in the end product under software control. The capability to field/update the application firmware makes a wide range of applications possible.
The P89V51RD2 is also In-Application Programmable (IAP), allowing the Flash program memory to be reconfigured even while the application is running.

Functional Description:
Power-On reset code execution
Following reset, the P89V51RD2 will either enter the Soft ICE mode (if previously enabled via ISP command) or attempt to auto baud to the ISP boot loader. If this auto baud is not successful within about 400 ms, the device will begin execution of the user code.
In-System Programming (ISP)
In-System Programming is performed without removing the microcontroller from the system. The In-System Programming facility consists of a series of internal hardware resources coupled with internal firmware to facilitate remote programming of the P89V51RD2 through the serial port. This firmware is provided by Philips and embedded within each P89V51RD2 device. The Philips In-System Programming facility has made in-circuit programming in an embedded application possible with a minimum of additional expense in components and circuit board area. The ISP function uses five pins (VDD, VSS, TxD, RxD, and RST). Only a small connector needs to be available to interface your application to an external circuit in order to use this feature.
Input/output (I/O) ports 32 of the pins are arranged as four 8-bit I/O ports P0–P3. Twenty-four of these pins are dual purpose with each capable of operating as a control line or part of the data/address bus in addition to the I/O functions. Details are as follows:
Port 0 This is a dual-purpose port occupying pins 32 to 39 of the device. The port is an open-drain bidirectional I/O port with Schmitt trigger inputs. Pins that have 1s written to them float and can be used as high-impedance inputs. The port may be used with external memory to provide a multiplexed address and data bus. In this application internal pull-ups are used when emitting 1s. The port also outputs the code bytes during EPROM programming. External pull-ups are necessary during program verification.
 Port 1 This is a dedicated I/O port occupying pins 1 to 8 of the device. The pins are connected via internal pull-ups and Schmitt trigger input. Pins that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs; as inputs, pins that are externally pulled low will source current via the internal pull-ups. The port also receives the low-order address byte during program memory verification. Pins P1.0 and P1.1 could also function as external inputs for the third timer/counter i.e.:
(P1.0) T2 Timer/counter 2 external count input/clockout
(P1.1) T2EX Timer/counter 2 reload/capture/direction control
Port 2 This is a dual-purpose port occupying pins 21 to 28 of the device. The specification is similar to that of port 1. The port may be used to provide the high-order byte of the address bus for external program memory or external data memory that uses 16-bit addresses. When accessing external data memory that uses 8-bit addresses, the port emits the contents of the P2 register. Some port 2 pins receive the high-order address bits during EPROM programming and verification. 
 Port 3 This is a dual-purpose port occupying pins 10 to 17 of the device. The specification is similar to that of port 1. These pins, in addition to the I/O role, serve the special features of the 80C51 family; the alternate functions are summarized below:
P3.0 RxD serial data input port
P3.1 TxD serial data output port
P3.2 INT0 external interrupt 0
P3.3 INT1 external interrupt 1
P3.4 T0 timer/counter 0 external input
P3.5 T1 timer/counter 1 external input
P3.6 WR external data memory writes strobe
P3.7 RD external data memory read strobe.
Timers/counters 0 and 1
The two 16-bit Timer/Counter registers: Timer 0 and Timer 1 can be configured to
operate either as timers or event counters (see Table 12 and Table 13). In the ‘Timer’ function, the register is incremented every machine cycle. Thus, one can think of it as counting machine cycles. Since a machine cycle consists of six oscillator periods, the count rate is 1¤6 of the oscillator frequency. In the ‘Counter’ function, the register is incremented in response to a 1-to-0 transition at its corresponding external input pin, T0 or T1. In this function, the external input is sampled once every machine cycle.
When the samples show a high in one cycle and a low in the next cycle, the count is incremented. The new count value appears in the register in the machine cycle following the one in which the transition was detected. Since it takes two machine cycles (12 oscillator periods) for 1-to-0 transition to be recognized, the maximum count rate is 1¤12 of the oscillator frequency. There are no restrictions on the duty cycle of the external input signal, but to ensure that a given level is sampled at least once before it changes, it should be held for at least one full machine cycle. In addition to the ‘Timer’ or ‘Counter’ selection, Timer 0 and Timer 1 have four operating modes from which to select.
The ‘Timer’ or ‘Counter’ function is selected by control bits C/T in the Special Function Register TMOD. These two Timer/Counters have four operating modes, which are selected by bit-pairs (M1, M0) in TMOD. Modes 0, 1, and 2 are the same for both Timers/Counters. Mode 3 is different. The four operating modes are described in the following text.
TMOD - Timer/Counter mode control register (address 89H) bit allocation
Not bit addressable; Reset value: 00000000B; Reset source(s): any source

Mode 0
Putting either Timer into Mode 0 makes it look like an 8048 Timer, which is an 8-bit Counter with a fixed divide-by-32 prescaler. Figure 7 shows Mode 0 operation.

In this mode, the Timer register is configured as a 13-bit register. As the count rolls over from all 1s to all 0s, it sets the Timer interrupt flag TFn. The count input is enabled to the Timer when TRn = 1 and either GATE = 0 or INTn = 1. (Setting GATE = 1 allows the Timer to be controlled by external input INTn, to facilitate pulse width measurements). TRn is a control bit in the Special Function Register TCON (Figure 6). The GATE bit is in the TMOD register.
The 13-bit register consists of all 8 bits of THn and the lower 5 bits of TLn. The upper 3 bits of TLn are indeterminate and should be ignored. Setting the run flag (TRn) does not clear the registers. Mode 0 operation is the same for Timer 0 and Timer 1 (see Figure 7). There are two
different GATE bits, one for Timer 1 (TMOD.7) and one for Timer 0 (TMOD.3).

Mode 1
Mode 1 is the same as Mode 0, except that all 16 bits of the timer register (THn and TLn) are used.

Mode 2
Mode 2 configures the Timer register as an 8-bit Counter (TLn) with automatic reload, as shown in Figure 9. Overflow from TLn not only sets TFn, but also reloads TLn with the contents of THn, which must be preset by software. The reload leaves THn unchanged. Mode 2 operation is the same for Timer 0 and Timer 1.

Mode 3
When timer 1 is in Mode 3 it is stopped (holds its count). The effect is the same as setting TR1 = 0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate 8-bit counters. The logic for Mode 3 and Timer 0 is shown in Figure 10. TL0 uses the Timer 0 control bits: T0C/T, T0GATE, TR0, INT0, and TF0. TH0 is locked into a timer function (counting machine cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls the ‘Timer 1’ interrupt. Mode 3 is provided for applications that require an extra 8-bit timer. With Timer 0 in Mode 3, the P89V51RD2 can look like it has an additional Timer.
Note: When Timer 0 is in Mode 3, Timer 1 can be turned on and off by switching it into and out of its own Mode 3. It can still be used by the serial port as a baud rate generator, or in any application not requiring an interrupt.

Timer 2
Timer 2 is a 16-bit Timer/Counter which can operate as either an event timer or an event counter, as selected by C/T2 in the special function register T2CON. Timer 2 has four operating modes: Capture, Auto-reload (up or down counting), Clock-out, and Baud Rate Generator which are selected according to Table 17 using T2CON (Table 18 and Table 19) and T2MOD .

The UART operates in all standard modes. Enhancements over the standard 80C51 UART include Framing Error detection, and automatic address recognition.
Mode 0
Serial data enters and exits through RxD and TxD outputs the shift clock. Only 8 bits are transmitted or received, LSB first. The baud rate is fixed at 1¤6 of the CPU clock frequency. UART configured to operate in this mode outputs serial clock on TxD line no matter whether it sends or receives data on RxD line.
Mode 1
10 bits are transmitted (through TxD) or received (through RxD): a start bit (logical 0), 8 data bits (LSB first), and a stop bit (logical 1). When data is received, the stop bit is stored in RB8 in Special Function Register SCON. The baud rate is variable and is determined by the Timer 1¤2 overflow rate.
Mode 2
11 bits are transmitted (through TxD) or received (through RxD): start bit (logical 0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (logical 1). When data  is transmitted, the 9th data bit (TB8 in SCON) can be assigned Or (e.g. the parity bit (P, in the PSW) could be moved into TB8). When data is received, the 9th data bit goes into RB8 in Special Function Register SCON, while the stop bit is ignored. The baud rate is programmable to either 1¤16 or 1¤32 of the CPU clock frequency, as determined by the SMOD1 bit in PCON.
Mode 3
11 bits are transmitted (through TxD) or received (through RxD): a start bit (logical 0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (logical 1). In fact, Mode 3 is the same as Mode 2 in all respects except baud rate. The baud rate in Mode 3 is variable and is determined by the Timer 1/2 overflow rate.

Watchdog timer
The device offers a programmable Watchdog Timer (WDT) for fail safe protection against software deadlock and automatic recovery. To protect the system against software deadlock, the user software must refresh the WDT within a user-defined time period. If the software fails to do this periodical refresh, an internal hardware reset will be initiated if enabled (WDRE = 1). The software can be designed such that the WDT times out if the program does not work properly. The WDT in the device uses the system clock (XTAL1) as its time base. So strictly speaking, it is a Watchdog counter rather than a Watchdog timer. The WDT register will increment every 344,064 crystal clocks. The upper 8-bits of the time base register (WDTD) are used as the reload register of the WDT. The WDTS flag bit is set by WDT overflow and is not changed by WDT reset. User software can clear WDTS by writing ‘1' to it. Figure 19 provides a block diagram of the WDT. Two SFRs (WDTC and WDTD) control Watchdog timer operation. During idle mode, WDT operation is temporarily suspended, and resumes upon an interrupt exit from idle. The time-out period of the WDT is calculated as follows:
Period = (255 - WDTD) ´ 344064 ´ 1/fCLK (XTAL1)
Where WDTD is the value loaded into the WDTD register and fosc is the oscillator frequency. 

Security Bit
The Security Bit protects against software piracy and prevents the contents of the
flash from being read by unauthorized parties in Parallel Programmer Mode. It also
protects against code corruption resulting from accidental erasing and programming
to the internal flash memory.
When the Security Bit is activated all parallel programming commands except for
Chip-Erase are ignored (thus the device cannot be read). However, ISP reads of the
user’s code can still be performed if the serial number and length has not been
programmed. Therefore, when a user requests to program the Security Bit, the
programmer should prompt the user and program a serial number into the

A system reset initializes the MCU and begins program execution at program 
Memory location 0000H. The reset input for the device is the RST pin. In order to reset the
device, a logic level high must be applied to the RST pin for at least two machine
cycles (24 clocks), after the oscillator becomes stable. ALE, PSEN are weakly pulled
high during reset. During reset, ALE and PSEN output a high level in order to perform
a proper reset. This level must not be affected by external element. A system reset
will not affect the 1 kbyte of on-chip RAM while the device is running, however, the
contents of the on-chip RAM during power up are indeterminate.
Power-on Reset
At initial power up, the port pins will be in a random state until the oscillator has
started and the internal reset algorithm has weakly pulled all pins HIGH. Powering up
the device without a valid reset could cause the MCU to start executing instructions
from an indeterminate location. Such undefined states may inadvertently corrupt the
code in the flash.
When power is applied to the device, the RST pin must be held HIGH long enough for
the oscillator to start up (usually several milliseconds for a low frequency crystal), in
addition to two machine cycles for a valid power-on reset. An example of a method to
extend the RST signal is to implement a RC circuit by connecting the RST pin to VDD
through a 10 mF capacitor and to VSS through an 8.2 kW resistor as shown in
Figure 26. Note that if an RC circuit is being used, provisions should be made to
ensure the VDD rise time does not exceed 1 millisecond and the oscillator start-up
time does not exceed 10 milliseconds.
For a low frequency oscillator with slow start-up time the reset signal must be
extended in order to account for the slow start-up time. This method maintains the
necessary relationship between VDD and RST to avoid programming at an
indeterminate location, which may cause corruption in the code of the flash. The
power-on detection is designed to work as power-up initially, before the voltage
reaches the brown-out detection level. The POF flag in the PCON register is set to
indicate an initial power-up condition. The POF flag will remain active until cleared by
software. Please refer to the PCON register definition for detail information.
Following reset, the P89V51RD2 will either enter the SoftICE mode (if previously
enabled via ISP command) or attempt to autobaud to the ISP boot loader. If this
autobaud is not successful within about 400 ms, the device will begin execution of the
user code.

Software reset
The software reset is executed by changing FCF[1] (SWR) from ‘0’ to ‘1’. A software
reset will reset the program counter to address 0000H. All SFR registers will be set to
their reset values, except FCF[1] (SWR), WDTC[2] (WDTS), and RAM data will not
be altered.

Brown-out detection reset
The device includes a brown-out detection circuit to protect the system from severed supplied voltage VDD fluctuations. The P89V51RD2’s brown-out detection threshold is 3.85 V. For brown-out voltage parameters, please refer to Table 67 and Table 68.
When VDD drops below this voltage threshold, the brown-out detector triggers the
circuit to generate a brown-out interrupt but the CPU still runs until the supplied
voltage returns to the brown-out detection voltage VBOD. The default operation for a
brown-out detection is to cause a processor reset.
VDD must stay below VBOD at least four oscillator clock periods before the brown-out
detection circuit will respond.
Brown-out interrupt can be enabled by setting the EBO bit in IEA register (address
E8H, bit 3). If EBO bit is set and a brown-out condition occurs, a brown-out interrupt
will be generated to execute the program at location 004BH. It is required that the
EBO bit be cleared by software after the brown-out interrupt is serviced. Clearing
EBO bit when the brown-out condition is active will properly reset the device. If
brown-out interrupt is not enabled, a brown-out condition will reset the program to
resume execution at location 0000H.
Interrupt priority and polling sequence
The device supports eight interrupt sources under a four level priority scheme.
Table 43 summarizes the polling sequence of the supported interrupts. Note that the
SPI serial interface and the UART share the same interrupt vector.

Idle mode
Idle mode is entered setting the IDL bit in the PCON register. In idle mode, the program
counter (PC) is stopped. The system clock continues to run and all interrupts and peripherals remain active. The on-chip RAM and the special function registers hold their data during this mode.
The device exits idle mode through either a system interrupt or a hardware reset. Exiting idle mode via system interrupt, the start of the interrupt clears the IDL bit and exits idle mode.
After exit the Interrupt Service Routine, the interrupted program resumes execution
beginning at the instruction immediately following the instruction which invoked the idle
mode. A hardware reset starts the device similar to a power-on reset.

Power-down mode
The Power-down mode is entered by setting the PD bit in the PCON register. In the
Power-down mode, the clock is stopped and external interrupts are active for level
sensitive interrupts only. SRAM contents are retained during Power-down, the
minimum VDD level is 2.0 V.
The device exits Power-down mode through either an enabled external level sensitive
interrupt or a hardware reset. The start of the interrupt clears the PD bit and exits
Power-down. Holding the external interrupt pin low restarts the oscillator, the signal
must hold low at least 1024 clock cycles before bringing back high to complete the
exit. Upon interrupt signal restored to logic VIH, the interrupt service routine program
execution resumes beginning at the instruction immediately following the instruction
which invoked Power-down mode. A hardware reset starts the device similar to
power-on reset.
To exit properly out of Power-down, the reset or external interrupt should not be
executed before the VDD line is restored to its normal operating voltage. Be sure to
hold VDD voltage long enough at its normal operating level for the oscillator to restart
and stabilize (normally less than 10 ms).

2. Earth Quake Detection sensor
Here we have used 2 electrodes to detect the earth quake. One end of first electrode is connected to 5v and the other end is dipped in ground. One end of second electrode is connected to channel one of the ADC and the other end is dipped inside the earth. When there is no earth quake we can get some voltage on the second electrode due to the moisture present in the earth. When there is an earth quake the output on the second electrode will be zero. By this we can detect the presence of earth quake. 
But actually we need to use a P-wave Detector (non-destructive primary waves that travel more quickly through the Earth's crust than do the destructive secondary and Rayleigh waves) connected to the channel one of the ADC. But due to the unavailability of the sensor module in the market we have gone for the above logic.

Zigbee module
  ZigBee is a specification for a suite of high level communication protocols using small, low-power digital radios based on the IEEE 802.15.4-2006 standard for wireless personal area networks (WPANs), such as wireless headphones connecting with cell phones via short-range radio. The technology defined by the ZigBee specification is intended to be simpler and less expensive than other WPANs, such as Bluetooth. ZigBee is targeted at radio-frequency (RF) applications that require a low data rate, long battery life, and secure networking.

The ZigBee Alliance is a group of companies which maintain and publish the ZigBee standard.802 groups is the section that deals with network operations and technologies.

  • Group 15 works more specifically with wireless networking.
  • Task Group 4 drafted the 802.15.4 standard for a low data rate wireless personal area network (WPAN).
  • Technological Standard Created for Control and Sensor Networks 
  • Based on the IEEE 802.15.4 Standard 
  • Created by the ZigBee Alliance
  • Named for erratic, zigzagging patterns of bees between flowers
  • Symbolizes communication between nodes in a mesh network

This technology allows for devices to communicate with one another with very low power consumption, allowing the devices to run on simple batteries for several years. Zigbee is targeting various forms of automation, as the low data rate communication is ideal for sensors, monitors, and the like. Home automation is one of the key market areas for Zigbee.

The protocols build on recent algorithmic research (Ad-hoc On-demand Distance Vector, neuRFon) to automatically construct a low-speed ad-hoc network of nodes. In most large network instances, the network will be a cluster of clusters. It can also form a mesh or a single cluster. The current profiles derived from the ZigBee protocols support beacon and non-beacon enabled networks.

In non-beacon-enabled networks (those whose beacon order is 15), an unslotted CSMA/CA channel access mechanism is used. In this type of network, ZigBee Routers typically have their receivers continuously active, requiring a more robust power supply. However, this allows for heterogeneous networks in which some devices receive continuously, while others only transmit when an external stimulus is detected. The typical example of a heterogeneous network is a wireless light switch: the ZigBee node at the lamp may receive constantly, since it is connected to the mains supply, while a battery-powered light switch would remain asleep until the switch is thrown. The switch then wakes up, sends a command to the lamp, receives an acknowledgment, and returns to sleep. In such a network the lamp node will be at least a ZigBee Router, if not the ZigBee Coordinator; the switch node is typically a ZigBee End Device.

In beacon-enabled networks, the special network nodes called ZigBee Routers transmit periodic beacons to confirm their presence to other network nodes. Nodes may sleep between beacons, thus lowering their duty cycle and extending their battery life. Beacon intervals may range from 15.36 milliseconds to 15.36 ms * 214 = 251.65824 seconds at 250 kbit/s, from 24 milliseconds to 24 ms * 214 = 393.216 seconds at 40 kbit/s and from 48 milliseconds to 48 ms * 214 = 786.432 seconds at 20 kbit/s. However, low duty cycle operation with long beacon intervals requires precise timing, which can conflict with the need for low product cost.

In general, the ZigBee protocols minimize the time the radio is on so as to reduce power use. In beaconing networks, nodes only need to be active while a beacon is being transmitted. In non-beacon-enabled networks, power consumption is decidedly asymmetrical: some devices are always active, while others spend most of their time sleeping.

ZigBee devices are required to conform to the IEEE 802.15.4-2003 Low-Rate Wireless Personal Area Network (WPAN) standard. The standard specifies the lower protocol layers—the physical layer (PHY), and the medium access control (MAC) portion of the data link layer (DLL). This standard specifies operation in the unlicensed 2.4 GHz, 915 MHz and 868 MHz ISM bands. In the 2.4 GHz band there are 16 ZigBee channels, with each channel requiring 5 MHz of bandwidth. The center frequency for each channel can be calculated as, FC = (2405 + 5 * (ch - 11)) MHz, where ch = 11, 12, ..., 26.

The radios use direct-sequence spread spectrum coding, which is managed by the digital stream into the modulator. BPSK is used in the 868 and 915 MHz bands, and orthogonal QPSK that transmits two bits per symbol is used in the 2.4 GHz band. The raw, over-the-air data rate is 250 kbit/s per channel in the 2.4 GHz band, 40 kbit/s per channel in the 915 MHz band, and 20 kbit/s in the 868 MHz band. Transmission range is between 10 and 75 (up to 1500 meters for zigbee pro.) meters (33 and 246 feet), although it is heavily dependent on the particular environment. The maximum output power of the radios is generally 0 dBm (1 mW).

The basic channel access mode is "carrier sense, multiple access/collision avoidance" (CSMA/CA). That is, the nodes talk in the same way that people converse; they briefly check to see that no one is talking before they start. There are three notable exceptions to the use of CSMA. Beacons are sent on a fixed timing schedule, and do not use CSMA. Message acknowledgments also do not use CSMA. Finally, devices in Beacon Oriented networks that have low latency real-time requirements may also use Guaranteed Time Slots (GTS), which by definition do not use CSMA.

Wireless Networks
A wireless network consists of nodes that are not connected by cables, but communicate with each other via radio, infra-red or other electromagnetic radiation. Therefore, each node is able to transmit and receive messages through the relevant medium. In addition, most nodes run one or more applications to perform their function in the network - for example, temperature and humidity measurement. 

Motivation for ZigBee
ZigBee is a worldwide open standard for wireless radio networks in the monitoring and control fields. The standard was developed by the ZigBee Alliance (an association of international companies) to meet the following principal needs:
low cost 
ultra-low power consumption
use of unlicensed radio bands 
cheap and easy installation
flexible and extendable networks 
integrated intelligence for network set-up and message routing

Some of the above requirements are related - for example, the need for extremely low power consumption is motivated by the use of battery-powered nodes which can be installed cheaply and easily, without any power cabling, in difficult locations.

Typical Application Areas
Application areas that are suitable for ZigBee networks are likely to have the following characteristics or requirements:
low data rates (less than 250kbps)
nodes which are idle (not transmitting/receiving) for long periods
node locations where cables would be difficult or expensive to install
a need to modify the network (add, remove or move nodes) while in service

The following are typical application areas in which ZigBee provides a low-cost solution (this is not an exhaustive list):

Commercial Building and Home Automation: Electronic control within a building or home can be implemented through wireless networks - example applications are HVAC (heating, ventilation and air-conditioning), lighting, curtains/blinds, doors, locks and home entertainment systems.

Security: Another important application within commercial buildings and the home is security – both intruder and fire detection.

Healthcare: This field employs sensors and diagnostic devices that can be networked by means of a wireless network. Applications include monitoring during healthcare programmes such as fitness training, in addition to medical applications such as patient monitoring.

Vehicle Monitoring: Vehicles usually contain many sensors and diagnostic devices, and provide ideal applications for wireless networks. A prime example is the use of pressure sensors in tyres, which cannot be connected by cables.

Agriculture: Wireless networks can help farmers monitor land and environmental conditions in order to optimise their crop yields. Such networks may require wide geographical coverage, but ZigBee addresses this issue by offering network topologies that allow the relaying of messages from node to node across the network.

ZigBee Frequencies
Operates in Unlicensed Bands
ISM 2.4 GHz Global Band at 250kbps
868 MHz European Band at 20kbps
915 MHz North American Band at 40kbps

Radio Communication
This page details the radio frequency bands available to ZigBee networks. In a ZigBee network, radio transmission/reception is handled by IEEE 802.15.4 (the lowest level in the software stack). 

Frequency Bands 
IEEE 802.15.4 (and therefore ZigBee) was designed to operate in unlicensed radio frequency (RF) bands. The unlicensed RF bands are not the same in all territories of the world, but IEEE 802.15.4 employs three possible bands, at least one of which should be available in a given territory. The three bands are centred on the following frequencies: 868, 915 and 2400 MHz.
The characteristics and geographical applicability of these RF bands are shown in the diagram on the right, and explained below:
· Each RF band is divided into a number of channels 
· There are 27 channels across the three RF bands, numbered 0 to 26 
· The three RF bands have different data rates: 20, 40 and 250 kbps (with increasing frequency) 
The 868- and 915-MHz frequency bands offer certain advantages such as fewer users, less interference, and less absorption and reflection. However, the 2400-MHz band is far more widely adopted for a number of reasons, including:
· Worldwide availability for unlicensed use 
· Higher data rate (250 kpbs) and more channels 
· Lower power (transmit/receive are on for a shorter time due to higher data rate) 

Channel Selection
Energy detection functionality is included that can be used by higher software layers to avoid interference between radio communications. The best frequency channel can be selected at initialisation.

Range of Transmission
The range of a radio transmission is the distance the radio communication can travel before it becomes undetectable. This is dependent on the operating environment - for example, inside or outside a building. The best results are obtained in an open area. Inside a building, the range is reduced due to absorption, reflection, diffraction and standing wave effects caused by walls and other solid objects.
With a standard device (around 0 dBm output power): 
· In an open area, a range of over 200 metres can typically be achieved (Jennic has measured in excess of 450 metres) 
· In a building, a range of 30 metres can typically be achieved 
However, high-power modules (greater than 15 dBm output power) can achieve a range of 5 times greater than a standard module.     
Low Power Consumption 
An important aim of ZigBee and the IEEE 802.15.4 standard is the provision for building autonomous, low-powered devices. These devices are powered from an internal source, such as a battery pack or solar cells, and therefore need no external power supply or power cabling. There are many wireless applications that require this type of device, from light-switches, active tags and security detectors to remote industrial control and monitoring. This page describes the advantages of and the methods of achieving such devices.
Advantages of Autonomy 
From a user perspective, autonomously powered devices have the following advantages: 
· Easy and low-cost installation of devices: No need to connect to a separate power supply 
· Flexible location of devices: Can be installed in difficult places where there is no power supply, and can even be used as mobile devices 
· Easily modified network: Devices can easily be added or removed, on a temporary or permanent basis 

Achieving Autonomy 
Autonomous network devices are generally battery-powered or solar powered:
· Battery-powered devices: Since these devices are generally small, they use low-capacity batteries. Infrequent device. maintenance is often another requirement, meaning long periods between battery replacement and the need for long-life batteries 
· Solar-powered devices: Solar power is an example of “energy harvesting” in which the device absorbs and stores energy from its surroundings. In this case, the energy is collected in the form of light and the device must be located in a well-lit environment. 
The power consumption of these devices must be carefully managed to make optimum use of very limited power resources over an extended period of time. These devices therefore present significant technical challenges to keep power consumption low. The methods employed to minimise power consumption include the following: 
· Low duty cycle: Most of the power consumption of a wireless network device corresponds to the times when the device is active - that is, transmitting or receiving. The active time as a proportion of the time interval between activity is called the duty cycle. Power use is optimised by using extremely low duty cycles, so that the device is active for a very small fraction of the time. This is helped by making the transmission/reception time short and the time interval between transmission/reception long. 
· Sleep mode: When not transmitting or receiving, the device should revert to a sleep mode during which the power consumption is minimal. 
· Modulation: The modulation schemes used to transmit data (BPSK for 868/915 MHz, O-QPSK for 2400 MHz) minimise power consumption by using a peak-to-average power ratio of one.    
In practice, not all devices in a network can be autonomously powered, particularly those that need to be switched on all the time (and cannot sleep), such as Routers and Co-ordinators. Such devices can often be installed in a mains-powered appliance that is permanently connected to the mains supply (even if not switched on) - for example, a ceiling lamp or an electric radiator.   
What is Wireless Sensor Network(WSN)?
The random distributed small nodes with sensors, the data processing unit and the connection module constitute network through a self-organizing way
By the sensor’s detecting with hot, infrared, sonar, and radar, nodes survey and send the data to the sink nodes using the multi-hop communication. 
Finally, data of the entire area are transferred to the long-distance centers.
Some limitations are exposed : 
Sensor nodes’ number, ability of communication, Power supply and ability of data processing
So, ZigBee was improved to solve these problems

Network Topologies 
The way that a message is routed from one network node to another depends on the network topology. This page provides a brief description of the possible topologies of a ZigBee network. The ZigBee topologies are described in more detail later in this course.
A ZigBee network can adopt one of the three topologies: Star, Tree, Mesh. These are illustrated on the right and briefly described below.
Star Topology 
A Star network has a central node, which is linked to all other nodes in the network. All messages travel via the central node.
Tree Topology 
A Tree network has a top node with a branch/leaf structure below. To reach its destination, a message travels up the tree (as far as necessary) and then down the tree.
Mesh Topology
A Mesh network has a tree-like structure in which some leaves are directly linked. Messages can travel across the tree, when a suitable route is available.

  There is always one node that takes a co-ordinating role in a network - the central node in a Star topology, the top node in a Tree/Mesh topology. There must also be nodes with the role of relaying messages from one neighbouring node to another. The different node types in a ZigBee network are described later in the course.   
ZigBee networks provide reliability and security mechanisms that make them highly dependable - that is, you can depend on ZigBee to provide a secure environment in which the network operates reliably (with minimal disruption). This page outlines the available reliability and security measures.
Reliable Operation
ZigBee employs a range of techniques to ensure reliable communications - that is, to ensure communications reach their destinations uncorrupted. Corruption could result, for example, from radio interference or poor transmission/reception conditions.
· Channel Selection: When a ZigBee network is initialised, the channels of the chosen RF band are assessed for activity. The results can be used to automatically select a quiet channel for the network to operate in. 
· Listen Before Sending: To avoid conflicting transmissions (more than one device transmitting in the same frequency channel at the same time), before beginning a transmission, a node will listen on the relevant channel to check whether it is clear. It will only transmit if no activity is detected on the channel, otherwise the node waits for a random period of time before re-trying. 
· Data Coding: ZigBee networks apply a coding mechanism to radio transmissions. Due to this coding, there is a higher probability that a message will get through to its destination intact, even if there are conflicting transmissions. 
· Acknowledgements: A system of message acknowledgements is available in ZigBee to confirm that messages reach their destinations. When a message arrives at its destination, the receiving device sends an acknowledgement to say the message has arrived. If the sending device does not receive an acknowledgement within a certain time interval, it resends the original message (it can resend the message several times until the message has been acknowledged). 
· Route Discovery: In a Mesh topology, the network has built-in intelligence to ensure that messages reach their destinations. If the default route to the destination node is down, due to a failed intermediate node or link, the network can “discover” and use alternative routes for message delivery. 
The above reliability measures allow a ZigBee network to operate in the same space and RF band as other ZigBee networks. In addition, ZigBee networks can operate in the neighbourhood of networks based on other standards, such as Wi-Fi and Bluetooth.

Secure Operation
ZigBee networks are highly secure - they incorporate measures to prevent intrusion from potentially hostile parties and from neighbouring ZigBee networks. For this purpose, a “Security Toolbox” is included in a ZigBee network, offering:
· Access Control Lists: Only pre-defined “friendly" nodes can join a network. 
· 128-bit AES-based Encryption: A very high-security key-based encryption system, preventing external agents from interpreting ZigBee network data. 
· Message Freshness Timers: Timed-out messages are rejected, preventing message replay attacks on the network. An example of a replay attack would be a malicious individual recording the open command for a garage door opener, and then replaying it to gain entry

Alliance Standards 
ZigBee is an open standard devised by the ZigBee Alliance. The standard includes measures to ensure that devices in a ZigBee network can operate together or, at least, exist alongside each other. The standard also includes a system of "profiles" to provide a standardised framework in which network designers can develop their software. This page outlines these measures.

Co-existence and Interoperability
Any device designed for use in a ZigBee network must comply with the ZigBee standard. This ensures “co-existence” and, to a certain extent, “interoperability” between devices - these terms are defined below: 
· Co-existence: The ability of a device to exist in the same network as other devices (possibly from other manufacturers) without preventing them from working. 
· Interoperability: The ability of a device to operate in conjunction with other devices (possibly from other manufacturers) - that is, to communicate and function with them. 
For the purpose of interoperability, the ZigBee Alliance has introduced the concept of a device “profile”, which contains the essential properties of a device for a particular application or market. There are two classes of profile, the "stack profile" and the "application profile", described below.
Stack Profile: This determines the resources that the ZigBee software stack provides for the configuration of the network, such as the network type and shape, and the features that are available to applications (such as the types of security). Three market profiles plus a generic profile have so far been defined by the ZigBee Alliance: Home Controls, Building Automation, Plant Control, Network Specific.
Application Profile: This is associated with a particular stack profile and addresses the needs of a specific application or market - for example, the ZigBee Alliance has defined the Home Controls-Lighting (HCL) application profile for use in controlling lighting in the home. It defines a number of devices and functions which are needed or are useful for controlling domestic lighting, such as switches, dimmers, occupancy sensors and load controllers (which control the light sources). Application profiles can be public or private:
· Public profiles are those introduced by the ZigBee Alliance for use by manufacturers implementing devices that need to work with devices from other manufacturers - for example, to allow a switch from one vendor to work with the light fitting from another vendor. Products implemented to a public profile are tested and certified for conformance to that profile. 
· Private profiles are also known as "non-public" profiles - they are proprietry profiles introduced by manufacturers to allow them to market products for which public profiles do not exist. This also allows manufacturers to differentiate their products from others in the same market segment. 

Node Types 
This page describes the types of node that are used in a ZigBee network. Reference will be made to the toplogies introduced on the previous page (Star, Tree, Mesh), but these topologies will be described in more detail later in this module. 

The ZigBee standard has the capacity to address up to 65535 nodes in a single network. However, there are only three general types of node: 
1. Co-ordinator 
2. End Device 
3. Router
These node types are described below.
These roles described below exist at the network level – a ZigBee node may also be performing tasks at the application level independent of the role it plays in the network. For instance, a network of ZigBee devices measuring temperature may have a temperature sensor application in each node, irrespective of whether they are End Devices, Routers or the Co-ordinator.

What makes ZigBee different?

  • Diverse market penetration.
  • Low power, sophisticated networking. 
  • Standardization.
  • Focuses on low data rate, low duty cycle connectivity.
  • ZigBee Market Goals
  • Global band operation, 2.4 GHz, 915 MHz, 868 MHz.
  • Unrestricted geographic use.
  • RF penetration through walls and ceilings.
  • Automatic or semi-automatic installation.
  • Ability to add or remove devices.
  • Cost advantageous.
  • ZigBee hardware must be able to communicate over a 10 to 75 meter range.
  • Typical 2.4 GHz hardware has demonstrated 30 meters indoors and over 100 meters outdoors.
  • Up to 2 years of battery life on standard alkaline Batteries.

1. Coordinator:
All ZigBee networks must have one (and only one) Co-ordinator, irrespective of the network topology. 
· In the Star topology, the Co-ordinator is the central node in the network. 
· In the Tree and Mesh topologies, the Co-ordinator is the top (root) node in the network. 
This is illustrated below, where the Co-ordinator is colour-coded in dark blue.

At the network level, the Co-ordinator is mainly needed at system initialisation. The tasks of the Co-ordinator at the network layer are:
· Selects the frequency channel to be used by the network (usually the one with the least detected activity) 
· Starts the network 
· Allows other devices to connect to it (that is, to join the network) 
The Co-ordinator can also provide message routing (for example, in a Star network), security management and other services.

  In some circumstances, the network will be able to operate normally if the Co-ordinator fails or is switched off. This will not be the case if the Co-ordinator provides a routing path through the network (for instance, in a Star topology, where it is needed to relay messages). Similarly the Co-ordinator provides services at the Application layer and if these services are being used (for example, Co-ordinator binding), the Co-ordinator must be able to provide them at all times.   

Zigbee End Device:
            End Devices are always located at the extremeties of a network: 
· In the Star topology, they are perimeter nodes 
· In the Tree and Mesh toplogies, they are leaf nodes 
This is illustrated below, where the End Devices are colour-coded in light blue.

The main tasks of an End Device at the network level are sending and receiving messages. Note that End Devices cannot relay messages and cannot allow other nodes to connect to the network through them. 
An End Device can often be battery-powered and, when not transmitting or receiving, can sleep in order to conserve power. 
Networks with Tree or Mesh topologies need at least one Router. The main tasks of a Router are:
· Relays messages from one node to another 
· Allows child nodes to connect to it 
In a Star topology, these functions are handled by the Co-ordinator and, therefore, a Star network does not need Routers.
In Tree and Mesh topologies, Routers are located as follows: 
· In a Tree topology, Routers are normally located in network positions that allow messages to be passed up and down the tree. 
· In a Mesh topology, a Router can be located anywhere that a message passing node is required. 
However, in all topologies (Star, Tree and Mesh), Router devices can be located at the extremeties of the network, if they run applications that are needed in these locations - in this case, the Router will not perform its message relay function, unless in a Mesh network (see above).
The possible positions of Routers in the different network topologies are illustrated below, where the Routers are colour-coded in red:
Note that a Router cannot sleep. 

Node Addresses 
In a ZigBee network, each node must have unique identification. This is achieved by means of two addresses: 
· IEEE address 
· Network address 
These are described below.

IEEE Address
This is a 64-bit address, allocated by the IEEE, which uniquely identifies the device – no two devices in the world can have the same IEEE address. It is also called the MAC address or the extended address.

Network Address
This is a 16-bit address identifies the node in the network - it is local to that network (thus, two nodes on separate networks may have the same network address). Network addresses are allocated by the parent node (Router or Co-ordinator) when a node joins a network. It is also called the short address.
The Co-ordinator always takes the network address 0x0000.

PIR Sensor
General Description
The PIR (Passive Infra-Red) Sensor is a pyroelectric device that detects motion by measuring changes in the infrared levels emitted by surrounding objects. This motion can be detected by checking for a high signal on a single I/O pin.
· Single bit output
· Small size makes it easy to conceal
· Compatible with all Parallax microcontrollers
Application Ideas
· Alarm Systems
· Halloween Props
· Robotics

Quick Start Circuit
Theory of Operation
Pyroelectric devices, such as the PIR sensor, have elements made of a crystalline material that generates an electric charge when exposed to infrared radiation. The changes in the amount of infrared striking the element change the voltages generated, which are measured by an on-board amplifier. The device contains a special filter called a Fresnel lens, which focuses the infrared signals onto the element. As the ambient infrared signals change rapidly, the on-board amplifier trips the output to indicate motion.

Pin Definitions and Ratings
Connecting and Testing
Connect the 3-pin header to your circuit so that the minus (-) pin connects to ground or Vss, the plus (+) pin connects to +5 volts or Vdd and the OUT pin connects to your microcontroller’s I/O pin. One easy way to do this would be to use a standard servo/LCD extension cable, available separately from Parallax(#805-00002). This cable makes it easy to plug sensor into the servo headers on our Board Of Education or Professional Development Board. If you use the Board Of Education, be sure the servo voltage jumper (located between the 2 servo header blocks) is in the Vdd position, not Vin. If you do not have this jumper on your board you should manually connect to Vdd through the breadboard.
You may also plug the sensor directly into the edge of the breadboard and connect the signals from
there. Remember the position of the pins when you plug the sensor into the breadboard.
Once the sensor warms up (settles) the output will remain low until there is motion, at which time the output will swing high for a couple of seconds, then return low. If motion continues the output will cycle in this manner until the sensors line of sight of still again.

The PIR Sensor requires a ‘warm-up’ time in order to function properly. This is due to the settling time involved in ‘learning’ its environment. This could be anywhere from 10-60 seconds. During this time there should be as little motion as possible in the sensors field of view.

The PIR Sensor has a range of approximately 20 feet. This can vary with environmental conditions. The sensor is designed to adjust to slowly changing conditions that would happen normally as the day progresses and the environmental conditions change, but responds by toggling its output when sudden changes occur, such as when there is motion.

No comments:

Post a Comment

leave your opinion