Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
SIM UNIVERSITY
SCHOOL OF SCIENCE AND TECHNOLOGY
SMART DEVICES FOR HOME ASSISTANCE
STUDENT : LIM ZONG YAO(W0704223)
SUPERVISOR: CARLOS ACOSTA
PROJECT CODE: JUL2010/ENG/065
A project report submitted to SIM University
in partial fulfilment of the requirements for the degree of
Bachelor of Engineering in Electronics
MAY 2010
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Abstract
With increasing technology and continuous demand for comfortable lives, the dream of a
hi-tech, all round automatic environment is not distant. Today however, constructing a
reliable yet cost effective smart home still poses a great challenge for us. The objective of
this project is to investigate the reliability and performance of various ubiquitous
computer systems that are suitable for application at home rather than creating an
expensive super microprocessor that has high computing speed, high memory, strong
communication frequency thus unable to reach its fullest potential in a small home
environment.
Through various experiment and result, we found Zigbee best fulfill most of the criteria
should it be used in a smart environment. This small radio frequency module
demonstrated strong power discipline allowing itself to enter sleep mode enabling
minimum power consumption that greatly contributes to cost saving and Eco friendliness.
It has very sophisticated mesh topology, that safeguard it's network performance even if a
few nodes are to malfunction.
The Zigbee does shows weak penetration strength and a small communicating distance of
less than 7 meters in a laboratory. Nevertheless taking account that it is suppose to be
performing in a home environment where there is not many walls and short distance.
Furthermore if distance is an issue, Zigbee has self discovering capabilities where it could
discover the nearest Zigbee and start relay the data or message in a hopping manner.
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Acknowledgements
I would like to take this opportunity to express my deepest gratitude and appreciation to
some of my friends for giving suggestions and help with the report. A very special thank
to my supervisor DR Carlos Acosta for his dedications, patience, guidance and
supervision he has provided me with from the very beginning to the end.
Last but not least, I would like to thank all my family members and loved ones who have
given their fullest support and understanding during this project.
ii
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Table of Contents
Abstract
i
Acknowledgement
ii

INTRODUCTION
1
1.1 Background
1
1.2 Project Objectives
2
1.2.1 Analysis of performance for ubiquitous computing system
2
1.2.2 Interfacing for simple devices
3
1.2.3 Design of new way of interacting with the system
3
1.3 Overall Objectives
4
1.4 Proposed Approach and Methods to be employed
4
1.5 Skill Review
5
1.5.1 Skills required to achieve targets

5
1.6 Project report organization
6
Literature Review
7
2.1 Overview of project background
7
2.1.1 Physical basic
7
2.1.2 Penetration of obstacles
8
2.1.3 Conditions that affect the RF communication
9
2.1.4 Comparison of existing wireless communication protocols
10
2.1.5 Network topologies
10
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
3
Lim Zongyao W0704223
Zigbee Technology
11
3.1 Hardware component
12
3.1.1 Micro-controller
13
3.1.2 Arduino Xbee shield
14
3.1.3 Xbee(Zigbee) module
15
3.2 Software component
3.2.1 Arduino software
16
3.2.2 X-CTU (XCTU) software
16
3.3 Zigbee network
4
16
17
3.3.1 Coordinator
17
3.3.2 Router
18
3.3.3 End devices
18
3.4 Digimesh network
18
Development, Results and Analysis of Project
19
4.1 System design
20
4.2 Configuring the Zigbee
21
4.3 Testing/Experimenting with the Arduino board and Xbee
23
4.3.1 Reliability Experiment
23
4.3.2 RSSI evaluation Experiment
24
4.3.3 Light sensor integration Experiment
26
4.3.4 Digimesh Experiment
28
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
5
6
Lim Zongyao W0704223
4.3.5 Motor Experiment
30
4.3.6 Sensor-Motor Experiment
32
4.4 Zigbee and DigiMesh Comparison
33
4.5 Discussion (Possible Scenarios)
38
Conclusions and Recommendations
39
5.1 Conclusions
39
5.2 Recommendations
40
References
42
Appendix A. Schematic of Arduino board
44
Appendix B. Program code
46
List of Figures
Figure 1 Picture of a smart home
Figure 2 Picture of home with various smart devices
Figure 3 Project Gantt chart
Figure 4 Graphic electromagnetic spectrum
Figure 5 Diffusion, reflection bending and penetration of obstacles
Figure 6 Comparison for existing wireless protocols
Figure 7 Diagram of different network topologies
Figure 8 Arduino Duemilanove board
Figure 9 Arduino Xbee shield
Figure 10 USB Xbee transmitter
Figure 11 Xbee/Xbee pro Module
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 12 Xbee/Xbee pro module schematic(Top view)
Figure 13 Serpac electronic enclosures
Figure 14 Arduino 0021 platform
Figure 15 Zigbee network nodes
Figure 16 Digimesh network nodes
Figure 17 System design
Figure 18 series1_TX flow diagram
Figure 19 series1_RX flow diagram
Figure 20 sensor flow diagram
Figure 21 Photo of interior structure of Light sensor
Figure 22 Servo motor
Figure 23 Connection of servo motor
Figure 24 Flow diagram for light sensor-motor sending node
Figure 25 Flow diagram for light sensor-motor receiving node
List of Tables
Table 1 Summary of required skills
Table 2 RSSI lab result
Table 3: Table of comparison for program for series1,2 and Digimesh
Table 4: Table of comparison of the physical differences for series1,2 and Digimesh
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
1. Introduction
1.1 Background
In modern society, people are demanding for more convenient and comfortable lives
especially at home; in the environment they play, live or work in. Since we are spending
more time at home than the office, there is more reason for us to build a low cost,
intelligent environment to better suit individual needs.
Imagine you have just returned home from a hard day's work, your garage opens
automatically when it senses your vehicle, your home's air-conditional system operates
immediately upon knowing you have safely parked your vehicle. Your LED TV turns
on, the curtain is drawn, the moment you enter the house. It seems like the different
devices can interact with one another thus eliminating the need for remote control or
other hand-held operating devices. Figure 1 and Figure 2 display a smart home
environment and several smart devices around the home.
Figure1:Picture of a smart home [10]
Page 1 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 2: Picture of home with various smart devices[9]
1.2 Project Objective
Before we can come to the fanciful features of a smart environment, we must first
understand and study the behavior behind the devices interaction. The project has three
major objectives described below.
1.2.1 Analysis of performance for ubiquitous computing system
The word "ubiquitous" can be defined as "existing or being everywhere at the same
time,""constantly encountered," and "widespread." When applying this concept to
technology, the term ubiquitous implies that technology is everywhere and we use it all
the time[12]. Ubiquitous technology is often wireless, mobile, and networked, making its
users more connected to the environment around them and the people in it.
There are currently a wide range of wireless technologies available in the market.
Therefore it is important for us to study their properties in terms of their frequency range,
Page 2 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
technology, performance, range, power consumption etc. The transmission of the data can be
achieved using Infrared (IR) and radio frequency (RF). IR requires line of sight (LOS) path
between the transmitter and receiver and hence is not used frequently. Instead, RF is
used in wireless sensor network as it implements a wireless link in which the waves can
penetrate a limited number of walls. It is foremost important also to conduct analysis on
the room to room penetration performance of these RF devices.
RF Wireless connectivity for smart devices application includes Zigbee, Wimax , Wi-fi,
Bluetooth etc.
1.2.2 Interfacing for simple devices
A major challenge in ubiquitous computing is physical integration and embedding of
computing and communication technology into environments and artefacts[8].
Embedding technology into everyday artefacts also inevitably implies embedding the
“computer” into tasks done by the user. This leads to new research challenges and
further questions:
1
What is the consequence of artefacts and environments becoming an integral part
of the “computer”?
2
How is it possible to interact with a system where many artefacts and the
environment is a part of the “human computer interface”?
3
Where is the application and how do we influence and interact with an
application where the “computer” and of “human computer interface” is a part of many
applications?
1.2.3 Design of new way of interacting with the system
The devices in a network need to know when to communicate with one another.
There are two types of communication modes: non-beacon mode and beacon mode[13].
Beacon mode is a fully coordinated mode in that all the devices know when to
coordinate with one another. In this mode, the network coordinator will periodically
"wake-up" and send out a beacon to the devices within its network. This beacon
Page 3 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
subsequently wakes up each device, which must determine if it has any message to
receive. If not, the device returns to sleep, as will the network coordinator, once its job
is complete. Non-beacon mode, on the other hand, is less coordinated, as any device can
communicate with the coordinator at will. However, this operation can cause different
devices within the network to interfere with one another, and the coordinator must
always be awake to listen for signals, thus requiring more power. In any case, we need
to obtain overall low power consumption because the majority of network devices at
home are able to remain inactive over long periods of time.
When communication data are being transmitted from devices node to node, there maybe
occurrence of faulty/sleeping node and therefore node link consideration is important.
Alternate route designs must be included, so that the whole network will not fail when
one or two node malfunction. Basically this entails the selection of suitable
topologies(for example star, mesh, or cluster tree).
1.3
Overall objective
With increasing technology and continuous demand for comfortable lives, the dream of a
hi-tech, all round automatic environment is not distant. Today however constructing a
reliable yet cost effective smart home still poses a great challenge for us. The objective
of this project is to investigate the reliability and performance of various ubiquitous
computer systems that are suitable for application at home rather than creating an
expensive super microprocessor that has high computing speed, high memory, strong
communication frequency thus unable to reach its fullest potential in a small
environment. Finding how well devices interact with one another is also critical; for
example, the types of networking.
Power discipline is another project objective where minimum power consumption
greatly contributes to cost saving and Eco friendliness.
1.4 Proposed approach and methods
The project will be divided into a few parts:
Page 4 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
 The foremost important step is research and understanding the basics of Wireless
technology, and finding more information on available wireless devices currently
in the market.
 Next step will involve a design of communication among the devices using a
wireless technology.
 Followed by conducting experiments on various devices to obtain relevant
results(result parameters include distance, signal strength, power consumption,
object penetration, reliable network topology etc)
 Finally do analysis on those data( To find the most reliable, cost effective,
longest battery life device that suits the implementation of a smart home)
The Gantt chart below is used to assess the progress of the project. It is created using
open office, it provides an overview of the project plan and schedule. Each project phase
is marked by completion of one or more deliverables. It is therefore important to ensure
that the targets or objectives are met in each phase for project completion.
March
April
May
June
Month August September October November December January February
serial
activity
no.
Week 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
1 Meet up supervisor for discussion
2 Research of project background
3 Project proposal
Arduino and Xbee technology
4 study
Familiarise and conduct
5 Experiment on Xbee
Perform lab experiment and obtain
6 lab result
Testing with difference types of
communication protocol (Namely
7 Series 1, 2 and Digimesh)
Compare and choose the best
8 communication protocol
9 Interface with sensor and motor
10 Fine tuning program
Brainstorm for smart environment
applicable with sensor-motor
11 relationship
12 Tabulate and conclude on result
13 Project refinement
14 Review by supervisor
15 Prepare final report
16 Prepare presentation
Figure 3: Project Gantt chart
Page 5 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
1.5 Skills review
1.5.1 Skills required to achieve targets
Skills Required
Sources and Methods
Foremost adequate research is needed
to study the background of existing
-
“smart” home systems
-
Acquired basic software skill and
source code programing of
“Arduino”
-
Assessing and evaluating project
progress
-
Presentation
Computer literacy
-
Case studies and Published journal
Reference books from UniSIM Library
and National Library
Research on the Internet
Product Manuals from Arduino
website[14].
Sample example code from the internet.
Xbee product datasheet for configuration.
Project Management
Execute target base on Gantt chart
Effective report writing skills and
communication
- Oral presentation skills
- Report writing skills
- Arduino 0021
- Microsoft PowerPoint
- Microsoft Words
- Microsoft Excel
- OpenOffice
Table 1: Summary of required Skills
1.6 Project report organization
Section 1 of the report basically introduced the ideas and concepts of this project and
categorized the difference objective to be achieved in this project. Discovery the required
critical knowledge and skill for project implementation. It is the stage for careful
planning and how to go about executing these deliverables.
Section 2 is included with all the research and knowledge of the project background. It
tells us various technologies currently in the market and their limitation. Brief
Page 6 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
description of radio frequency capabilities and their limitation. The awareness of
different kind of network topologies.
Section 3 presents the essence of this project, the Zigbee technology. It shows all the
important hardware and software components for carrying out these project, and teaches
us how to use them. It also enable us to choose from the range of network topologies
adopted by zigbee.
Section 4 contained all the experiment procedure and their result. It also explain the
program code usage and effect on the hardware through simple flow diagram.
Comparisons have been made between the network topologies and program based on the
lab result obtained. Finally a lot of ideas on the Zigbee implementation are brainstorm
and tabulated in this section.
Section 5 concludes the whole project and a few recommendation for improvement.
2. Literature Review
2.1 Overview of project background
2.1.1 Physical Basic
Radio waves are, as light, part of the electromagnetic spectrum which describes different
types of electromagnetic waves(see Figure 3). The only difference from light is the
wavelength and the frequency with which the waves oscillate. For the single wavelength
or frequency areas, different descriptions have been made, e.g. UHF or microwave,
infrared, ultraviolet etc[4].
Page 7 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 4: Graphic electromagnetic spectrum[4]
2.1.2 Penetration of obstacles
Now, as radio waves are basically the same as light, the propagation of radio waves is
the same: linear. But due to the different wavelength, some effects have a different
intensity. Light could penetrate glass or any other transparent material very well but it is
totally blocked by a brick wall. It can partly penetrate thin paper, depending on the
power of the light source. It is able to bend very slightly around the edges of obstacles,
which is seen as a half shadow. Light is totally reflected on some surfaces, like polished
metal or mirrors, and only partly reflected by other materials.
Radio waves limits are not the same. The lower frequency or longer wavelength allows
radio waves to penetrate material easier, so a brick wall is not necessarily an absolute
obstacle; however, similar to light penetrating the paper, the intensity of the radio waves
are damped. Also sound waves can be bent more easily around obstacles. The rule is, the
lower the frequency, the easier the wave penetrates obstacles. Independent of the
wavelength, a radio wave is always reflected by a metal surface.
Page 8 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 5: Diffusion, reflection bending and penetration of obstacles[4]
2.1.3 Conditions that affect the RF communication
As described, radio waves are part of the electromagnetic spectrum and share the same
medium, the open space. Whatever happens in this space is uncontrollable; hence, usage
of mobile radios, cell phones or WLAN laptops would cause interference.
Sources of interference[5]:
 Microwave ovens-can generate RF strong enough to overcome your wireless
LAN[6].
 Electrical devices-cell phone, laptop etc, produce electromagnetic wave
interference.
 Passive systems-Indoor metallic furniture that reflect RF
 Dense building material-like cinder block, rock fireplace wall etc, will
significantly lower your wireless signal strength down.
Page 9 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
2.1.4 Comparison of existing wireless communication protocols
A comparison has been made between the existing wireless standards such as Bluetooth,
Wi-Fi, HyperLan and Zigbee. These wireless communication protocols were seen with
respect to the sensor network .The table below lists the different protocols on the basis of
the data rate, power dissipation, range of communication and cost etc.
Figure 6: Comparison for existing wireless protocols[1].
2.1.5 Network topologies
Since wireless networks usually contain more than two nodes, the organization of the
network is of interest.
The network architectures are categorized as follows [3]:

bus

ring

star
Page 10 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE

tree

mesh
Lim Zongyao W0704223
Figure 7: Diagram of different network topologies[7]
3. Zigbee Technology
ZigBee is an open global standard built on the IEEE 802.15.4 MAC/PHY. ZigBee
defines a network layer above the 802.15.4 layers to support advanced mesh routing
capabilities. The ZigBee specification is developed by a growing consortium of
companies that make up the ZigBee Alliance. The Alliance is made up of over 300
members, including semiconductor, module, stack, and software developers[16].
Zigbee operates with low-cost, low-power digital radios in a small wireless personal area
network. It is intended to be user friendly, thus making implementation and integrating
easier in any home electronics equipment for benefit of simple user- machine interaction.
Page 11 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
3.1 Hardware Component
3.1.1 Micro-controller
Arduino board(Arduino Duemilanove ATmega328): A single board micro-controller that
could be used for configuration of the zigbee/xbee The microcontroller on the board can
be programmed using the Arduino programming language and the Arduino development
environment. The Arduino Duemilanove has the option of being powered via the USB
connection or with any external power supply. The power source is selected
automatically upon hardware interfacing. The Atmega328 has 32 KB of flash memory
for storing code (of which 2 KB is used for the bootloader), 2 KB of SRAM and 1 KB of
EEPROM. Each of the 14 digital pins on the Duemilanove can act as an input or output,
using pinMode(), Digiwrite(), and digitalRead() functions. They operate at 5 volts. Each
pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor
(disconnected by default) of 20-50 kOhms[14]. Pin 13 on the board is for LED. Blinking
of the LED when powering up is a form of testing whether the board is working or
otherwise.
Page 12 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 8: Arduino Duemilanove board
3.1.2 Arduino Xbee Shield
The Arduino Xbee Shield is an expansion board developed for the Arduino Duemilanove
board. It allows an Arduino board to communicate wirelessly with the presence of
Zigbee. There are basically two jumpers on board to interchange between USB and
Wireless communication. It is based on the Xee module from MaxStream. The module
can communicate up to 100 feet indoors or 300 feet outdoors (with line-of-sight). It can
be used as a serial/usb replacement or just put it into a command mode and configure it
for a variety of broadcast and mesh networking options. The shields breaks out each of
the Xbee's pins to a through-hole solder pad. It also provides female pin headers for use
of digital pins 2 to 7 and the analog inputs, which are covered by the shield (digital pins
8 to 13 are not obstructed by the shield, so it can use the headers on the board itself)[14].
Page 13 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 9: Arduino Xbee shield
Figure 10: USB Xbee transmitter
Page 14 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
The USB Zigbee transmitter USB port adapter is solely for Xbee/Zigbee usage. There is
a total of 20 inputs of which only 17 are in use on the transmitter board for the Xbee.
One major IC compound embedded on the transmitter is the FT232R which is the USB
to serial UART interface. This simple adaptor could help us interact with the
Xbee/Zigbee via series port connections.
3.1.3 Xbee(Zigbee) module
The Xbee module is a tiny wireless Modem using RF communication to communicate
among one another, and is thus applicable in a smart environment. It has low data rate,
maintains long battery life, and can be configured to operate in a secure network. The RF
module is always in idle mode when not receiving or transmitting any data. The Module
may transverse into four mode of operations; transmit mode, received mode, sleep mode
and command mode.
Figure 11: Xbee/Xbee pro Module
Figure 12: Xbee/Xbee pro module schematic(Top view)
Page 15 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
3.1.4 Electronics enclosure
The final/end product needs to sit perfectly in an enclosure to protect, insulate and at the
same time beautify the model instead of exposing those unsightly loose wiring.
Therefore under my supervisor's recommendation the below serpac electronics
enclosures[17] S-series, model number 231-I has been sourced which best suits the
Arduino board, expansion board and Xbee.
Figure 13: Serpac electronic enclosures
3.2 Software component
3.2.1 Arduino software
The Arduino software is to be downloaded and installed in order to get started. It consists
of an Arduino development environment containing a text editor for writing code, a
message area, a text console, a toolbar with buttons for common functions, and a series
of menus. It can run on various operating systems such as Windows, Mac OS X, and
Linux. The environment is written in Java and based on Processing, avr-gcc, and other
Page 16 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
open source software. It can also be connected to the Arduino hardware or serial port to
upload programs and also communicate with hardware devices[14].
Figure 14: Arduino 0021 platform
Verify button: Debugging of structured program
New button: Starting a new sketch
Stop button: Stop debugging
Open button: Open file from arduino folder
Save button: Saving of current program to the sketch folder
Upload button: Upload current program to the micro-controller
When uploading the program, we must select the correct model arduino board and serial
port which it is connected. Both selection could be found under the tools option.
Page 17 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
3.2.2 X-CTU (XCTU) software
It is used for configuring and testing MaxStream radio modems. The software allows
MaxStream customers to test the radio modems in the actual environment with just a
computer and the items included with the radio modems. It is by-far the most critical
software for flushing the Xbee into ZNET 2.5 Router/End Device AT also known as the
Digimesh.
3.3 Zigbee Networks
Zigbee networks are called personal area networks or PANs[16]. Each of these network
has a unique PAN identifier (PAN ID). Zigbee adopts 16 and 24 bit PAN ID.
Coordinator, Router and End devices need to be in play in order for the network to
operates properly.
Figure 15: Zigbee network nodes
C= Corrdinator
R= Router
E= End devices
Page 18 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Zigbee protocol includes:
3.3.1 Coordinator
It:
 Selects a channel and PAN ID(64-bit and 16-bit) to start a network.
 Aware of all nodes in the network.
 Regulates the routers and end devices joining the network.
 Assists in data or information routing
 Needs to be powered at all times, cannot employ any kind of sleep mode
3.3.2 Router
It:

Relays or routes data to other devices in the network

Needs to be powered at all times, cannot employ any kind of sleep mode
3.3.3 End devices
They:

Only transmit and receive RF data through its parent.

No data routing ability

Can go into sleeping mode for power conservation
3.4 Digimesh Network
Page 19 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 16: Digimesh network nodes
Digi has developed an alternate mesh protocol named DigiMesh. Only one node type is
presented in this network. There are no parent-child relationships. All nodes in the
network system can route data and are interchangeable. The network has the ability to
create or discover alternate route when one or more node fails. All nodes in the network
can be configured as low-power/battery-powered devices. Unlike Zigbee network,
Digimesh network setup is much simpler as no coordinator or routers are needed. Thus
the whole network system is more reliable without having to worry for the coordinator or
router during failure. Data can hope from node to node to cover greater distance.
Digimesh allows nodes to sleep, reducing power consumption, which is helpful for nodes
that are powered by battery, thereby increasing battery life. Sleeping of nodes is allowed
by time synchronization and digimesh enable time synchronization through a nomination
and election process, enabling the network to operate autonomously.
4. Development, Results and Analysis of project
4.1 System design
Page 20 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
In order to have a rough idea of how we are going about achieving the objectives as per
declared in section 1.
Figure 17: System design
The proposed system will have a network of 2 to 3 nodes, the nodes will be connected in
a mesh network. The following experiments will help us to decide which type of mesh
network is more suitable for our system. The 2 nodes will be sensors and the other node
will be an actuator. The communication between sensors and actuator will help to
illustrate the potential of these type of wireless networks for application on smart houses.
Each smart node consist of this an arduino board, arduino Xbee board, and a Xbee
module. They could all be powered by a battery of 5 volts or less thus demonstrating the
power objective in section 1.
4.2 Configuring the Xbee
Page 21 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
First of all we need to install any kind of serial port communication platform(eg
minicom) on the computer in order to communicate with the Xbee modules.
Certain command inputs for configuration must be written to the Xbees in order for the
Xbees to communicate in the same channel, addresses, baud rate etc. The Xbees can
even be switched to different modes such as sleep mode, to allow the RF module to enter
states of low-power consumption when not in use.
Important Configuration Command:
1) +++: To enter in configuration mode.
2) ATRE: Restore default factory setting.
3) ATID: The network ID of the Xbee module.
4) ATCH: The channel of the Xbee module.
5) ATMY; The 16-bit address of the module.
6) ATDH and ATDL: The destination address for wireless communication (DH is
the high 32 bits, DL the low 32).
7) ATBD: The baud rate used for serial communication with the Arduino board or
computer.
8) ATWR: Write newly configured parameter values to non-volatile (long-term)
storage. Otherwise, they will only last until the module loses power.
9) ATCN: Close configuration mode.
4.3 Testing/Experimenting with the Arduino board and Xbee.
All equipments and facilities for carrying out the experiment are provided by singapore
polytechnic. The below experiments conducted are to illustrate the performance of
Zigbee in an enclosed environment. Evaluate the signal strength, penetration strength
Page 22 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
and the reliability in a network. Simply integration of components such as sensor and
motor to show that Arduino is compatible with these devices. Through these
experiments, we are not only able to achieve our objectives but also to explore other
capabilities of Zigbee technology.
4.3.1 Reliability Experiment
The project kicked off with testing on the reliability and workability of both the Arduino
board and Xbee as the products had just been bought. Other objectives of this experiment
include communicating in transparent mode, exploring the uni-cast and broad-cast
capabilities of Xbee.
Knowing that they can be configured to communicate in two types of communication
operations:
Transparent operation:

By default all Xbee/ Xbee pro is in this operation

In this operation, data must queued up for RF transmission

In a point to multipoint system, there is a need to send extra information
for the receiving module to distinguish between the data coming from
various nodes.

Must keep on transiting into command mode for setting of the module
parameters.
API operation also known as Application programming interface operation:
 In this operation, host or user can configure or interact with any module's
network capability as and when they deem fit.
 Datas/messages are contained in UART data frames that define operations
and events for the particular module.
 Sophisticated routing capability is presented in API mode.
Page 23 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
 Able to identify the source address of each individual packet.
In this experiment, a pair of RF modules, two computers, an arduino board, an arduino
expansion board, a USB Xbee transmitter were used for testing. By using the Arduino
Board for configuring the Xbees, we needed to remove the micro-controller from the
board. The pair of Xbee was configured based on the above mentioned simple command
to operate in the same baud rate, PAN ID and alternating DL and MY:
1st Xbee
Configured with command “ ATID3332, DH0, DL0, MY1, BD7, WR, CN”
2nd Xbee
Configured with command “ ATID3332, DH1, DL1, MY0, BD7, WR, CN”
After the set-up, the experiment was a success as the RF modules were able to transmit
simple keyboard lettering to one another. Following the experiment we also tested on the
broad-cast and unicast using 3 Xbees this time round. In order for Broadcast
transmission, the DL of one of the RF modules needs to be set to “FFFF”. For uni-cast,
the DL needs to be set to the receiving module's address. The experiment once again
proved that it is possible for unicast and broadcast transmitting on Xbee.
4.3.2 RSSI evaluation Experiment
In this experiment, we took measurements of “RSSI” for the Xbee. In
telecommunications RSSI stands for received signal strength indicator;it is a
measurement of the power present in a receiving radio signal. This experiment is
relevant to our objectives stated in section 1 that is to find out the penetration and signal
strength based on obstacle and distance.
We made use of the example program “series1_TX” and “series1_RX”.The command “
rssi=data.getRSSI();” was added in the program “series1_RX” to further indicate a RSSI
reading figure when data was successfully received by the receiving module.
With a pair of Xbee, Arduino board and expansion board, the experiment started with
the Xbees configured as a coordinator and end device respectively. The coordinator was
Page 24 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
uploaded with the program “series1_TX” while the end device was uploaded with the
program “series1_RX”.
Figure18: series1_TX flow diagram
Page 25 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 19: series1_RX flow diagram
RSSI values have been obtained in different parts of the robot laboratory. Following is a
summary table of what was obtained during the lab experiment.
Distance
Obstacles(wall)
RSSI
Remark
2-3cm
none
45-50
To get an estimate on
RSSI at the stronger
signal value at line-ofsight and extremely
close distance
5 meters
1 thin walls
80
Noted as distance gap
get bigger and with the
presence of obstacle,
the RSSI value get
bigger
Page 26 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
2.5 meters
2 thin walls
94
Noted obstacles does
affect the RSSI
significantly
7 meters
2 thin wall
94
Hard time getting any
signal, error LED keep
blinking
10 meters
3 thin walls
none
Error reading, thus
packet is lost.
Table 2: RSSI lab result
The experiment concluded that beyond 10 meters and with 3 walls, this mini RF system
will not work. Therefore it is important for us to consider these factors when designing a
smart environment. Further research was done on the RSSI values collected from the
experiment and it seemed that the figure got larger as the signal weakered. From the
forum[18] it is understood that the RSSI reading from the Xbee is in fact a measurement
of interference rather than strength, hence the smaller the value the better the signal
strength.
4.3.3 Light sensor integration Experiment
In this experiment we integrated a light sensor on the Arduino board and at the same
time programmed the circuitry to a perform simple task upon getting a certain value from
the light sensor. At this stage of the project, we need to perform check and testing with
physical component to see how arduino fare with external devices. A light sensor, an
Arduino board, an expansion board, and a PC are only needed for this experiment. The
program “sensor” was written to operate and communicate in baud rate 115200bps, it
will print the value of the light intensity amd at the same time turn on the status LED, if
the reading from the light sensor is more than 900; else it turns off the LED. Finally
delay 500millisecond and start the whole process again.
Page 27 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 20: sensor flow diagram
Page 28 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 21: Photo of interior structure of Light sensor
Photo above shows the end product of the integration of light sensor on an arduino
board, expansion board and Xbee embedded in an electronics enclosure.
4.3.4 Digimesh Experiment
This experiment is to test the extent of the mesh network topology developed by digi.
Therefore through the different comparison, we are able to choose the best topology that
best suit home application at the same time fulfill our objective as per declared in section
1.
This experiment required the use of the X-CTU software to flash the Xbees with
Digimesh. The X-CTU was also used to check for individual addresses of the Xbees,
which is required for programming purposes.
Steps: 1) Xbees flushed with Digimesh
2) Xbee is labelled node 1 and 5 for easy identification
Page 29 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Node 1
Node 5
Address: (13A200)SH
Address: (13A200)SH
(403B868A)SL
Uploaded with program “send_dm_n1”
(403B86B8)SL
Uploaded with program “received_dm_n1”
3) Noted that Digimesh uses a Mac type 64 addressing. Therefore a specific
address needs to be indicated in the program when communicating in
unicast mode.
4) When both node were successfully communicating between one another
as per indicated by the blinking LED, we separated both nodes to a range
beyond their communication capability.
5) A node 7 that was also flushed with Digimesh was introduced in between
node 1 and 5. As anticipated, node 1 and 5 started to communicate. Thus
node 7 did help to relay the message without the need for further
instruction from the user. This experiment exhibits the wonder of
Digimesh network, which caters best for creating a smart environment.
The following command line was needed in the program for setting the parameter for
sending:
// Set params to send //
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee)); // defined size of packet and
create memory of variable //
paq_sent->mode=BROADCAST; //mode of transmission could be in unicast or
broadcast //
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
Page 30 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
xbeeDM.hops=0;
xbeeDM.setOriginParams(paq_sent, "0013A200403B868A", MAC_TYPE); //
Digimesh uses MAC_TYPE which is 64 addressing//
// Command for sending packet//
xbeeDM.setDestinationParams(paq_sent, "0013A200403B86B8", data1, MAC_TYPE,
DATA_ABSOLUTE); //The address must match receiving 64bit address, “data1” is the
actual data/information to be send//
xbeeDM.sendXBee(paq_sent);// command line for sending the packet
The following three command lines must be included in any receiving node's program:
free(xbeeDM.packet_finished[xbeeDM.pos-1]);
xbeeDM.packet_finished[xbeeDM.pos-1]=NULL;
xbeeDM.pos--;
The packet must be treated or discarded once read/processed because of the small
amount of memory of the Arduino.
The above experiment proves the following:

The Digimesh has self-healing capability meaning any node/device entering or
leaving the system does not cause the network to fail as a whole.

Self discovery of node is presented.

There is no need to configure or any indication of parent-child relation anywhere
between the nodes. Thus the system is more flexible as each individual node is
interchangeable, meaning they can be either the parent or child.

Instead of creating a network/routing map, routes are created only when needed.
4.3.5 Motor Experiment
In this experiment, we are going to integrate motor on the arduino board. Motor runs in
many of the household appliances. Therefore It is essential to know if motor is
Page 31 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
compatible and controllable by arduino. Through the success of this experiment we will
be able to conclude that controlling most of the appliances won't be any problem.
This experiment involved programing the robot servo motor to rotate clockwise,
anticlockwise direction. The program “servo_motor” (please refer to Appendices) was
uploaded to the arduino board with the 3 pin of the servo motor connected to the 5v
power source, ground and pin 9 on the arduino board. Pin 9 was selected due to the
program written, it could be any other input pin on the arduino board.
Figure 22: Servo motor[19]
Page 32 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 23: Connection of servo motor[20]
The program is able to perform clockwise and anticlockwise rotation; however, the
major problem encountered was the motor being unable to stop once it started. Thus after
searching the forums for help, we finally came to understand that in order to stop the
motor, the additional code is inserted:
myservo.write(93);
The use of the above mentioned code line is to control the speed of the motor.
The value in the bracket:
- (0) full speed in a direction
-(180) full speed in the other direction
-(90-95) no movement, subjected to self tuning
requirement based on difference type of servo motor.
4.3.6 Sensor-Motor Experiment
In the last experiment, we incorporated a light sensor and a motor to communicate in
Digimesh. Light sensor was plugged onto node 1 and program “
lightsensor_wif_motor_senddm_n1” was uploaded into node 1's micro-controller to send
the data if light sensor detected something. When light sensor was activated, the data
“H” was sent to the receiving module.
Page 33 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 24: Flow diagram for light sensor-motor sending node
The receiving end, node 5 was plugged with a motor and program
“light_sensor_wif_motor_receive_dm_n5” was uploaded into node 5's micro-controller.
When received data1(H), the program tells the end device to start the motor by turning
clockwise direction to 90 degree followed by counter clockwise direction 90 degree.
Stop the motor after the sequence has been performed.
Page 34 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Figure 25: Flow diagram for light sensor-motor receiving node
4.4 Zigbee and DigiMesh Comparison
Xbee programs
Library
Series 1
#include <XBee.h>
Series 2
#include <XBee.h>
Digimesh
#include "WaspXBeeDM.h"
Setup Xbee
Series 1
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
xbee.begin(9600);
Page 35 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
}
Series 2
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
pinMode(dataLed, OUTPUT);
// start serial
xbee.begin(9600);
flashLed(statusLed, 3, 50);
}
Digimesh
void setup()
{
// Inits the XBee DigiMesh library
xbeeDM.init(NORMAL);
// Powers XBee
xbeeDM.ON(9600);
pinMode(13, OUTPUT);
}
Creating object
Series 1
XBee xbee = XBee();
unsigned long start = millis();
uint8_t payload[] = { 0, 0 };
Tx16Request tx = Tx16Request(0x1874, payload, sizeof(payload));
TxStatusResponse txStatus = TxStatusResponse();
Page 36 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
int pin5 = 0;
int statusLed = 11;
int errorLed = 12;
Series 2
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
int statusLed = 13;
int errorLed = 13;
int dataLed = 13;
Digimesh
packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char* data="Test message!";
Check for a message
Series 1
// creating a loop to continuously check for message
void loop() {
xbee.readPacket();
Series 2
// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
xbee.readPacket();
Digimesh
// no read packet is required
Page 37 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
void loop()
{
Check for availability
Series 1
if (xbee.getResponse().getApiId() == RX_16_RESPONSE ||
xbee.getResponse().getApiId() == RX_64_RESPONSE) {
// got a rx packet
if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
xbee.getResponse().getRx16Response(rx16);
option = rx16.getOption();
data = rx16.getData(0);
} else {
xbee.getResponse().getRx64Response(rx64);
option = rx64.getOption();
data = rx64.getData(0);
}
Series 2
if (xbee.getResponse().isAvailable()) {
// got something
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet
// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);
if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
// the sender got an ACK
Page 38 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
flashLed(statusLed, 10, 10);
}
Digimesh
if( xbeeDM.available() )
{
digitalWrite(13,HIGH);
xbeeDM.treatData();
Table 3: Table of comparison for program for series1,2 and digimesh
Series 1
Topology
Series 2
Point to point and star Point to point, star
topology
and mesh Network
Node types, benefits Simplest of the 3.
Coordinators(C),
Only peer-to-peer, routers(R), end
gives user maximum devices(E). End
control over the
devices potentially
network node.
less expensive
because of reduced
functionality.
Forwarding
Node to node
Digimesh
Digimesh
One type, all node is
flushed with digimesh,
homogenous. More
flexibility to expand
the network.
Simplifies network
setup.
Needs a coordinator Using AODV (Ad-hoc
and routers to allow On-demand Distance
Page 39 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
techniques
Lim Zongyao W0704223
joining the network Vector). An
and routing the data. associative routing
table is used to map a
destination node
address with its next
hop.
Sleeping Routers,
Battery Life
All nodes can sleep
Only end devices can All nodes can sleep.
sleep.
No single point of
failure associated with
relying on gateway or
coordinator to
maintain time
synchronization.
Addressing
Two layers. MAC
address (64bit) and
network address
(16bit).
Two layers. MAC
address (64bit) and
network address
(16bit).
MAC address (64 bit)
only.
RF data rate
250kbps
250kbps
250kbps
Power down current 10uA
1uA
<10uA
Supply voltage
2.8-3.6 V
2.8-3.4 V
2.8-3.4 V
Table 4: Table of comparison of the physical differences for series1,2 and Digimesh
Lastly we have brainstormed on the usage or integration of this sensor-motor relationship
to be implemented at home. It is more important to come up with creative and impressive
ideas of implementing this simple yet reliable technology. Below are some of the
brainstormed ideas.
4.5 Discussion (Possible Scenarios)
Scenario 1
Light sensors should be installed outside the window to check on the light intensity. If
majority of the sensor detected darkness, then it means currently it is in the night so
curtains should be withdrawn. If the sensor detected an average amount of light, they
Page 40 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
will instruct the curtain to be drawn. Motor is integrated in the curtain to draw or
withdraw the curtain based on its turning motion nature.
Scenario 2
Motion sensor installed in different parts of the house. When radio/hifi is on with remote
control, the volume of the radio is controlled by the various sensors that determine which
part of the house the owner currently is in. The volume tuning is based upon the distance
of the sensor, thus the hifi/radio is tuned to the loudest when the owner is at the furthest.
Scenario 3
Have sensors in every room located near the door to detect if owner is entering or
leaving the room, thus effectively deciding whether to switch off or on the light. This
idea is the most simple implementing logic to save electricity and prolong the bulb
lifespan.
Scenario 4
Have sensors around the room to detect any presence of user, if yes switch on the air
conditional system, if no switch off the air conditional system, and based on a timer to
set the temperature at different times of a day. For example at night, surrounding
temperature may be lower, and our body tends to lose more heat. Hence at this time
higher room temperature should be maintained.
Scenario 5
Since we will need to devote some of our time a day in the toilet, smart toilet
environment is also crucial. Sensor needs to be installed for the tap, to create full
automation and at same time cut down on water consumption. Toilet bowl will need to
be installed with sensor also to detect any present of user. Upon detection of user, the
toilet bowl start by warming the seat, flushes the towel bowl during and after use.
Chapter 5 Conclusions and Recommendations
5.1 Conclusions
Page 41 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Coming to the end of this capstone project, the various results for the lab
testing/experimenting suggest that Zigbee/Xbee is significantly one of the most reliable
technologies in the market in terms of cost, wall penetration capability, distance, power
discipline, failure proof network topology, complexity, should it be used in a smart home
environment. We are unable to obtain any other mote of another technology for
comparison between the wireless technology due to the high cost needed. Thus
effectively demonstrated that Zigbee/xbee is much more cost effective. Since now that
we are familiarized with this simple technology, more ideas and improvement in
implementing this technology at home could be made to the Xbee module.
The main objective of investigation and studying the reliability of wireless technology
suitable for a smart home environment has undoubtedly been met. We have conducted
tests/experiments on some of the communication topologies and satisfactory results show
that our choice of Digimesh network is the easiest, most efficient, most reliable should it
be used in a smart home environment. We have come up with a lot of ideas for
implementation, but more time and resources are needed for complementing and
improvising these ideas.
5.2 Recommendations
For this project, the whole idea is to find a cheap yet reliable technology for creating a
smart home environment. We have came to know of Zigbee which is currently in the
market. This technology is still not very popular, and due to the limitation of sample or
skeleton program structures available in the internet, there is still a need for discovering
it's actual or full potential.
The actual implementation of the above mentioned fancy ideas for implementing the
Zigbee may not be as smooth as predicted. We don't really know to what extent can any
home appliances be physically integrated. We don't know the lifespan of the Zigbee. Is
the Zigbee weather resistant? Will the different appliances cause interference for the
zigbee to be operating properly? For example we do know that this technology may not
be integrated in microwave oven. As we know that microwave emit quite an extensive
amount of electromagnetic wave that cause radio interference.
Page 42 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
From the lab result, we know Zigbee has very low penetration strength and short
communicating distance of less than 7 meter in the laboratory. If in a big house distance
may pose an great issue, we will have to tap into Zigbee's data hopping capability to
ensure message is successfully send to the receiving party. Hence carefully planning and
measurement for the placement of the Zigbee module is crucial in the beginning.
Overall this project has increased my knowledge of wireless technology, as well as its
code. This will prove to be extremely helpful in my future engineering career as it
increases my knowledge in network topology. I have learnt how to do time management
and am now stronger in my troubleshooting ability. I would still continue to study and
discover on this interesting technology even when I graduate to further improve and
upgrade myself.
Page 43 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
6. References
References
1. Implementation of Wireless Sensor Mote
http://home.iitk.ac.in/~ynsingh/mtech/manish2006.pdf (August 2010)
2.Wireless connectivity for a world of smart devices
http://www.wi-tivity.com/2006/ap/content/overview.asp?tabvar=e (August 2010)
3. Wireless/Networking
http://compnetworking.about.com/od/networkdesign/a/topologies.htm (August 2010)
4. Wireless technology guide
http://www.pepperl-fuchs.sg/cps/rde/xchg/singapore/hs.xsl/10701.htm?rdeCOQ=SIDB74FD5BD-FEC86D91 (August 2010)
5. RF Interference study
http://wireless.ictp.it/school_2002/lectures/ermanno/HTML/interference.pdf (August 2010)
6. Wireless driver
http://www.wireless-driver.com/knowledge/faq/What-will-affect-a-wireless-network-signalaround-an-average-home.htm (August 2010)
7. Network topologies
http://en.wikipedia.org/wiki/File:NetworkTopologies.png (August 2010)
8. Ubiquitous computing
http://www.comp.lancs.ac.uk/~albrecht/phd/Albrecht_Schmidt_PhD-Thesis_UbiquitousComputing_print1.pdf (August 2010)
9. Electricpig
http://www.electricpig.co.uk/2008/11/27/nokia-home-control-center-to-take-charge-of-your-gaff
(August 2010)
10. Smart home
Page 44 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
http://www.stereoepiloges.com/smarthome.asp (August 2010)
11. James P. Clements and Jack Gido “Effective project management” 2006, thomson
soth-western
12.What Is Ubiquitous Computing?
http://www.rcet.org/ubicomp/what.htm (August 2010)
13. How Zigbee works
http://homepage.uab.edu/cdiamond/How%20Zigbee%20Works.htm (september 2010)
14. Arduino webpage
http://arduino.cc/en/ (April 2011)
15. Arduino duemilanove schematic
http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf (April 2011)
16. Zigbee Network
http://ftp1.digi.com/support/documentation/90000976_F.pdf (April 2011)
17. Electronics enclosures
http://www.serpac.com/ (April 2011)
18. RSSI measurement forum
http://bytes.com/topic/mobile-development/answers/854516-zigbee-xbee-signal-strengthmeasurement-rssi (April 2011)
19. Servo motor
http://www.active-robots.com/products/motorsandwheels/hitec-servomotors.shtml (April 2011)
20. Circuit connection for servo motor
http://arduino.cc/en/Tutorial/Sweep (April 2011)
Page 45 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Appendix A
Schematic of Arduino board[15]
Page 46 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Page 47 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Appendix B
Page 48 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Program Code:
“Servo_motor”
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0;
// variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{
// in steps of 1 degree
myservo.write(pos);
delay(50);
// tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1)
// goes from 180 degrees to 180 degrees
{
myservo.write(pos);
delay(50);
// tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
}
}
“series1_Rx”
Page 49 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
/**
* Copyright (c) 2009 Andrew Rapp. All rights reserved.
*
* This file is part of XBee-Arduino.
*
* XBee-Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XBee-Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>.
*/
#include <XBee.h>
/*
This example is for Series 1 XBee (802.15.4)
Receives either a RX16 or RX64 packet and sets a PWM value based on packet data.
Error led is flashed if an unexpected packet is received
*/
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
Rx16Response rx16 = Rx16Response();
Page 50 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
Rx64Response rx64 = Rx64Response();
int statusLed = 11;
int errorLed = 12;
int dataLed = 10;
uint8_t option = 0;
uint8_t data = 0;
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
pinMode(dataLed, OUTPUT);
// start serial
xbee.begin(9600);
flashLed(statusLed, 3, 50);
}
// continuously reads packets, looking for RX16 or RX64
void loop() {
xbee.readPacket();
Page 51 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
if (xbee.getResponse().isAvailable()) {
// got something
if (xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() ==
RX_64_RESPONSE) {
// got a rx packet
if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
xbee.getResponse().getRx16Response(rx16);
option = rx16.getOption();
data = rx16.getData(0);
} else {
xbee.getResponse().getRx64Response(rx64);
option = rx64.getOption();
data = rx64.getData(0);
}
// TODO check option, rssi bytes
flashLed(statusLed, 1, 10);
// set dataLed PWM to value of the first byte in the data
analogWrite(dataLed, data);
} else {
// not something we were expecting
flashLed(errorLed, 1, 25);
}
}
}
“series1_Tx”
/**
* Copyright (c) 2009 Andrew Rapp. All rights reserved.
*
* This file is part of XBee-Arduino.
Page 52 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
*
* XBee-Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XBee-Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>.
*/
#include <XBee.h>
/*
This example is for Series 1 XBee
Sends a TX16 or TX64 request with the value of analogRead(pin5) and checks the status response for
success
Note: In my testing it took about 15 seconds for the XBee to start reporting success, so I've added a startup
delay
*/
XBee xbee = XBee();
unsigned long start = millis();
// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0, 0 };
// with Series 1 you can use either 16-bit or 64-bit addressing
// 16-bit addressing: Enter address of remote XBee, typically the coordinator
Tx16Request tx = Tx16Request(0x1874, payload, sizeof(payload));
Page 53 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
// 64-bit addressing: This is the SH + SL address of remote XBee
//XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x4008b490);
// unless you have MY on the receiving radio set to FFFF, this will be received as a RX16 packet
//Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));
TxStatusResponse txStatus = TxStatusResponse();
int pin5 = 0;
int statusLed = 11;
int errorLed = 12;
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
xbee.begin(9600);
}
void loop() {
// start transmitting after a startup delay. Note: this will rollover to 0 eventually so not best way to
handle
if (millis() - start > 15000) {
// break down 10-bit reading into two bytes and place in payload
pin5 = analogRead(5);
Page 54 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
payload[0] = pin5 >> 8 & 0xff;
payload[1] = pin5 & 0xff;
xbee.send(tx);
// flash TX indicator
flashLed(statusLed, 1, 100);
}
// after sending a tx request, we expect a status response
// wait up to 5 seconds for the status response
if (xbee.readPacket(5000)) {
// got a response!
// should be a znet tx status
if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);
// get the delivery status, the fifth byte
if (txStatus.getStatus() == SUCCESS) {
// success. time to celebrate
flashLed(statusLed, 5, 50);
} else {
// the remote XBee did not receive our packet. is it powered on?
flashLed(errorLed, 3, 500);
}
}
} else {
// local XBee did not provide a timely TX Status Response -- should not happen
flashLed(errorLed, 2, 50);
}
delay(1000);
}
Page 55 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
“Sensor”
byte zero=0x00;
int ledPin = 13; // LED connected to digital pin 13
int inPin = 3; // pushbutton connected to digital pin 7
int val = 0;
// variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
// sets the digital pin 13 as output
// sets the digital pin 7 as input
Serial.begin(115200);
}
void loop()
{
val = analogRead(inPin); // read the input pin
//digitalWrite(ledPin, val);
// sets the LED to the button's value
if(val > 900)
{
digitalWrite(ledPin, HIGH);
Serial.print("Sensor reading");
Serial.print(val);
delay(500);
}
else
{
digitalWrite(ledPin, LOW);
}
}
“lightsensor_wif_motor_senddm_n1”
/*
* ------Waspmote XBee DigiMesh Sending & Receiving Example-----*
* Explanation: This example shows how to send and receive packets
* using Waspmote XBee DigiMesh API
*
Page 56 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
* This code sends a packet to another node and waits for an answer from
* it. When the answer is received it is shown.
*
* Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version:
0.2
* Design:
David Gascón
* Implementation:
Alberto Bielsa
*/
#include "WaspXBeeDM.h"
packetXBee* paq_sent;
Page 57 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
int8_t state=0;
long previous=0;
char* data1="H";
int val = 0;
// variable to store the read value
void setup()
{
// Inits the XBee DigiMesh library
xbeeDM.init(NORMAL);
// Powers XBee
xbeeDM.ON(9600);
pinMode(13, OUTPUT);
pinMode(3, INPUT); //using the sensor
}
void loop()
{
val = analogRead(3); // read the input pin
digitalWrite(13,LOW);
// Set params to send
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=BROADCAST;
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
xbeeDM.hops=0;
xbeeDM.setOriginParams(paq_sent, "0013A200403B868A", MAC_TYPE);
if(val > 900)
{
xbeeDM.setDestinationParams(paq_sent, "0013A200403B86B8", data1, MAC_TYPE,
DATA_ABSOLUTE);
Page 58 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
digitalWrite(13,HIGH);
xbeeDM.sendXBee(paq_sent);
}
free(paq_sent);
paq_sent=NULL;
// Waiting
delay(1000);
}
“Light_sensor_wif_motor_receive_dm_n5”
/*
* ------Waspmote XBee DigiMesh Sending & Receiving Example-----*
* Explanation: This example shows how to send and receive packets
* using Waspmote XBee DigiMesh API
*
* This code sends a packet to another node and waits for an answer from
* it. When the answer is received it is shown.
*
* Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
Page 59 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version:
0.2
* Design:
David Gascón
* Implementation:
Alberto Bielsa
*/
#include "WaspXBeeDM.h"
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos=0;
packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char* data="Test message!";
void setup()
{
// Inits the XBee DigiMesh library
xbeeDM.init(NORMAL);
// Powers XBee
xbeeDM.ON(9600);
pinMode(13, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
Page 60 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
{
digitalWrite(13,LOW);
if( xbeeDM.available() )
{
//digitalWrite(13,HIGH);
xbeeDM.treatData();
if( !xbeeDM.error_RX )
{
// Writing the parameters of the packet received
while(xbeeDM.pos>0)
{
if (xbeeDM.packet_finished[xbeeDM.pos-1]->data[0] == 'H')
{
digitalWrite(13,HIGH);
// servo
/*for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{
// in steps of 1 degree
myservo.write(pos);
delay(5);
// tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
} */
myservo.write(10);
/*for(pos = 180; pos>=1; pos-=1)
// goes from 180 degrees to 180 degrees
{
myservo.write(pos);
delay(50);
// tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
}*/
}
free(xbeeDM.packet_finished[xbeeDM.pos-1]);
Page 61 of 69
Eng 499 SMART DEVICES FOR HOME ASSISTANCE
Lim Zongyao W0704223
xbeeDM.packet_finished[xbeeDM.pos-1]=NULL;
xbeeDM.pos--;
}
}
delay(1000);
myservo.write(95);
}
}
Page 62 of 69