Senior - 2022 (1) v4
Senior - 2022 (1) v4
Senior - 2022 (1) v4
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING
BY
NGUYEN HUU HUNG
i
BUILD A WIRELESS NETWORK (ZIGBEE) TO TRANSMIT DATA AND
CONTROL DEVICES IN SMART HOME.
BY
NGUYEN HUU HUNG
Under the guidance and approval of the committee, and approved by its members, this thesis has been
Approved:
Chairperson
Committee member
Committee member
Committee member
ii
HONESTY DECLARATION
My name is Nguyen Huu Hung. Other than the sources that have been acknowl-
edged, this thesis either uses no original language, ideas, or other materials, or it hasn’t
been submitted to any other academic or research programs or organizations. I under-
stand that if any of the papers in my thesis contradict the aforementioned statement, the
International University-Vietnam National University in Ho Chi Minh City will imme-
diately disqualify me from the EE program.
Date
Student’s Signature
iii
TURNITIN DECLARATION
Name of student: Nguyen Huu Hung
Date: January 3rd , 2023
iv
ACKNOWLEDGEMENT
I would like to gratefully acknowledge various people who have journeyed with me in
this senior project.
I want to convey my sincere appreciation to my adviser, Mr. Nguyen Van Binh, and
Mr. Ton That Long for their insightful advice. They have spent a lot of useful time with
me to guide this research. Besides, their teaching method and inexhaustible motivation
have inspired me in completing the report on time. At the same time, he has consolidated
my fundamental knowledge and given me an insight and realistic view of the electrical
engineering field in my future career. In particular, he is a huge motivation for me to try
my best and never give up. That is the reason why I always strive to be a better version
of myself compared to who I was yesterday.
I want to thank my parents who were always beside me and gave me belief and
strength. Moreover, they always encourage and support me to reach my own goals.
v
ABSTRACT
In this topic, the Zigbee application can control the simulated lighting system.
When the code is transferred to the Zigbee system, it will emit broadcast data to the
router device in the system. This device was designed to communicate with a microcon-
troller (PIC or Arduino). After that, the microcontroller processed broadcast data and
emit the signal to the simulated lighting system.
vi
Contents
TURNITIN DECLARATION iv
ACKNOWLEDGEMENT v
ABSTRACT vi
I INTRODUCTION 1
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Structure Of Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Goals and Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
IV LITERATURE REVIEW 6
4.1 Smart Home . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.1.1 Smart home definition . . . . . . . . . . . . . . . . . . . . . . . . 6
4.1.2 The advantage of the smart home . . . . . . . . . . . . . . . . . . 7
4.2 Zigbee Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2.1 WPAN definition . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2.2 Zigbee definition . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2.3 Developed history . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2.4 Comparison between Zigbee, Bluetooth, and Wifi. . . . . . . . . 9
vii
4.3 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.5 Protocol Model of ZIGBEE/IEEE802.15 [6] . . . . . . . . . . . . . . . . . 15
4.5.1 Physical Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.6 Equipment Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.6.1 Coordinator (ZC) . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.6.2 Router (ZR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.6.3 Zigbee End Device (ZED) . . . . . . . . . . . . . . . . . . . . . . 17
4.7 Network Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.7.1 Star topology (Point to Point) . . . . . . . . . . . . . . . . . . . . 18
4.7.2 Mesh topology (Peer-to-Peer) . . . . . . . . . . . . . . . . . . . . 19
4.7.3 Cluster Tree topology . . . . . . . . . . . . . . . . . . . . . . . . 20
V METHODOLOGY 21
5.1 Model of Zigbee network . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2 Hardware Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.2.1 Interfacing XBee with Arduino (Router 1) . . . . . . . . . . . . . 22
5.2.2 Interfacing XBee with NodeMCU (Router 2) . . . . . . . . . . . . 23
5.2.3 Interfacing XBee with Arduino (Coordinator) . . . . . . . . . . . 24
5.3 Configuring XBee Modules using XCTU Software [7] . . . . . . . . . . . 25
5.4 Flow Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.5 ZigBee (Router 1) Communication Program for Arduino . . . . . . . . . 33
5.6 ZigBee (Coordinator) Communication Program for Arduino . . . . . . . 35
5.7 ZigBee (Router 2) Communication Program for ESP32 . . . . . . . . . . . 36
5.8 Create UI to control system . . . . . . . . . . . . . . . . . . . . . . . . . . 41
VI EXPECTED RESULTS 42
6.1 Router 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.2 Router 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.3 Coordinator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.4 Android User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
REFERENCES 44
viii
List of Figures
ix
List of Tables
1 Hardware devices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Software devices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Budget plan. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Project Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5 Comparison between Zigbee, Bluetooth, and Wifi. . . . . . . . . . . . . . 9
6 Destination and source address. . . . . . . . . . . . . . . . . . . . . . . . 30
x
ABBREVIATIONS AND NOTATIONS
PAN: A personal area network
FB: Firebase
ZC: Zigbee Coordinator
ZR: Zigbee Router
ZED: Zigbee End-device
xi
I INTRODUCTION
This chapter is divided into 2 parts: the overview, and the structure of the project.
1.1 Overview
ZigBee technology is used in sensors and control systems that have a lengthy op-
erational cycle but low transmission speed. ZigBee technology has the benefits of short
transmission times, low power requirements, cheap costs, low error rates, simple scal-
ing, and high interoperability. It operates in the frequency ranges of 868/915 MHz and
2.4 GHz. I want to show my study on ZigBee technology and the device connection
application in my senior project so that you can better grasp the technology.
1
At the same time, smart home is a growing trend in the construction of houses,
apartments, or commercial centers. For a long time, it has been a topic that has attracted
much attention and research from scientists as well as the community. With that crite-
rion, this thesis will present how to build a simple monitoring and control system for
connecting and controlling home appliances through the Zigbee network.
Hopefully, through the issues mentioned in this thesis, people will have a deeper
appreciation and understanding of ZigBee/IEEE 802.15.4 technology and its role and
potential in daily life.
The structure of the report is depicted in eight chapters. Chapter 1 introduces my project.
It includes two small parts: the overview, and the structure of the report. The specifi-
cation of required design and performance standards is covered in chapter 2 after that.
Additionally, chapter three of the project management book displays the project’s strat-
egy, which includes its statistics-based timetable, budget, and resources. Chapter 4 is the
literature review that includes the information as well as the fundamental concepts of the
dipole antenna, reflector antenna, and balun. Therefore, chapter 5 will be the method-
ology that carefully illustrates the implementation processes. Furthermore, chapter 6 is
the expected results of the project which will be shown clearly with detailed comments.
In chapter 7, the conclusion and future work will be discussed. The project’s business,
social, and ethical issues are presented in the eighth and final chapters. The report also
includes a list of references at the conclusion.
The goal of this senior project is to understand how the xbee work and the way to transfer
data through internet. A network system which uses 3 Xbee was built in order to create
three node in a network. Each node will control one light and all the information to
control the system will store on FB.
2
II DESIGN SPECIFICATIONS AND STANDARDS
In this senior project, the data will be transferred through 2 Zigbee communicated with
Arduino by UART communication, before getting to the ESP32S. After that, ESP32 con-
nected to the Internet will be stored at Firebase. Users can control devices by using a
user interface that is built using Android Studio.
Hardware Description
3
2.3 Software
Software Description
Firebase [3] Firebase provides tools to grow your app and busi-
ness, for startups and global enterprises. Get
your app up and running quickly and securely
with fully managed backend infrastructure. Build
Extraordinary Apps. Release Apps Confidently.
Monitor App Performance. Backed by Google.
There are two main constraints for this project. First, the wires connected between de-
vices are regularly loose which causes the system shut down, and I found difficulties
when tracking back the errors. Second, the stimulation device on Android Studio is not
stable and the time for turning on the stimulation device is extended.
4
III PROJECT MANAGEMENT
This chapter provides a summary of the project’s personnel, timelines, financial con-
cerns, and techniques for planning, monitoring, and controlling the project. The project
has been supported during performed processes and the consultants who are pioneer
instructors approached the right direction to harvest the best dominant seed and listed
their work in this project management process.
There are various challenges and problems in calculating the cost of the components
and devices during the installation phase. The project comprises a Zigbee, a smart home
system prototype. Without factoring in travel expenses and the cost of additional in-
struments like those shown in the table, the project’s overall budget is around 3.000.000
VND.
Zigbee 3 2.500.000
Arduino 2 230.000
Esp32s 1 195.000
Total 6 2.950.000
Find and investigate the related documents about 07/09/2022 – 14/09/2022 - 1 week
Zigbee.
Arduino 2
5
IV LITERATURE REVIEW
This chapter includes the Smart home’s definition and provides detailed information
about Zigbee technology.
The term ”smart home” refers to a particular style of home where electrical and elec-
tronic technology is installed to automate or partially automate certain tasks, such as
management and control.
In a smart home, the toilet, living room, and bedroom equipment are connected
to electronic controls via the internet and mobile devices, enabling owners to remotely
control or program them to carry out predetermined actions. Additionally, appliances
can communicate and understand one another’s languages.
6
4.1.2 The advantage of the smart home
This technology not only enables integrated control within the home but also over
the phone (fixed or mobile), internet, or PDA. Therefore, whether we are at work or on
the street, all activities can be managed. If you choose the proper technology, you may
completely smart any living place, including office buildings, supermarkets, shopping
malls, hotels, restaurants, factories, banks, hospitals, or other complexes.
7
4.2 Zigbee Network
A WPAN is a wireless personal area network. This set of radio technologies comprises
those with minimally tens to hundreds of meters of coverage. These technologies link
mobile phones and PCs to peripheral devices including printers, keyboards, mice, hard
drives, USB keys, watches, etc. This collection of technologies consists of Bluetooth,
VVibree, ZigBee, UWB, wireless USB, and Enocean.
A set of short-distance wireless network communication protocols with low data trans-
mission rates. Zigbee-based wireless devices operate on three frequency ranges, 868MHz,
915MHz, and 2.4GHz.
The name Zigbee is derived from the way honeybees transmit information, which
is the zig-zag type of honeybees. The name Zigbee is also a combination of these two
words.
8
4.2.3 Developed history
Technology developers created the Zigbee network in 1998 after realizing that Bluetooth
and WiFi weren’t practical for many uses. The IEEE 802.15.4 standard was finished in
May 2003. the founding of the Zigbee Alliance in October 2004. This group of businesses
is cooperating to allow and test low-speed, no-wire, inexpensive, energy-efficient, and
highly secure product networks. is a cooperative, independent, not-for-profit organiza-
tion. It develops industry standards for Zigbee engineering, certification, brand building,
and market.
• On 11/12/2004, the first version was born: Zigbee 2004. Also around this time, the
world’s first Zigbee phone was introduced with features such as control of house-
hold electrical appliances and temperature monitoring. temperature, humidity, and
alarm system.
Unlike Bluetooth and Wifi, which only allow two goods to communicate with one
another, Zigbee enables information to be transmitted to several devices simultaneously
(mesh network). The operational range of Zigbee has increased from 75 meters to a few
hundred meters.
Although the speed is only 256 Kbps and Zigbee is more commonly utilized in larger
mesh networks than Bluetooth, this technology uses less energy than Bluetooth. When
9
Bluetooth is not amplified, its operational range is just 10 meters, but it may reach up to
75 meters when it does.
4.3 Features
– The device uses an open standard suitable for all electrical-electronic devices
on the market.
• Easy to control
– Wireless technology reduces the costs and troubles of traditional wired net-
works. Use 2.4 GHz international frequency easily installed and used.
• Safety
– Easily installs wireless sensors to monitor the security of the house. Receive
instant notifications when an unusual event occurs.
– AES Wireless system is specially encrypted, ensuring that only the owner has
the ability to control the system.
• Activity link
– Because the applications are built in the module form, users only have to buy
the equipment they need. It is possible to combine many product lines without
caring for manufacturers who can work with other Zigbee networks.
10
4.4 Applications
Efficiency energy: is the top standard in the world for compatible products that reg-
ulate, automate, notify, and monitor the supply of water energy. Providing customers
with the knowledge and automation they need to quickly lower their usage and save
money, contributes to the development of a greener home.
This standard addresses the many requirements of the global ecosystem, product
makers, and government initiatives to fulfill future energy and water demands.
It allows clients more freedom by allowing them to manage equipment from neigh-
boring rooms and install devices virtually anywhere, even behind wood, walls, interior
design, or glass.
Smart home: Zigbee Smart Home provides a common standard for Zigbee-compatible
smart home products that can manage energy and security settings, control lighting and
appliances, and connect to other Zigbee networks. Customers who live in smart homes
may save money, feel safer, and take advantage of a variety of easy-to-maintain features.
The functionality of every Zigbee smart home gadget is guaranteed. Texas Instru-
ments, Phillips, and Control4 are just a few of the inventors that have contributed their
knowledge to this standard.
11
Healthcare: is keeping an eye on patients at home. Wearable technology may be
used to assess things like a patient’s heart rate and blood pressure. A Zigbee gadget
that the patient wears monitors vital signs including heart rate and blood pressure. The
first analysis is carried out on a local server, which might be a personal computer in the
patient’s house before the data is wirelessly transported there.
The patient’s nurse or physiotherapist will then get critical information over the In-
ternet for additional analysis. Leading healthcare organizations and businesses, such as
Motorola, Phillips, Freescale Semiconductor, Avvarepoint, and RF technology, are sup-
porting the development of ZigBee Healthcare technology.
12
Telecommunication services: ZigBee Telecommunications Services provides a
global standard for compatible devices, enabling a range of value-added businesses in-
cluding transportation, mobile gaming, and service-based services. Areas for payments,
peer-to-peer data sharing services, secure mobile payments, mobile advertising, and pay-
ments.
As they look for new methods to engage the public, companies, governments, mo-
bile phone providers, and product manufacturers may all benefit from ZigBee Telecom-
munications services. All devices from ZigBee Telecom Services have performance cer-
tifications.
Phillips, Telecom Italia, Telefonica, OKI, Huawei, Motorola, and Texas Instruments
were among the leading telecommunications, product manufacturing, and technology
firms that contributed to the creation of this standard.
Automatic construction:
• Control
– Centrally and seamlessly managed lighting, heating, cooling, and security sys-
tems.
• Preservation
• Flexibility
• Safety
13
– Deploy a wireless surveillance network for enhanced perimeter protection.
14
4.5 Protocol Model of ZIGBEE/IEEE802.15 [6]
This is a method for designing application layers and network layers based on the PHY
and MAC levels of the IEEE 802.15.4 standard. Dependability, simplicity, low power
usage, and high network environment adaptability are advantages of it.
Provides management service and data service (PHY), the two major services (PHY).
The PPDU data block’s transceiver is controlled by the data service (PHY) over the
physical radio duplex channel.
15
• ED (Energy Detection)
The ED index is measured by the ED receiver. This index will be used by the network
layer as a step in the channel selection algorithm. It is the result of an estimate of the
energy capacity of the received signal. It has no role in decoding or identifying the
signal transmitted in this channel. The detection and processing time is equivalent
to 8 symbols.
A minimum value of ED (= 0) when the received power is +10 DB less than theo-
retical. The magnitude of the received power range to display the minimum ED is
40db ± 6db
Full-function devices (FFDs) are gadgets that can play any part in the system and
completely support IEEE 802.15.4 functionalities. The FFD can function in three different
capacities: as the coordinator of the entire PAN, as the coordinator of a subnet, or just
as a regular member of the network, boosting the network’s memory and processing
capabilities. it may be utilized in edge network devices or is suited for network router
functionality (where the network touches the real world).
Reduced-unction devices (RFDs): are devices that limit some functions (only com-
municate with FFDs, applicable to simple applications that do not require sending large
amounts of data such as turning lights on and off) with lower cost and more complexity.
A network must have at least one FFD device, one FFD can work with multiple
RFDs or multiple FFDs while an RFD can only work with one FFD.
16
There are three types of Zigbee’s devices:
This device forms and maintains the overall network architecture, and it controls and
monitors the network, and stores information about the network. So it requires the
most memory and computing power. It is an FFD device.
a smart device capable of extending network coverage by routing and providing redun-
dancy or recovery of congested routes; acts as an intermediary router, transmitting data
between different devices. It tries to connect to ZC, ZR, and even ZED. It is also an FFD
device.
Those are sensor nodes that have information from the environment. It can receive
messages but cannot transmit messages, it can connect to ZC and ZR but cannot connect
to each other. It can be FFD or RFD.
17
4.7 Network Models
Network nodes in a Zigbee network can be connected to each other according to the star
network structure (Star), mesh (Mesh), and cluster tree structure (Tree). This diversity
of network structure allows Zigbee technology to be widely applied.
For this type of network, the devices link to a PAN coordinator device, which is a de-
vice configured to operate the control center. The FFD may create its own network and
take on the role of a PAN coordinator after being activated for the first time. The PAN ID
(PAN identifier), which is exclusive to each star network and cannot be used by any other
networks within its sphere of influence (the area), is required for radio emitters to suc-
cessfully connect with one another. In other words, it makes sure that no other adjacent
networks are using the PAN ID it picks, enabling the network to operate autonomously.
After then, the PAN coordinator can be reached via the FFD and RFD.
Every network node in the PAN network must pass via the PAN coordinator, mak-
ing it a centralized network. As a result, zc will use more energy than other network
nodes, and the network has a large coverage area. limited coverage (within a 100m ra-
dius). Small-scale applications including home automation, computer accessories, toys,
and games are advised to use this star structure.
18
4.7.2 Mesh topology (Peer-to-Peer)
This type of network topology also has a PAN coordinator. In fact, this is a combination
of two types of star and lattice structures peer-to-peer, in this network topology, device
A can make a connection with any other device as long as that device is within range of
device A.
The mesh network is not highly concentrated like a star network, but instead has
point-to-point connections within the coverage of network points. The network oper-
ates in an ad-hoc mode that allows multi-hop forwarding through ZRs, which means that
a routing algorithm is required to find the most optimal paths. This network can operate
over a wide range, but it is difficult to reduce the complexity of linking any point-to-
point in the network, so it is difficult to guarantee a minimum transmission time. The
applications of this structure can be in measurement and control, wireless sensor net-
work, monitoring, and alarm monitoring and control (forest fire alarm)… ZR acts as a
coordinator in the area. Its operating area to widen communication at the network level.
If devices in a peer-to-peer network are placed close enough to one another, a con-
nection can be established between them. In a peer-to-peer network, every FFD has the
ability to act as a PAN coordinator. One technique to choose which device will act as
the PAN operator is to choose the first FFD device to commence communication as a
PAN coordinator. An RFD can be a part of a network, but it only communicates with
one specific network device (ZC or ZR).
19
4.7.3 Cluster Tree topology
This is a special kind of mesh design where the bulk of the devices are FFDs and an
RFD can be joined to the tree as a separate node at the end of a branch. Since each FFD
has the potential to serve as a coordinator and provide synchronization signals to other
devices and coordinators, this type of network design provides exceptional coverage
and scalability. Despite the possibility of several coordinators, there is only one PAN
coordinator in this configuration.
ZRs receive messages and form branches. The ZEDs behave as if they were leaves
and do not take part in routing.
The PAN coordinator creates the first group by electing its own leader and assigns
that leader a special personal identifier called CID-0 (cluster identifier) by automatically
establishing CLH (cluster head) using CID-0. It selects an idle PAN identifier and broad-
casts the identity broadcast to neighboring devices. The device that receives this frame
can request to connect to the CLH network. If the PAN coordinator allows the device to
connect, it will add the device’s name to the list.
So this newly connected device becomes the CLH of the new branch and starts
broadcasting periodically so that other devices can connect to the network. From there,
CLH1, CLH2 were formed…
The tree network promises to bring the advantages of the two networks above: star
network (synchronism, reliable transmission thanks to GTS mode) and mesh network.
20
V METHODOLOGY
This chapter illustrates how to configure and program Zigbee by using XCTU and Ar-
duino software. In addition, it also introduces how to simulate the circuit by using Fritz-
ing software.[2]
The model starts with the connection of one ESP32 and 2 Arduino through the Zigbee
network. The final output is the status of three LEDs which are updated on the Fire-
base. Then User Interface on mobile will realizes the change of data on Firebase before
updating the UI. The App on the mobile can also change and control the LED through
Firebase.
21
5.2 Hardware Design
The push-button that transmits data when pressed is utilized in the Arduino XBee circuit
design above. Connect one end of the button to Arduino pin number 3 and the other end
to GND to do this.
Connect the XBee module’s VCC (pin 1) and GND (pin 10) to the Arduino Uno’s
3.3V and GND, respectively. The transmitting side XBee module is powered by these two
connectors. Connect Din (pin 3) to Arduino Uno pin 5 and Dout (pin 2) to Arduino Uno
pin 4. The hardware arrangement I created for this circuit on a breadboard, complete
with all the connections, is shown below.
Figure 7: Router 1.
22
5.2.2 Interfacing XBee with NodeMCU (Router 2)
Connect the XBee’s Vcc (Pin 1) to the NodeMCU’s 3.3V supply and the Gnd (Pin 10) to
the NodeMCU’s GND. The two connections mentioned above are also used to power the
XBee module. Connect the XBee’s Din (pin 3) and Dout (pin 2) pins to the NodeMCU’s
22-pin and 23-pin, respectively, for data reception.
We’ve utilized LED to show if the data has been received or not. To do this, connect
the LED cathode to GND and the LED anode to pin 18 of the NodeMCU with a 220-ohm
resistor. Once more, I built this circuit on a breadboard, and the hardware setup I used,
complete with all the connections, is shown below.
Figure 8: Router 2.
23
5.2.3 Interfacing XBee with Arduino (Coordinator)
We utilized an Arduino Nano for this portion of the connection. Boards from NodeMCU
or the Arduino Uno can also be utilized.
Connect the XBee module’s VCC (pin 1) and GND (pin 10) to the Arduino Uno’s
3.3V and GND, respectively. The transmitting side XBee module is powered by these two
connectors. Connect Din (pin 3) to Arduino Uno pin 5 and Dout (pin 2) to Arduino Uno
pin 4. The hardware arrangement I created for this circuit on a breadboard, complete
with all the connections, is shown below.
Figure 9: Coordinator.
24
5.3 Configuring XBee Modules using XCTU Software [7]
25
Step 2: Selecting the COM port that the XBee module is connected to will prompt
you to click ”Next.”
26
Step 4: At this point, select ”Add Selected Devices” from the pop-up box.
Step 5: Now the left side of the window will display the XBee module. By clicking
it, you may adjust the user interface.
27
Step 6: Click ”Upgrade” to upgrade the firmware, then choose ”802.15.4 TH” from
the Function set and the most recent firmware from the Firmware version. After that, a
pop-up window will appear. Pick YES.
Step 7: As the PAN ID, enter any 4 digits. PAN identification is called a PAN ID. A
unique ID must be assigned to each network. Make sure the same PAN ID is supplied
for both XBee modules. The presence of both XBee modules in the same network is
indicated by this.
28
Step 8: The destination address might be any 4 digits. The other XBee module’s
Source Address must also be the same number.
Step 9: The Source Address might be any 4 digits. For the second XBee module, the
Destination Address must be the same number.
29
Step 10: Specify ”Coordinate [1]” for one device. as ”End Device [0],” and the other
device.
Step 11: At this stage, click Write in the top bar. When something is successfully
completed, the Symbol switches from ”E” to ”C.” (End Device to Coordinator, as we have
configured). For the other XBee module, ”E” is the appropriate response.
30
5.4 Flow Diagrams
31
Figure 20: Push button Flow Diagram
32
5.5 ZigBee (Router 1) Communication Program for Arduino
First, we include the SoftwareSerial library and declare the pin for XBee to communicate
with Arduino in pin 4 (Rx) and pin 5 (Tx).
1 S o f t w a r e S e r i a l XBee ( 4 , 5 ) ; / / r x P i n , t o x i n
Pin 3 must be designated as the push button. The button is attached to the Arduino
Nano on pin 3, which is necessary for data transmission. The LED is connected through
pin 13. Set the distinct values for the led’s on and off states.
1 c o n s t i n t p u s h B u t t o n = 3 ; / / push p u s h B u t t o n
The statement is utilized to monitor button clicks. The LED is turned on when the button
is pressed once; it is turned off when the button is pressed again. It uses the toggle to
keep track of this.
1 boolean toggle = f a l s e ;
The program starts from a void setup, and the baud rate for the serial monitor is set.
1 S e r i a l . begin ( 9 6 0 0 ) ;
2 XBee . b e g i n ( 9 6 0 0 ) ;
2 pinMode ( l e d , OUTPUT ) ;
33
This part will check if the Zigbee receives the signal. If it receives and the value is
1, the light will be turned on. The reverse will be true when the value is 0.
1 i f ( XBee . a v a i l a b l e ( ) > 0 ) {
2 i n t r e c e i v e d = XBee . r e a d ( ) ;
4 d i g i t a l W r i t e ( l e d , HIGH ) ;
5 toggle = false ;
6 }
8 d i g i t a l W r i t e ( l e d , LOW) ;
9 toggle = true ;
10 }
11 }
These lines of code illustrate the situation when the push button is pressed.
1 else
2 {
3 i f ( d i g i t a l R e a d ( p u s h B u t t o n ) == LOW && t o g g l e )
4 {
5 toggle = false ;
6 S e r i a l . p r i n t l n ( ”ON” ) ;
8 d i g i t a l W r i t e ( l e d , HIGH ) ;
9 delay (1000) ;
10 }
11
12 e l s e i f ( d i g i t a l R e a d ( p u s h B u t t o n ) == LOW && ! t o g g l e )
13 {
14 toggle = true ;
15 S e r i a l . p r i n t l n ( ” OFF ” ) ;
17 d i g i t a l W r i t e ( l e d , LOW) ;
18 delay (1000) ;
19 }
20 }
34
5.6 ZigBee (Coordinator) Communication Program for Arduino
1 S o f t w a r e S e r i a l XBee ( 4 , 5 ) ; / / r x P i n , t x P i n
2 c o n s t i n t p u s h B u t t o n = 3 ; / / push p u s h B u t t o n
4 boolean toggle = f a l s e ;
10
11 void setup ( )
12 {
14 S e r i a l . begin ( 9 6 0 0 ) ;
15 XBee . b e g i n ( 9 6 0 0 ) ;
17 pinMode ( l e d , OUTPUT ) ;
18 }
19
20 void loop ( )
21 {
22 i f ( d i g i t a l R e a d ( p u s h B u t t o n ) == LOW && t o g g l e )
23 {
24 S e r i a l . p r i n t l n ( ”ON” ) ;
25 toggle = false ;
26 d i g i t a l W r i t e ( l e d , HIGH ) ;
28 delay (1000) ;
29 }
30
31 e l s e i f ( d i g i t a l R e a d ( p u s h B u t t o n ) == LOW && ! t o g g l e )
32 {
33 S e r i a l . p r i n t l n ( ” OFF ” ) ;
34 toggle = true ;
35 d i g i t a l W r i t e ( l e d , LOW) ;
35
37 delay (1000) ;
38 }
40 e l s e i f ( XBee . a v a i l a b l e ( ) > 0 )
41 {
42 i n t r e c e i v e d = XBee . r e a d ( ) ;
44 {
45 d i g i t a l W r i t e ( l e d , LOW) ;
46 toggle = true ;
47 }
49 {
50 d i g i t a l W r i t e ( l e d , HIGH ) ;
51 toggle = false ;
52 }
54 {
55 XBee . w r i t e ( r e c e i v e d ) ;
56 }
57 }
58 }
Because the Arduino program does not have a board that allows esp to connect to upload
code. So we need to add the preferences in Arduino in other to trigger the download
board of the software.
Step 3: Then click Tool − > Board − > ESP32 Arduino − > ESP32 Dev Module
36
Figure 21: Preferences.
37
Figure 23: Connect ESP32 with Arduino.
1 # i n c l u d e <WiFi . h>
2 # i n c l u d e <F i r e b a s e E S P 3 2 . h>
Defining wifi password and wifi username in other to allow ESP to connect to Wifi.
1 # d e f i n e WIFI SSID ” w i f i s s i d ”
2 # d e f i n e WIFI PASSWORD ” w i f i p a s s w o r d ”
Including the SoftwareSerial library and declaring pin for XBee to communicate with
Arduino in pin 4 (Rx) and pin 5 (Tx).
1 S o f t w a r e S e r i a l XBee ( 4 , 5 ) ; / / r x P i n , t x P i n
1 # d e f i n e FIREBASE HOST ” f i r e b a s e h o s t ”
2 # d e f i n e FIREBASE AUTH ” f i r e b a s e a u t h ”
Function setStreamCallback is to assign the callback function that accepts the FirebaseS-
tream class as a parameter.
2 {
3 Serial . println () ;
4 s i z e t numChild = s i z e o f ( c h i l d P a t h ) / s i z e o f ( c h i l d P a t h [ 0 ] ) ;
5 S e r i a l . p r i n t l n ( numChild ) ;
6 f o r ( s i z e t i = 0 ; i < numChild ; i + + )
7 {
8 i f ( stream . get ( c h i l d P a t h [ i ] ) )
38
9 {
10 S e r i a l . p r i n t l n ( stream . get ( c h i l d P a t h [ i ] ) ) ;
13 }
14 }
15 Serial . println () ;
16 }
The global notification function for failed stream connections. The library will automat-
ically reestablish the stream connection.
1 void streamTimeoutCallback ( bool timeout )
2 {
3 i f ( timeout )
4 {
5 Serial . println () ;
6 S e r i a l . p r i n t l n ( ” S t r e a m t i m e o u t , resume s t r e a m i n g . . . ” ) ;
7 Serial . println () ;
8 }
9 }
The WiFi library’s network settings are set up using wifi.begin(SSID, PASSWORD),
which also returns the current status.
• SSID: the SSID (Service Set Identifier) the name of the WiFi network.
While the connection is still not established, the dot will be printed on the serial monitor
every 500ms
1 w h i l e ( WiFi . s t a t u s ( ) ! = WL CONNECTED ) {
2 delay (500) ;
3 Serial . print ( ” . ” ) ;
4 }
Define the Firebase Data object, and Firebase for sending data.
39
1 FirebaseData firebaseData ;
2 FirebaseData firebaseData1 ;
1 F i r e b a s e . b e g i n (& c o n f i g , &a u t h ) ;
1 F i r e b a s e . beginStream ( f i re b as e D at a , path ) ) {
2 S e r i a l . p r i n t l n ( ”REASON : ” + f i r e b a s e D a t a . e r r o r R e a s o n ( ) ) ;
3 Serial . println () ;
4 } else {
5 S e r i a l . p r i n t l n ( ” Streaming ” ) ;
6 }
40
5.8 Create UI to control system
Download Android Studio and install software to computer − > Create a new flutter
project.
After that, create 3 files which are customDatabase, navigationDrawer, and custom-
Data. Create a navigation drawer for the app.
41
VI EXPECTED RESULTS
6.1 Router 1
6.2 Router 2
42
6.3 Coordinator
43
REFERENCES
References
[1] Store Arduino Arduino. “Arduino”. In: Arduino LLC 372 (2015).
[2] Mon Mon Aye, Aye Myat Myat Myo, and Zar Chi Soe. “Microcontroller Based Temperature Moni-
[3] Laurence Moroney. “The firebase realtime database”. In: The Definitive Guide to Firebase. Springer,
[4] Yogendra Singh Parihar et al. “Internet of things and nodemcu”. In: Journal of Emerging Technologies
[5] Rap Payne. “Developing in Flutter”. In: Beginning App Development with Flutter. Springer, 2019, pp. 9–
27.
[6] Nisha Ashok Somani and Yask Patel. “Zigbee: A low power wireless technology for industrial ap-
plications”. In: International Journal of Control Theory and Computer Modelling (IJCTCM) 2.3 (2012),
pp. 27–33.
[7] Jonathan A Titus. The hands-on XBEE lab manual: experiments that teach you XBEE wirelesss commu-
44