You are on page 1of 55

VIETNAM NATIONAL UNIVERSITY – HOCHIMINH CITY

INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING

BUILD A WIRELESS NETWORK (ZIGBEE) TO TRANSMIT DATA


AND CONTROL DEVICES IN SMART HOME.

BY
NGUYEN HUU HUNG

A SENIOR PROJECT SUBMITTED TO THE SCHOOL OF ELECTRICAL

ENGINEERING IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE

DEGREE OF BACHELOR OF ELECTRICAL ENGINEERING

HO CHI MINH CITY, VIET NAM


2020

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

accepted in partial fulfillment of the requirements for the degree.

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

Advisor Signature Student Signature

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

HONESTY DECLARATION iii

TURNITIN DECLARATION iv

ACKNOWLEDGEMENT v

ABSTRACT vi

ABBREVIATIONS AND NOTATIONS xi

I INTRODUCTION 1
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Structure Of Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Goals and Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

II DESIGN SPECIFICATIONS AND STANDARDS 3


2.1 Design Specifications and Standards . . . . . . . . . . . . . . . . . . . . . 3
2.2 Hardware Requirements for Establishing Zigbee Communication . . . . 3
2.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Realistic constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

III PROJECT MANAGEMENT 5


3.1 Budget and Cost Management Plan . . . . . . . . . . . . . . . . . . . . . 5
3.2 Project Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

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

1 Model of Zigbee Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . 15


2 Three types of device in Zigbee System . . . . . . . . . . . . . . . . . . . 17
3 Zigbee Start topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4 Zigbee Mesh topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5 Zigbee Cluster Tree topology . . . . . . . . . . . . . . . . . . . . . . . . . 20
6 Connection Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7 Router 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
8 Router 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
9 Coordinator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
10 XCTU interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
11 Select the port to scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
12 Default setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
13 Add selected devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
14 XBee module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
15 Update the firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
16 Pan ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
17 Destination Address. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
18 Source Address. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
19 Connection Flow Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 31
20 Push button Flow Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 32
21 Preferences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
22 Confirm preferences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
23 Connect ESP32 with Arduino. . . . . . . . . . . . . . . . . . . . . . . . . 38
24 Create a new flutter project. . . . . . . . . . . . . . . . . . . . . . . . . . 41
25 Install Firebase to flutter app. . . . . . . . . . . . . . . . . . . . . . . . . . 41
26 Router 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
27 Router 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
28 Coordinator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
29 Android User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

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

In today’s telecommunications network, people are managing, exchanging, communi-


cating debating, doing politics, buying, selling, and experimenting - that is, doing all
kinds of things The model works in a way that only an IoT can do. Telecommunica-
tion creates a cross-chain connecting people across the planet and is expanded endlessly
wide, full of promise and hope. However, a small bandwidth still has a lot of challenges
to reach its potential. Scientists over the world are thinking about a solution that applies
higher bandwidths, but this solution faces many issues because electronic technology is
still under development. So, a crucial method was given that used a unique frequency.
Therefore, an urgent solution is given to use the same frequency channel, although there
are still many problems that arise, for example, there may be many variations between
devices of the same frequency, or other problems. One of the new tools currently in use
in network communication has achieved the effect of ZigBee technology.

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.

1.2 Structure Of Report

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.

1.3 Goals and Objectives

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

This chapter includes: Design Specifications, Standards, and Constraints in my project

2.1 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.

2.2 Hardware Requirements for Establishing Zigbee Communication

Hardware Description

NodeMCU-32S CH340 Ai-Thinker [4] Nodemcu-32S is developed on the central micro-


controller ESP32 SOC with the latest wifi, ca-
ble, and ARM architecture today, Kit with hard-
ware design, firmware, And the same uses as Kit
Nodemcu ESP8266, with the advantage of easy
use, full legs, integrated charging circuits and
UART CH340, suitable for studies, applications on
wifi, cable, iodine, and control and collect data
over the network.

Arduino Board [1] Arduino senses the environment by receiving in-


puts from many sensors, and affects its surround-
ings by controlling lights, motors, and other actu-
ators.

Zigbee Zigbee is a standards-based wireless mesh net-


work that is widely used in asset monitoring,
smart cities, smart lighting, and building automa-
tion.

Table 1: Hardware devices.

3
2.3 Software

Software Description

XCTU A free, cross-platform program that works with


Windows, macOS, and Linux is called XCTU.
Simple wireless network configuration and archi-
tecture using the graphical network view.
A straightforward programming tool called API
Frame Builder is used to create XBee API frames
rapidly.
Users may browse and view firmware release
notes using the Firmware Release Notes Viewer.

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.

Flutter [5] The open-source Flutter UI software development


kit was created by Google. It is used to develop
cross-platform software from a single codebase
for Google Fuchsia, Android, iOS, Linux, macOS,
Windows, and the web.

Table 2: Software devices.

2.4 Realistic constraints

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.

3.1 Budget and Cost Management Plan

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.

Ingredient Quantity Cost (Unit: VND)

Zigbee 3 2.500.000

Arduino 2 230.000

Esp32s 1 195.000

Total 6 2.950.000

Table 3: Budget plan.

3.2 Project Schedule

Working Property Time

Find and investigate the related documents about 07/09/2022 – 14/09/2022 - 1 week
Zigbee.

Arduino 2

Table 4: Project Schedule

5
IV LITERATURE REVIEW

This chapter includes the Smart home’s definition and provides detailed information
about Zigbee technology.

4.1 Smart Home

4.1.1 Smart home definition

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.

Typically, a fully intelligent home has the following attributes:

• A home theatre is a multimedia distribution system.

• Adjust the drapes, shades, and lighting.

• Monitoring and managing the environment (temperature, humidity, etc.).

• Have inter-room communication capabilities.

• Keep an eye on and manage security cameras.

• Remote control and observation.

6
4.1.2 The advantage of the smart home

Automated, intelligent, and technologically advanced homes encourage people to take


their time throughout daily chores. In other words, this is a system that enables owners
to simply manage the entire building while also enjoying life’s conveniences. No matter
where we are, we can control everything with a single remote. By engaging in very
personal acts, like reclining on the bed to open the gate, we can envision the impact that
a smart house has. The lights in the room, the kitchen, the water heater. . . will work
at the scheduled time; the entire lighting system will automatically turn off after being
not needed; control the temperature difference between the outside and the inside of the
house; and many other utilities. There won’t be any more falling due to not being able
to see the road because the stairs will light up automatically when there are people.

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

4.2.1 WPAN definition

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.

4.2.2 Zigbee definition

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.

Zigbee versions have been released since then:

• 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.

• In December 2006, Zigbee 2006 was born.

• In 2007, Zigbee PRO was born with more outstanding features.

4.2.4 Comparison between Zigbee, Bluetooth, and Wifi.

Zigbee™ Wifi Bluetooth

Frequencies 868M Hz, 915M Hz 2.4GHz 2.4 GHz, 5 GHz


2.4Ghz

Data rate 20-250Kbps 1-100 Mbps 1-3 Mbps

Distance 10-100m 30-100m 2-10m

Table 5: Comparison between Zigbee, Bluetooth, and Wifi.

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

• Simple to use, reasonable price, energy saving

– The device is manufactured to be suitable for both self-installers and home


builders’ professional system integration. Optimize energy, and reduce power
consumption when in use.

– 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.

– Automatic or semi-automatic control feature: Liberation of human labor. An


Internet connection allows remote control. Self-install, easy installation.

• 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

– Integrated control and monitoring of the electrical modules of the house as


well as security systems, and access control.

– 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.

Remote control: Offers a cutting-edge international standard and is simple to op-


erate with a remote control that is non-line-of-sight, two-way, and has a larger operating
range. It is made to work with a variety of set-top boxes, home theater systems, and au-
dio gear.

Consumers’ remote controls are made available on gadgets through Zigbee.

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.

– Multiple systems are automatically controlled to provide flexibility and secu-


rity.

• Preservation

– Reduce energy expenses by managing the HVAC system optimally.

– Utilize real usage to evenly distribute utility expenses.

• Flexibility

– Lighting should be quickly adjusted to produce space-adaptive work.

• Safety

– Network and data integration t multi-way access control points.

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.

Figure 1: Model of Zigbee Protocol

4.5.1 Physical Layer

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.

Receiver activation or deactivation, power detection, channel selection, line index-


ing, channel release, and the receipt and transmission of data packets across the trans-
mission medium are a few examples of physical layer properties.

The IEEE 802.15.4 standard specifies three different frequency bands:

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

• LQI (Link Quality Indicator)


Together with the ED index, this indicator assesses the SNR and describes the re-
ceived packet quality. The network layer and the processing application layer are
each given their value.

4.6 Equipment Classification

First, let’s learn the terms:

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:

Figure 2: Three types of device in Zigbee System

4.6.1 Coordinator (ZC)

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.

4.6.2 Router (ZR)

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.

4.6.3 Zigbee End Device (ZED)

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.

4.7.1 Star topology (Point to Point)

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.

Figure 3: Zigbee Start topology

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.

Figure 4: Zigbee Mesh topology

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.

Figure 5: Zigbee Cluster Tree topology

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]

5.1 Model of Zigbee network

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.

Figure 6: Connection Model

21
5.2 Hardware Design

5.2.1 Interfacing XBee with Arduino (Router 1)

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]

Step 1: Launch the XCTU program, then select ”Discover boards.”

Figure 10: XCTU interface

25
Step 2: Selecting the COM port that the XBee module is connected to will prompt
you to click ”Next.”

Figure 11: Select the port to scan

Step 3: Click ”Finish” while keeping the default settings in place.

Figure 12: Default setting

26
Step 4: At this point, select ”Add Selected Devices” from the pop-up box.

Figure 13: Add selected devices

Step 5: Now the left side of the window will display the XBee module. By clicking
it, you may adjust the user interface.

Figure 14: XBee module

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.

Figure 15: Update the firmware

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.

Figure 16: Pan ID

28
Step 8: The destination address might be any 4 digits. The other XBee module’s
Source Address must also be the same number.

Figure 17: Destination Address.

Step 9: The Source Address might be any 4 digits. For the second XBee module, the
Destination Address must be the same number.

Figure 18: Source Address.

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.

Destination address Source address Pan ID


Coordinator 2222 1111 1999
End Device 1111 2222 1999

Table 6: Destination and source address.

30
5.4 Flow Diagrams

Figure 19: Connection Flow Diagram

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

2 const int led = 13;

3 # d e f i n e TURN OFF BED ROOM ’ 4 ’

4 # d e f i n e TURN ON BED ROOM ’ 5 ’

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 ) ;

Initializing the button pin to read input.

1 pinMode ( p u s h B u t t o n , INPUT PULLUP ) ;

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 ( ) ;

3 i f ( r e c e i v e d == TURN ON BED ROOM ) {

4 d i g i t a l W r i t e ( l e d , HIGH ) ;

5 toggle = false ;

6 }

7 e l s e i f ( r e c e i v e d == TURN OFF BED ROOM ) {

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” ) ;

7 XBee . w r i t e ( TURN ON BED ROOM ) ;

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 ” ) ;

16 XBee . w r i t e ( TURN OFF BED ROOM ) ;

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

The code is the same as router 1.

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

3 const int led = 13;

4 boolean toggle = f a l s e ;

5 # d e f i n e TURN OFF BATH ROOM ’ 2 ’

6 # d e f i n e TURN ON BATH ROOM ’ 3 ’

8 # d e f i n e TURN OFF BED ROOM ’ 4 ’

9 # d e f i n e TURN ON BED ROOM ’ 5 ’

10

11 void setup ( )

12 {

13 / / p u t your s e t u p c o d e her e , t o run once :

14 S e r i a l . begin ( 9 6 0 0 ) ;

15 XBee . b e g i n ( 9 6 0 0 ) ;

16 pinMode ( p u s h B u t t o n , INPUT PULLUP ) ;

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 ) ;

27 XBee . w r i t e ( TURN ON BATH ROOM ) ;

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) ;

36 XBee . w r i t e ( TURN OFF BATH ROOM ) ;

35
37 delay (1000) ;

38 }

39 / / p u t your main c o d e her e , t o run r e p e a t e d l y :

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 ( ) ;

43 i f ( r e c e i v e d == TURN OFF BATH ROOM )

44 {

45 d i g i t a l W r i t e ( l e d , LOW) ;

46 toggle = true ;

47 }

48 e l s e i f ( r e c e i v e d == TURN ON BATH ROOM )

49 {

50 d i g i t a l W r i t e ( l e d , HIGH ) ;

51 toggle = false ;

52 }

53 e l s e i f ( r e c e i v e d == TURN OFF BED ROOM | | r e c e i v e d == TURN ON BED ROOM )

54 {

55 XBee . w r i t e ( r e c e i v e d ) ;

56 }

57 }

58 }

5.7 ZigBee (Router 2) Communication Program for ESP32

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 1: Open Arduino and click to file − > preferences

Step 2: Add 2 links to the preference inputs and click OK to confirm

Step 3: Then click Tool − > Board − > ESP32 Arduino − > ESP32 Dev Module

36
Figure 21: Preferences.

Figure 22: Confirm preferences.

Step 4: Go to manage library => Install FirebaseESP32.h, Wifi.h.


Step 5: Create project on Firebase => Firebase console => Create Project => Copy
the Firebase host and Firebase auth so that ESP32 can access to firebase real-time data.

37
Figure 23: Connect ESP32 with Arduino.

Include all libraries belonging to ESP32 and the SoftwareSerial.h

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

Define firebase host and firebase auth.

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.

1 void streamCallback ( MultiPathStreamData stream )

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 ] ) ) ;

11 S e r i a l . p r i n t l n ( ” path : ” + stream . dataPath + ” , type : ” + stream . type + ” ,

value : ” + stream . value ) ;

12 handlePin ( stream . dataPath , stream . value ) ;

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.

• PASSWORD: Password of the wifi.


1 WiFi . b e g i n ( WIFI SSID , WIFI PASSWORD ) ;

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 ;

Initialize the library with the Firebase authen and config.

1 F i r e b a s e . b e g i n (& c o n f i g , &a u t h ) ;

Set AP reconnection in setup()

1 Firebase . reconnectWiFi ( true ) ;

Firebase.beginStream(firebaseData, path) is to subscribe to the data changes at a defined


node. If something is wrong, print the specific error on the serial monitor. Otherwise,
announce user that ESP32 is connected to Firebase.

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.

Figure 24: Create a new flutter project.

After that, create 3 files which are customDatabase, navigationDrawer, and custom-
Data. Create a navigation drawer for the app.

Figure 25: Install Firebase to flutter app.

41
VI EXPECTED RESULTS

6.1 Router 1

Figure 26: Router 1

6.2 Router 2

Figure 27: Router 2

42
6.3 Coordinator

Figure 28: Coordinator

6.4 Android User Interface

Figure 29: Android User Interface

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-

toring and Controlling System using XBee Network”. In: (2019).

[3] Laurence Moroney. “The firebase realtime database”. In: The Definitive Guide to Firebase. Springer,

2017, pp. 51–71.

[4] Yogendra Singh Parihar et al. “Internet of things and nodemcu”. In: Journal of Emerging Technologies

and Innovative Research 6.6 (2019), p. 1085.

[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-

nications. Elsevier, 2012.

44

You might also like