HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY AND EDUCATION FACULTY FOR HIGH QUALITY TRAINING GRADUATION PROJECT PHAN TẤN DŨNG Student ID: 18119011 NGUYỄN VĂN ĐẠO Student ID: 1811901
Trang 1
DESIGN AND IMPLEMENTATION AN IOT APPLICATION PLATFORM FOR SALANGANE
HOUSE MANAGEMENT SYSTEM
LECTURER: TRUONG QUANG PHUC, M.Eng STUDENT: PHAN TAN DUNG
NGUYEN VAN DAO
S K L 0 1 0 5 9 2
Ho Chi Minh City, December 2022 GRADUATION PROJECT COMPUTER ENGINEERING TECHNOLOGY
Trang 2HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY AND
EDUCATION FACULTY FOR HIGH QUALITY TRAINING
GRADUATION PROJECT
PHAN TẤN DŨNG
Student ID: 18119011 NGUYỄN VĂN ĐẠO
Student ID: 18119013
Ho Chi Minh City, December 2022
DESIGN AND IMPLEMENTATION AN IOT
APPLICATION PLATFORM FOR SALANGANE
HOUSE MANAGEMENT SYSTEM
Major: COMPUTER ENGINEERING TECHNOLOGY Advisor: TRƯƠNG QUANG PHÚC, M.Eng
Trang 3HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY AND
EDUCATION FACULTY FOR HIGH QUALITY TRAINING
GRADUATION PROJECT
DESIGN AND IMPLEMENTATION AN IOT
APPLICATION PLATFORM FOR SALANGANE
HOUSE MANAGEMENT SYSTEM
PHAN TẤN DŨNG
Student ID: 18119011 NGUYỄN VĂN ĐẠO
Student ID: 18119013 Major: COMPUTER ENGINEERING TECHNOLOGY Advisor: TRƯƠNG QUANG PHÚC, M.Eng
Ho Chi Minh City, December 2022
Trang 4THE SOCIALIST REPUBLIC OF VIETNAM
Independence – Freedom– Happiness
-
Ho Chi Minh City, December 17, 2022
GRADUATION PROJECT ASSIGNMENT
Date of assignment: _ Date of submission: _
1 Project title: Design and Implementation an IoT Application Platform for Salangane House Management System
2 Initial materials provided by the advisor: _
3 Content of the project: _
4 Final product:
CHAIR OF THE PROGRAM
(Sign with full name)
ADVISOR
(Sign with full name)
Trương Quang Phúc
Trang 5THE SOCIALIST REPUBLIC OF VIETNAM
Independence – Freedom– Happiness
-
Ho Chi Minh City, December 17, 2022
ADVISOR’S EVALUATION SHEET
Student name: Nguyễn Văn Đạo Student ID: 18119013
Major: Computer Engineering Technology
Project title: Design and Implementation an IoT Application Platform for Salangane House
2 Strengths:
3 Weaknesses:
4 Approval for oral defense? (Approved or denied)
Approved
5 Overall evaluation: (Excellent, Good, Fair, Poor)
Good
6 Mark: 9.0 (in words: )
Ho Chi Minh City, Dec 17, 2022
ADVISOR
(Sign with full name)
Trương Quang Phúc
Trang 6Số hiệu: BM16/QT-PKHCN-QHQT-NCKH/02 Lần soát xét: 02 Ngày hiệu lực: 01/4/2020 Trang: 1/1
HO CHI MINH CITY OF UNIVERSITY OF
TECHNOLOGY AND EDUCATION
FACULTY OF HIGH QUALITY TRAINING
SOCIALIST REPUBLIC OF VIETNAM Independence – Freedom – Happiness
Ho Chi Minh City, January 10, 2023
MODIFYING EXPLANATION OF THE GRADUATION PROJECT
MAJOR: COMPUTER TECHNOLOGY ENGINEERING
1 Project title: Design and Implementation an IoT Application Platform for
Salangane House Management System
3 Advisor: Trương Quang Phúc, M Eng
5 Modifying explanation of the graduation project:
specifications in details
“System requirement” is in chapter 3
“Specifications” in chapter 3
2
Authors should show the parameter
values which are selected for
design What are requirements of
system?
Parameter values that are selected for design are modified and added in
“SPECIFICATIONS” (chapter 3), and
“System requirement” is in chapter 3
3
Authors should consider interaction
of parameters each other The
variation in the temperature can
affect humidity for example
The temperature and humidity parameters are considered for auto mode that is shown
in “Central processing unit block” in chapter 3
Head of Department
(Sign with full name)
Advisor (Sign with full name)
Trương Quang Phúc
Students
(Sign with full name)
Trang 7THE SOCIALIST REPUBLIC OF VIETNAM
Independence – Freedom– Happiness
-
Ho Chi Minh City, December 17, 2022 PRE-DEFENSE EVALUATION SHEET Student name: Phan Tấn Dũng Student ID: 18119011 Student name: Nguyễn Văn Đạo Student ID: 18119013 Major: Computer Engineering Technology Project title: Design and Implementation an IoT Application Platform for Salangane House Management System Name of Reviewer:
EVALUATION 1 Content and workload of the project
2 Strengths:
3 Weaknesses:
4 Approval for oral defense? (Approved or denied)
5 Overall evaluation: (Excellent, Good, Fair, Poor)
6 Mark:……….(in words: )
Ho Chi Minh City, month day, year
REVIEWER
(Sign with full name)
Trang 8THE SOCIALIST REPUBLIC OF VIETNAM
Independence – Freedom– Happiness
-EVALUATION SHEET OF DEFENSE COMMITTEE MEMBER Student name: Phan Tấn Dũng Student ID: 18119011 Student name: Nguyễn Văn Đạo Student ID: 18119013 Major: Computer Engineering Technology Project title: Design and Implementation an IoT Application Platform for Salangane House Management System Name of Defense Committee Member:
EVALUATION 1 Content and workload of the project
2 Strengths:
3 Weaknesses:
4 Overall evaluation: (Excellent, Good, Fair, Poor)
5 Mark:……….(in words: )
Ho Chi Minh City, …, …, …
COMMITTEE MEMBER
(Sign with full name)
Trang 9i
SUPERVISOR APPROVAL
………
………
………
………
………
………
………
………
………
………
………
……….………
………
………
………
………
………
………
………
………
………
………
……….………
………
………
………
………
………
………
………
………
………
………
………….………
………
………
………
………
………
………
………
………
………
Trang 10ii
ACKNOWLEDGMENTS
We would like to thank all of the teachers in Faculty for High Quality Training who instructed the valuable knowledge in our major for my team We appreciate this knowledge to complete our graduation thesis
We would like to express our very great appreciation to TRUONG QUANG PHUC, M.Eng for his valuable advice during the planning, designing, and finishing of this project His guidance helped my team to be able to enhance the idea and develop this project
We would also like to extend our thanks to all of the great classmates in class 18119CLA who gave many essential comments to contribute to this project
Finally, although we complete and achieve some goals in this project, there are also some inevitable defects in this project We hope teachers and classmates sympathize with the problems We wish to receive advices from teachers and classmates
Thank you very much!
Trang 11iii
ABSTRACT
In this project, we built an IoT Platform using Wi-Fi communication protocol to support users to be able to observe some environmental parameters such as temperature value, humidity value, light value and operation states of some devices such as a speaker, fans, a light bulb, a humidifier in the salangane house This system will collect environmental data by reading data from sensors The environment data will be stored on Firebase and then displayed on the website and mobile application Users can supervise and control the devices remotely In addition, users can also observe warning of environmental parameters through the website or the mobile application
The system is built with four parts Firstly, we have to design a controlling box using ESP32 to communicate with the temperature/humidity sensor and light sensor for collecting the environmental parameters This box with ESP32 also controls the devices in this system Secondly, we build a database by using the Realtime Database
of Google Firebase to store device states and the environmental parameters that are collected by the controlling box Thirdly, the purpose of building the website is to help the user to be able to control the devices, observe some knowledge about Salangane and supervise environmental parameters, and warnings of these parameters Fourth, a mobile application is built to control the devices, supervise environmental parameters, and warnings of these parameters
Trang 12iv
TABLE OF CONTENTS
LIST OF FIGURES VII
LIST OF TABLES X LIST OF ABBREVIATIONS XI
CHAPTER 1 OVERVIEW 1
1.1 INTRODUCTION 1
1.2 OBJECTIVES 2
1.3 LIMITATION 2
1.4 RESEARCH CONTENT 3
1.5 OUTLINE 3
CHAPTER 2 BACKGROUND 5
2.1 TECHNICAL INFORMATION ABOUT SALANGANES FARMING 5
2.1.1 SALANGANES BEHAVIOR 5
2.1.2 SALANGANES GROWING CONDITIONS 5
2.2 THEORETICAL BASIS 6
2.2.1 PWM TECHNIQUE (PULSE WIDTH MODULATION) 6
2.2.2 ONE-WIRE COMMUNICATION PROTOCOL 8
2.2.3 I2C COMMUNICATION PROTOCOL 9
2.3 PROGRAMMING TOOL 13
2.3.1 PROTEUS 13
2.3.2 ARDUINO IDE 13
2.3.3 VISUAL STUDIO CODE 13
2.4 THINGSPEAK 14
2.5 FIREBASE 14
2.6 OVERVIEW OF HTML, CSS, JAVASCRIPT 15
2.6.1 HTML 15
2.6.2 CSS 15
2.6.3 JavaScript 17
2.7 CONTROLLING SYSTEM ON SMARTPHONE APPLICATION 17
2.7.1 APP INVENTOR 17
2.8 HARDWARE 18
2.8.1 ESP32-WROOM-32 MICROCONTROLLER 18
2.8.2 DUAL FULL BRIDGE DRIVER – L298 19
Trang 13v
2.8.3 RELAY MODULE 20
2.8.4 I 2 C MODULE 20
2.8.5 LCD 20x4 21
2.8.6 SPEAKER MODULE 22
2.8.7 LIGHT BULB 23
2.8.8 HUMIDIFIER 23
2.8.9 MOTOR 24
CHAPTER 3 DESIGN AND IMPLEMENTATION 25
3.1 CUSTOMER NEEDS 25
3.2 SPECIFICATIONS 25
3.2.1 FUNCTIONS 25
3.2.2 SENSOR PROPERTIES 25
3.3 SYSTEM REQUIREMENTS 27
3.4 BLOCK DIAGRAM 27
3.5 DETAIL HARDWARE DESIGNS 29
3.5.1 Sensor Block 29
3.5.2 Buttons Block 31
3.3.3 Display Block 32
3.3.4 Actuator Block 33
3.3.5 Central processing unit block 38
3.5.3 The power supply block 45
3.6 DETAIL SOFTWARE DESIGNS 46
3.6.1 MOBILE APPLICATION BLOCK 46
3.6.2 DESIGN THE WEBSITE 49
CHAPTER 4 RESULTS 52
4.1 HARDWARE IMPLEMENTATION 52
4.2 SOFTWARE IMPLEMENTATION 54
4.2.1 WEBSITE INTERFACE 54
4.2.2 ANDROID MOBILE APPLICATION 61
4.3 SYSTEM OPERATION 62
CHAPTER 5 CONCLUSIONS AND FUTURE WORK 71
5.1 CONCLUSIONS 71
5.1.1 Advantages 71
5.1.2 Drawbacks 72
Trang 14vi
5.2 FUTURE WORK 72
APPENDIX 73 REFERENCES 77
Trang 15vii
LIST OF FIGURES
Figure 2.1: PWM technique 6
Figure 2.2: Duty cycle of PWM technique 7
Figure 2.3: Average output voltage of PWM technique 7
Figure 2.4: One-wire communication standard [7] 8
Figure 2.5: Bus operation of one-wire standard [8] 8
Figure 2.6: I2C communication structure [10] 9
Figure 2.7: I2C message frame 10
Figure 2.8: Devices in I2C communication protocol 10
Figure 2.9: Start condition in I2C communication protocol 11
Figure 2.10: Transmission in I2C communication protocol [10] 12
Figure 2.11: Stop condition in I2C communication protocol 12
Figure 2.12: Firebase 14
Figure 2.13: App Inventor 18
Figure 2.14: NodeMCU ESP32 18
Figure 2.15: Pinout of NodeMCU ESP32 19
Figure 2.16: L298 motor driver 19
Figure 2.17: Relay module 1 channel 5V 20
Figure 2.18: I2C module 21
Figure 2.19: LCD 20x4 21
Figure 2.20: Module GM4563 22
Figure 2.21: Light bulb 23
Figure 2.22: Humidifier 23
Figure 2.23: Motor 12V 24
Figure 3.1: DHT11 sensor 25
Figure 3.2: Light sensor 26
Figure 3.3: Block diagram of Salagane house management system 28
Figure 3.4: The schematic for DHT11 29
Figure 3.5: The schematic for connecting light sensor 30
Trang 16viii
Figure 3.6: Schematic for buttons block 31
Figure 3.7: Schematic for connection between buttons and ESP32 32
Figure 3.8: Connection between MCU and I2C LCD 20x4 33
Figure 3.9: The schematic for H-bridge circuit 33
Figure 3.10: The schematic for L298 module and motors 34
Figure 3.11: Operation of relay module 35
Figure 3.12: Schematic for controlling light bulb 36
Figure 3.13: Schematic for controlling humidifier 37
Figure 3.14: Schematic for controlling speaker 37
Figure 3.15: Schematic for ESP32 38
Figure 3.16: Main programming flowchart 40
Figure 3.17: Programming flowchart for manual mode 41
Figure 3.18: Programming flowchart for automatic mode 44
Figure 3.19: Flowchart for mobile application 47
Figure 3.20: Design interface on App Inventor 48
Figure 3.21: Connecting GG Firebase on App Inventor 48
Figure 3.22: Blocks interface on App Inventor 49
Figure 3.23: Contents of Website interface 49
Figure 3.24: Flowchart of Manual mode in website 50
Figure 4.1: Top-down view of the project 52
Figure 4.2: Outer view of controlling box (UP-DOWN view) 53
Figure 4.3: Inner view of hardware implementation (UP-DOWN view) 53
Figure 4.4: Home Page 54
Figure 4.5: Information Page 55
Figure 4.6: Basic knowledge of information page Interface 55
Figure 4.7: Some product prices of information page Interface 56
Figure 4.8: Technique for taking care of Salangane 56
Figure 4.9: Environmental Parameters Page 57
Figure 4.10: Temperature parameter on the Website 58
Trang 17ix
Figure 4.11: Humidity parameter on the Website 58
Figure 4.12: Light parameter on the Website 59
Figure 4.13: Manual Mode Page with devices off 59
Figure 4.14: Manual Mode Page with devices on 60
Figure 4.15: Auto Mode Page 60
Figure 4.16: Android mobile application 61
Figure 4.17 : Controlling interface of mobile application 62
Figure 4.18: Result of controlling box, mobile application and website 63
Figure 4.19: Updating environmental parameters to Firebase 63
Figure 4.20: Result of displaying environmental status 64
Figure 4.21: Operation of manual mode 64
Figure 4.22: Operation of controlling light bulb 65
Figure 4.23: Operation of controlling humidifier 65
Figure 4.24: Operation of controlling speaker 66
Figure 4.25: Operation of controlling fans 66
Figure 4.26: Operation of auto mode 67
Figure 4.27: Auto mode when temperature and humidity are satisfied 67
Figure 4.28: Auto mode when temperature is low and humidity is satisfied 68
Figure 4.29: Auto mode when temperature and humidity are low 68
Figure 4.30: Auto mode when temperature is high and humidity is low 69
Figure 4.31: Auto mode when temperature is low and humidity is high 69
Trang 18x
LIST OF TABLES
Table 2.1: HTML tags 15
Table 3.1: Connection between DHT11 and ESP32 29
Table 3.2: Features of some light sensors 30
Table 3.3: Connection between buttons and ESP32 31
Table 3.4: Connection between I2C module and ESP32 32
Table 3.5: Connection between L298 module and ESP32 34
Table 3.6: Connection diagram of ESP32 39
Table 3.7: Calculated power consumption of each device 46
Trang 19xi
LIST OF ABBREVIATIONS
Trang 20Sarangani’s Nest is regarded as a valuable food, having significant nutritional content and outstanding health benefits Because a bird's nest includes essential nutrients that the body cannot synthesize on its own, the addition of a bird's nest is
a way to help the body be healthier Furthermore, the bird's nest is a source of nutritious food that may assist the elderly in battle aging and illnesses, health restoration, faster metabolism, and immune strengthening, lower blood pressure and improve cardiac function [1] Therefore, bird’s nest farming is one of the professions that bring high economic efficiency to Vietnam, our nation has various potentials and benefits for the growth of salangane farming due to the advantage of geography However, exploiting a bird's nest in the wild takes a lot of time, effort, and a very limited amount, which does not match the demands of customers today [2] As a result, the model of raising salangane in the house was developed to improve the quality and the number of products as well as meet the market's need for this nutritious food source while also providing a high income for farmers However, the raising of salangane can bring such high economic value, it will face many difficulties and challenges People should be knowledgeable in all aspects of bird's nest farming, such as installing devices to entice salangane to nest,
Trang 212
caring for swiftlets to avoid diseases, managing equipment, and harvesting nests [3] Furthermore, the salangane housing must guarantee that the direction of the swiftlets inside and outside the house, as well as environmental parameters such as light, temperature, and humidity, are consistent in order to maintain the salangane for an extended period of time Another important factor is that the investment cost for the nest is very important to ensure that people's equipment can work well to ensure the health of the salangane Nowadays, in rural areas few farming households apply monitoring and remote-control devices to stabilize parameters such as temperature, humidity, and light Most people only use their hands to adjust these parameters based on their personal experiences and do not know the exact parameters, which results in the salangane not returning to the nest or death due to disease [4]
From the above issues, our group chose the topic “Design and
implementation an IoT application platform for the Salangane house management system” The system will collect and help the users to be able to
monitor changes in the environmental conditions of Salangane house in order to adjust the equipment, ensure a stable living environment and improve product quality Furthermore, the system will enable users to monitor their Salangane house remotely
1.2 OBJECTIVES
Design a Salangane house management system that includes functions such as measuring temperature, humidity, and light intensity and display warnings about environmental parameters for users to control directly by using website and mobile application installed on their Android phones
Building the system that has 2 controlling modes including automatic control mode and manual control mode With automatic mode, the system can base on sensor parameters to control the devices to meet the ideal living conditions of the Salangane With manual mode, users can control devices through physical buttons, buttons on the website or their Android mobile application
Design a website by using HTML and CSS Building an Android mobile application to display, monitor sensor data, provide warnings to the user and control the hardware devices
Trang 223
• The goal of our group's project is only to build a collection system that collects information about temperature, humidity, light, and gives several warnings about parameters, allowing users to monitor environmental parameters and control devices in their bird's nest via the physical buttons, mobile application and website
• If the actuators or sensors are broken down, the system cannot warn users of this problem
• This project is applied on the small model and this project cannot be applied in real life currently
• This system can be applied on an only specific area
1.4 RESEARCH CONTENT
These are descriptions of the implemented contents:
• Content 1: Refer to documents and survey suitable environmental parameters for bird nest farming
• Content 2: Calculate and design block diagrams to select devices
• Content 3: Research about ESP32 microcontroller, sensors such as temperature, humidity, light and devices based on block diagrams
• Content 4: Find out the ESP32 module's protocol for communicating with the sensors and the website
• Content 5: Design and simulation system on proteus
• Content 6: Write programs for microcontroller
• Content 7: Design of website and application interface
• Content 8: Implement the printed circuit board and connect all modules
• Content 9: Test and evaluate the system after completion
• Content 10: Writing a report
• Content 11: Prepare slides for presentation
1.5 OUTLINE
This report will be divided into five chapters below:
Chapter 1 OVEREVIEW: This chapter gives a brief introduction to the system
we research
Chapter 2 BACKGROUND: This chapter introduces the theoretical basis of the components, technique and software We will give the brief introduction about the hardware using to build the system
Trang 234
Chapter 3 DESIGN AND IMPLEMENTATION: This part is about the block diagram of the system and system requirements, the details of each component and how they can be designed in this project
Chapter 4 RESULTS: Show the results obtained
Chapter 5 CONCLUSIONS AND FUTURE WORK: Overall evaluation of the model, and suggestions for things that can be improved in the future
Trang 24do not eat food like poultry, they do not eat bran and do not eat food provided by humans as well They only eat small insects (size 0.01–0.72g) such as bees, termites, damselflies or locusts Salanganes usually hunt at altitudes ranging from 0 to 50 meters, they get up early every day to catch insects The proportion of feed ingredients varies from month to month and year to year, changing the proportion of insect groups flying in the air They can fly up to 300 kilometers in search of prey and feed for 15 hours a day However, they usually only feed about 25 kilometers away from the nest.Salanganes begin feeding at sunrise, depending on the season, they will leave the nest
the nest between 18:00 pm and 18:30 pm, returning earlier in the winter around 17:30
pm [5] Birds that do not raise fledglings leave the nest to look for food from morning until evening and return to the nest to rest Pairs that are incubating eggs take turns incubating eggs For couples who are raising chicks, the number of times the parents return to the nest more or less depends on how old of fledglings are (large birds require more food during the day)
2.1.2 SALANGANES GROWING CONDITIONS
higher than the houses surrounding the house next door, in the rural house has good conditions for birds to fly and a source of food to eat more The Salangane house's design is based on the results of a survey of the area and intended location When designing and building the Salangane house, it is critical to consider the sub-climate of the chosen area for building a bird's nest house
Trang 25One required element to keep Salanganes indoors is sound, there are many different types of sounds used to attract Salanganes today, but in general, there are 3 types: the type of external language used to attract Salanganes to gather, the sucking sound used to attract birds into the house, and the clear sound used to fool the swiftlets into thinking that this house has many Salanganes to live Bird's nest speakers have a sound frequency of about 1-16 kHz, usually between 2-5 kHz, this is the frequency that the human ear can hear [6]
Additionally, use odorant solutions to make swiftlets believe that this house is full of swiftlets There are numerous odor solutions on the market today, including KW3, PW-Cair, PW Concentrate, Love Potion… or real bird droppings Choose wisely based on the design and conditions
2.2 THEORETICAL BASIS
2.2.1 PWM TECHNIQUE (PULSE WIDTH MODULATION)
PWM is a signal that is generated by a digital integrated circuit The signal of the PWM are square clock pulses with the high logic level at high voltage level and the low logic level at low voltage level (GND or 0V) The signal is high or low at any time To be easy for understanding, we will consider 5V PWM (5V is high level and 0V is low level):
Figure 2.1: PWM technique
Trang 267
In the figure 2.1, the PWM signal has some different duty cycle, this duty cycle will decide the average output voltage that decides the speed of the motor We need to consider about frequency and period of the signal in order to calculate the duty cycle:
Figure 2.2: Duty cycle of PWM technique
If the signal is at high level, this period of time is called ON time If the signal is
at low level, this period of time is called OFF time In the figure 2.2 above, if we focus
on a period (ON time + OFF time), ON time period is a haft of the period Therefore,
cycle is 100% that means the signal is high every time When duty cycle is calculated,
𝑝𝑒𝑎𝑘 𝑣𝑜𝑙𝑡𝑎𝑔𝑒 × 𝐷𝑢𝑡𝑦 𝑐𝑦𝑐𝑙𝑒:
Figure 2.3: Average output voltage of PWM technique
For example, the duty cycle of the signal is 75%, so the average output voltage is 3.75V because the average voltage = 5V x 75% = 3.75V In the similar way, the average output voltages of 0%, 25%, 50% and 100% duty cycle are 0V, 1.25V, 2.5V and 5V respectively
Trang 278
2.2.2 ONE-WIRE COMMUNICATION PROTOCOL
One–wire communication protocol is designed by Dallas Semiconductor Corp This communication is a serial communication and it uses a wire to operate in a system:
Figure 2.4: One-wire communication standard [7]
To implement this communication, we need to have a master device and slave devices because this communication protocol needs only a Master to transmit or receive data with other slaves
There are four operation modes in this communication including reset mode, writing 0-bit mode, writing 1-bit mode, and reading bit mode:
Figure 2.5: Bus operation of one-wire standard [8]
Firstly, we consider on Write 1-bit operation, this operation helps the master can send a bit 1 to the slave devices In this operation, the master pulls the bus down to the ground in 6 us, and then the bus is released to the high voltage level in 64 us Secondly, if the master wants to send a bit 0, this device will drive the bus down in 60
us Then, the pull-up resistor will pull the bus up in 10 us Thirdly, read-bit operation helps the master to be able to read a bit from the slaves To read a bit, the master has to
Trang 289
keep the bus at low voltage in 6 us, then, Finally, the reset operation is used to reset the master and slaves To reset, the master will pull the bus down during a period of about 480us and then this bus is pull up by the register After the period of pulling up, the mater start sampling If slave pulls the bus to low voltage level, master will know that slave still live and data exchange continues Otherwise, if the bus is still at high level, the master will understand that there are no slave device and stop the process
2.2.3 I2C COMMUNICATION PROTOCOL
I2C (Inter-Integrated Circuit) is a synchronous serial communication protocol This communication protocol is invented and developed by Phillips Semiconductor I2C is used to transmit and receive data between ICs by using two wires SCL and SDA Data bits will be transmitted bit by bit depending on time periods set by a synchronous signal This protocol is usually used by many peripherals such as microcontrollers, sensors, EEPROM, … to communicate with other peripherals in a system
In order to implement the I2C communication protocol, we need a Master and Slaves or a multi-master and a multi-slave environment There are two main signal lines in this communication protocol:
- SCL (Serial Clock Line): this line is used to transmit clock pulses that are generated by Masters
- SDA (Serial Data Line): the role of this line is to transmit and receive data between Masters and Slaves
Figure 2.6: I2C communication structure [10]
I2C protocol is a transmission and receiving process between master devices and slave devices Master devices are microcontrollers, these devices will control the clock pulse signals through the SCL and transmit or receive data or instruction from other devices in the system through SDA The devices getting the instructions and signals
Trang 29Rp These devices can only pull the bus down to the ground but cannot pull the buses
up to high voltage to prevent short circuit issues from the activity that one device pulls the buses up and the other pulls the buses down Therefore, there is a register (4.7 kΩ)
to keep the buses high in default
In I2C communication, the master devices and the slave devices communicate with each other by forming a message including some kind of bits These bits are illustrated in the figure 2.7 below:
Figure 2.7: I2C message frame
Firstly, there is a Start bit in a frame When a master device wants to start a request (transmission of receiving data), it will send a start bit to other devices to begin
a frame After sending the start bit, an address frame will be sent, this frame consists
of seven or ten address bits and helps the master devices to be able to identify the other devices Because the communication process is implemented between many devices, each device will be assigned to an address to be recognized:
Figure 2.8: Devices in I2C communication protocol
Trang 3011
In the figure 2.8, each device has an address and this address helps the master to recognize the slave devices in the system for example the LCD in the figure has the address of 0x27, … If the master device wants to communicate with this LCD, the master will send the address of 0x27 to other devices through the buses The device with the same address of 0x27 (LCD) will be chosen to communicate with the master Then, the master sends the Read/Write bit This bit is used to decide the transmission process of the master operated or the receiving process of the master operated If this bit is set to 0 by the master, the transmission process of the master will operate and the master will send data to other devices If this bit is set to 1 by the master, the receiving process of the master will operate and the master will receive the data from other devices When the master decides to receive or send the data to other devices by setting Read/Write bit, it will consider an ACK/NACK bit standing for Acknowledge/Nonknowledge bit The first ACK/NACK bit is used to compare the physical address bits of the devices to the address bits in the message that is sent by the master If these address bits are the same, the slave device will set the ACK/NACK bit to 0 by pulling the SDA down to the ground Unless these address bits are the same, the ACK/NACK has a default bit of 1 The Data field has 8 data bits, these bits are set up and sent by the transmission devices to the receiving devices, and then an ACK/NACK bit is sent after the data bits immediately in order to examine whether the data bits are received successfully or falsely If the data bits are received completely, the ACK/NACK bit is set to 0 If the receiving devices fail to receive data, the ACK/NACK bit is set to 1 Finally, when all the data is sent or received successfully, the master devices will send a Stop bit to the Slave devices for announcing that the communication process is finished
In general, there are two main cases in the communication process of the I2C communication protocol The master sends the data to the slave and the master receives the data from the slave that means the master is a transmitter in case 1 and the master is a receiver in case 2
In case 1, the role of the master is a transmitter and the slave is a receiver First, the master will send a START condition and address bits to the slave:
Figure 2.9: Start condition in I2C communication protocol
Trang 3112
The figure 2.9 illustrates the START condition in the I2C communication process This condition occurs when there is a transition from a high to a low voltage level in the SDA bus during the voltage level of the SCL bus is high Then, the master will transmit the data bits:
Figure 2.10: Transmission in I2C communication protocol [10]
Each data bit in the SDA bus is transferred during each clock pulse of the SCL bus The most significant bit is transferred first and then the ACK/NACK bit is set depending on whether data bits are received successfully or falsely The master will then send the STOP condition:
Figure 2.11: Stop condition in I2C communication protocol
This condition occurs when there is a transition from a low to a high voltage level in the SDA bus during the voltage level of the SCL bus is high
In case 2, the role of the master is a receiver and the slave is a transmitter The process is nearly similar to case 1 In this case, the master sends a request to read the slave and receive data bits from the slave
Trang 32Features of Proteus:
There are 2 main parts of proteus first is used to design and draw different circuits and the second is for designing PCB layout
− First is ISIS that used to design and simulate circuits
− And second is ARES that is used for designing printed circuit boards It also provides features related to the three-dimensional view of design in PCB
2.3.2 ARDUINO IDE
Arduino IDE is an open-source software mainly used to write and compile code into microcontrollers such as Arduino Uno, Arduino Mega, ESP32/8266, Arduino Leonardo, Arduino Micro, and many other modules Each module contains an onboard microcontroller that is programmed and accepts information in the form of code The main program, also referred to as the sketch, is created on the IDE platform and converted into a Hex file, which is then uploaded into the on-board controller
The IDE environment mainly contains two basic parts: Editor and Compiler, For the editor is used to know the code, compiler is used to compile the code so that the microcontroller can understand the program from the writer
2.3.3 VISUAL STUDIO CODE
Visual Studio Code is an application to edit code to support in the process of building and designing websites quickly Visual Studio Code runs smoothly on Windows, macOS, and Linux platforms Furthermore, VS Code is compatible with mid-range configuration machines that can still be easily used It supports debugging,
is bundled with Git, and includes syntax highlighting, smart auto-completion, snippets, and source code enhancements
Visual Studio Code brings a lot of advantages over any other IDE:
• Cross-platform support
• Supports many popular programming languages: C/C++, C#, F#, JavaScript, JSON, Visual Basic, HTML, CSS…
• Effective Features
Trang 33• Can view data in real time
• Devices can be easily configured and sent data to ThingSpeak using communication protocols
• It could receive information from third-party software
• Can be used to analyze data with MATLAB
• Building an IoT system prototype does not necessitate the use of a server
or web software
2.5 FIREBASE
Firebase is a database service that works on the cloud (Cloud) It comes with Google's powerful server system The primary function of the system is to assist users
in programming applications by simplifying database operations
Firebase is a versatile platform, it provides a lot of different services to its users, and here are some of the outstanding services such as: Real-time Database, Authentication, Firebase cloud messaging, Firebase database query, Remote Config…
Figure 2.12: Firebase
Trang 3415
2.6 OVERVIEW OF HTML, CSS, JAVASCRIPT
2.6.1 HTML
HTML stands for Hypertext Markup Language is a programming language used
to build and restructure the components contained on the Website It helps users create and structure elements in a Web page, Application, Heading, Links, and Blockquotes
Table 2.1: HTML tags
<header></header> Is the header section, containing the title,
Logo
<button></button> Create a button on the web
<h3></h3>
It uses the character format in the title and inserts a class attribute so we could change the font and color of the tag The font size is smaller than H1, and H2
<section></section>
It is used to divide content on a web page and insert a class attribute so we can edit the font, color, image, and position of the tag base on the CSS
CSS components have 4 elements:
+ Selector: point to tag from HTML to change the Properties
Trang 351 Commands define the background
To set the background properties, we use the commands listed below:
+ Background-image: Choose an image for the background
+ Background-position: define the position of the background
+ Background-repeat: define the number of copies of the background image
+ Background-attachment: let the background image scroll with the screen or not + Background-size: define the size of the image
2 Commands define the location of the element
Commands that define the location are used to set the position of the declaration element to display, such as those listed below:
+ Margin: create space around elements, outside of any defined borders
+ Padding: create space around an element's content, inside of any defined borders + Position: define the element's positioning method (static, relative, absolute, fixed, or sticky)
+ Text-align: the horizontal alignment of text in an element is specified by the property
+ Z-index: the stack order of an element is specified by the property A ordered element is always in front of a lower-ordered element
higher-+ Justify-content: align the flex items at the center of the container
+ Align-items: center the alignments for all the items of the flexible element + Display: display properties of the element
3 Commands for text format
+ Text-decoration: define specify the decoration added to the text
+ Font-size: set the size of the font text
+ Font-family: define property specifies the font for an element
+ Font-weight: define how thick or thin characters in text should be displayed + Text-transform: controlling text capitalization
4 Some others for decoration
Trang 3617
Other commands can be used for a variety of elements such as images or text:
+ Border-radius: the radius of the element's corners is defined by the property + Width: define the width that takes place of the element
+ Height: define the height that takes place of the element
+ Color: define the color of the element
+ Transition: property specifies the origin position of a background image
+ Cursor: define the shape of the pointer in this element
+ Opacity: property sets the opacity level for an element
+ Overflow: controls what happens to content that is too big to fit into an area
2.6.3 JavaScript
JavaScript is a popular website programming language that is integrated and embedded in HTML to enhance the visual appeal of the website JavaScript is a web page component; the executable allows client-side scripts from both the user and server sides (Nodejs) to create dynamic web pages
JavaScript is an object-oriented interpreted programming language as well As one of the three main languages in web programming, and they are interconnected to create a lively, professional website:
• HTML: Support in building layout, add content easily on the website
• CSS: Supports design formatting, layout, style, color, …
• JavaScript: Create "dynamic" content on the website
2.7 CONTROLLING SYSTEM ON SMARTPHONE APPLICATION 2.7.1 APP INVENTOR
App inventor is an open-source web application that is supplied by Google from July 2010 After that, app inventor is managed by Massachusetts Institute of Technology (MIT)
In principle, the operation of app inventor is based on android mobile platform that means an application product generated by MIT app inventor will be able to operate on the Android platform Interface of app inventor consists of blocks that contain codes The users can drag and drop these blocks to the interface to create an application used on mobile phone or tablet
Trang 37The ESP32 NodeMCU LuaNode32 Wi-Fi BLE RF transceiver kit is developed
on the basis of the ESP32 central module with the latest integrated Wi-Fi, BLE technology and ARM SoC core The kit has a similar hardware design, firmware and usage Kit NodeMCU ESP8266, with the advantage of easy use, full output, integrated charger and UART CP2102 communication, BLE Wi-Fi Kit ESP32 NodeMCU LuaNode32 is the first choice in Wi-Fi research and applications, BLE and IoT
Figure 2.14: NodeMCU ESP32
Trang 38− 2 channels DAC converter
− SPI, UART: 3 pins
− I2S, I2S: 2 pins
− CAN bus 2.0
− GPIO: 34 pins
2.8.2 DUAL FULL BRIDGE DRIVER – L298
The L298 DC motor driver circuit is capable of controlling two DC motors, the limit current for each motor is 2A, integrated circuit protection diode and power IC
7805 to supply 5VDC power to other modules
Figure 2.16: L298 motor driver
Trang 3920
The maximum power for one bridge is 20W, the formula is expressed below:
P = U*I Specifications [12]:
− Current Consumes: 80mA
− There is an indicator light on each relay
− Switch station voltage maximum: AC250V ~ 10A or DC30V ~ 10A
− Weight: 17g
− Dimensions: 5.0 x 2.6 x 1.9 cm
2.8.4 I2C MODULE
LCD has too many pins, making it difficult to connect and occupy many pins
of the microcontroller I2C converter module for LCD will solve this problem, instead of using a minimum of 6 pins of the microcontroller to connect to LCD (RS, EN, D7, D6, D5, and D4), with a converter module, it only needs to use 2 pins (SCL, SDA) offers two signal output pins (SDA and SCL) for communication with
a MCU/MPU I2C converter module supports LCD types using HD44780 driver (LCD 1602, LCD 2004, ), connected to the microcontroller via I2C interface, compatible with most of today's microcontrollers
Trang 4021
Figure 2.18: I2C module
Specifications [14]:
− Operating voltage: 5V (DC)
− PCF8574-based I2C control
− Address for I2C: 0X20–0X27
Figure 2.19: LCD 20x4
Pinout of LCD 20x4 [17]:
− VSS: Ground pin for LCD
− VDD: LCD power output at 5V