Tải bản đầy đủ (.docx) (31 trang)


Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.29 MB, 31 trang )





FIGURE 1.1: Logo Arduino IDE……………………………………………………….10
FIGURE 1.2: Timer and counter in microcontroller…………………………………....13
FIGURE 1.3: Sensor diagram…………………………………………………………...14
FIGURE 1.4: Module ESP32……………………………………………………………16
FIGURE 1.5: Commuinication webserver with ESP32…………………………………16
FIGURE 1.6: Connect wireless devices…………………………………………………18
FIGURE 2.1: ESP32…………………………………………………………………….19
FIGURE 2.2: ESP32 pinout……………………………………………………………..20
FIGURE 2.3: Principle diagram ESP32…………………………………………………21
FIGURE 2.4: Flame sensor………………………………………………………………23
FIGURE 2.5: Principle diagram of flame sensor………………………………………...24
FIGURE 2.6: Buzzer……………………………………………………………………..25
FIGURE 2.7: Principle diagram buzzer………………………………………………….27
FIGURE 2.8: General principle diagram………………………………………………...27
FIGURE 3.1: Algorithm flowchart of ESP32……………………………………………29
FIGURE 3.2: Algorithm flow chart of computer………………………………………...31
FIGURE 4.1: Arduino programming…………………………………………………….33
FIGURE 4.2: SIMULATION……………………………………………………………34
FIGURE 4.3: SIMULATION……………………………………………………………34


Chapter 1: Overview of the topic

Introduction topic

The smart fire alarm system for houses has not yet been applied by many
families and also knows a lot about it. Smart fire alarm systems are designed to
alert us in an emergency so we can take action to protect ourselves, our
families and others. Early detection is also a key factor in helping to protect the
safety of life and property, and giving emergency responders enough time to
provide timely assistance in the event of a fire or small toxic gas. Protection
mechanism including detection of fires or flames. Warning mechanis including
siren, indicator light or sending sms.


Automatic fire alarm system is a device system that automatically detects and
announces fire locations (according to Vietnamese standards TCVN 57382001). Automatic fire alarm system includes: Fire alarm center, fire detectors,
(combination of bells, lights, push buttons) and other peripheral devices...
Working principle: Normally the whole system is on duty. In this mode, the fire
alarm center always has a signal to check the work of the equipment in the
system, and the addressable fire detectors, modules, etc. also have a response
signal to the center. Periodically, from time to time (depending on setting) the
center will print the status of the system and information about the equipment
that needs maintenance. In the circuit there is always current Io flowing

through. In the monitoring mode, if the center receives an error signal from the
devices or does not receive a response signal from the devices, the center will
switch to trouble mode.


How it works when the sensor detects a fire within a range of about 80cm, then
a signal will be sent to the owner via sms, then the owner will confirm the real
or fake alarm and then press the alarm button, and at the same time call the fire
brigade to come to the rescue.



The fire alarm system can be applied to houses or apartments, the fire alarm
system is compact, so it can be placed in the corners on the ceiling without
occupying the area of the house or losing its beauty.


Research purpose

To make a microcontroller, it is important that we know about the Arduino IDE
software, IDE stands for Integrated Development Environment. Arduino IDE is
an open source software mainly used to write and compile code into Arduino
modules. Arduino has versions for operating systems such as MAC, Windows
and runs on the Java platform that comes with built-in functions and

commands to play an important role in debugging, editing and compiling the
code in the environment. Each module contains an onboard microcontroller
that is programmed and accepts information in the form of code, the master
code is also known as a sketch.

Figure 1.1: Logo Arduino IDE

Programming environment (IDE). In the world people program ESP32 through
2 IDEs, VS Code and Arduino. With Arduino, it is too famous, but there are
limitations such as:
● Inability to self-complete code, suggestions (leading to typos) and I really

hate this point
● Unable to view source of included libraries. Leads to you not knowing how

to use that library, and have to use another editor to open it

● The original function could not be found. When programming you forget to

pass any parameters, with VS Code just a simple operation of Ctr Click, it
will open the file containing that original function, but the Arduino does not
have this effect a lot on the process. submit your code
● Not cool and Pro. One thing is for sure, when you use VS code, you won't

want to use arduino again.

Arduino: Written based on ESP-IDF, it can also be said that Arduino lib is a
sublibrary of ESP-IDF


● Familiar with Arduino users
● The code is fast and easy, there are many sources of support


● No code optimization
● Some functions are missing


ESP-IDF: is a library package released by the company, with an entire API
manual, suitable for English learners.


From time immemorial, the prevention of fire or the work of fire prevention
has always been considered a top important issue in each country. In Vietnam
today, the speed of infrastructure construction is taking place strongly.
Townhouses are appearing more and more, especially in big cities. Houses with
many different architectures and more importantly, houses are often do not
focus on creating safety for the home, so with the knowledge that I have
learned at school, I decied to apply this research to find a good solution. I think
microcontroller is very suitable for me to apply in this research although I am

not very good at it but I still want to try it.


The purpose of my research is to apply the learned microcontroller to create a
better product. I want to use the knowledge that I have learned to be able to
create a product so that it can be applied in practice in a more useful way and
can help more people.


Today, people often do not pay attention to the safety of home fire alarms on
the market, often the system is quite complex and takes up a lot of space in the
house. Because of this inconvenience, it was the idea for me to research smart
home fire alarm systems. The purpose of this is to bring safety and aesthetics to
the house, and especially to learn more new knowledge about microcontrollers
so that I can experience more new things that can be applied more practical


Research subjects

The objects that I study in this topic are microcontrollers and sensors.


Microcontroller is like a computer intergrated on a chip and used to control
electronic devices. It a self-contained embedded system with peripherals,
processor, and memory. It is applied in the manufacture of many civil
electronic devices such as phones, cars, led equipment, ambient temperature
gauges,… There are different types of microcontrollers, they are classified
according to parameters such as Bits, RAM size, Flash, number of input and
output lines.


The microcontroller has the following components:
● CPU: This is considered the brain of the microcontroller
● I/O port: Used to control and communicate with devices
● Memory: Used to store data and programs
● The serial port is the part that connects the microcontroller and other

external peripherals
● ADC and DAC converter: ADC is used to convert analog signals to digital.

DAC is used to convert digital signal to analog
● Timer and counter: Timer and counter function in microcontroller


Figure 1.2: Timer and counter in microcontroller

A sensor is a device that detects and responds to some kind of input from the
physical environment. The specific input is light, heat or any one of many other

enviromental phenomena. The output is generally a signal converted to a
display readable at the sensor position, or transmitted electronically over a
network for further reading or processing. In this research, I chose a fire alarm
sensor to match the topic I am researching. Flame sensor has a detection range
of about 80cm with a scanning angle of 60 degrees and has 2 signal outputs,
digital and analog, very easy to use. There is also built-in IC LM393 to convert
ADC. When the module is active, the signal pins will signal to the control
device. At that time signal pin Dout:
● High level signal is no fire
● Low level signal is fire


Figure 1.3: Sensor diagram

Arduino is an open source platform that helps people build electronic
applications that are better able to link and interact with each other. Arduino
can be seen as a miniature computer that helps users program and execute
programs. Electronic projects do not need specialized tools for the code
loading process.


The Arduino components include the following hardware and software:
● Armature: Microcontroller with some open source circuit boards for control

and programming including:
● Arduino Uno a kind of simple board suitable for beginners. This data board

includes 14 pins, 6 pins 5V to help resolve 1024 levels. Arduino Uno can
run at 16MHz, voltage 7v-12v. The size of this board is 5.5x7cm and it
costs about 200,000 VND.
● Arduino Micro has 20 pins compact design, light weight, board size 5x2cm.
● New design Arduino Pro, digital pin is not available. This type of board

usually has 2 sources of 3.3v and 5v.
● Arduino Nano is the most compact size, easy to install with the size of


● Arduino Mega design part counting pins 64 pins, size 5x10cm.
● Arduino Leonardo does not have a USB port for programming. Design

board with small chip to control, connect via virtual COM.
● The IDE integrated development support software is responsible for

editing, compiling code, loading chapters for the board.

The history of the Arduino: In the 9th century in Italy, the Arduino was born
and was named after the king of that country, King Arduin. Arduino was
officially introduced in 2005 as a tool for students to learn. One of the Arduino
developers at the Interaction Design Institute Ivrea. Arduino has now been
applied in many areas of life. This open source code brings many practical
benefits to people. Thanks to that, Arduino was born for a long time but still
exists and is so popular.


Applications of Arduino in human life. When it comes to applications of
Arduino, there are a number of areas that must be mentioned as follows:
● Arduino makes Robot with the ability to monopolize sensor devices,

control motors .... Arduino helps the central processing unit do its job
through a variety of robots.
● Interactive games: Arduino is used to interact with the screen, Joystick, ...

when playing games like breaking bricks, Mario, Tetris,...
● The plane is unmanned.
● Control traffic lights, flashing LED effects.
● Make a 3D printer.
● Lighting design.
● Make a toaster with a tweet warning when the cake is done.

Ability to connect to other devices. You can use Arduino to do a few things:
● Arduino works independently.
● The Arduino connects to the computer to access sensor data from the

outside world and provide you with feedback.
● The Arduinos will connect themselves to each other.

● Arduino connects to another electronic device.
● Arduino connects to the control chip.

Figure 1.4: Module ESP32

A webserver or web server is a computer that installs programs that serve web
applications. Webserver is capable of receiving requests from web browsers
and sending responses to clients via HTTP or other protocols.


Whenever you view a web page on the internet, you are requesting that page
from a web server.

Figure 1.5: Commuinication webserver with ESP32



When you enter the URL on a browser (web browser) like chrome, firefox
actually does the following steps:
● The browser will request information from one or more DNS servers

(through the internet). The DNS server will tell the browser which IP
address the domain name should point to which is also where the website is
● The DNS server will redirect the browser to the IP address of the server

corresponding to that domain name

● The server responds to the browser with the requested information: Usually

it's an HTML page
● The browser renders the html, css, js... files that the server transmits into a

website displayed on the computer for the user to use.

Research scope

The scope of application of this topic can be used for households, corporate
offices or even important small corners of factories. But since this is a small
model, applying this model in practice is really not very promising because the
modules applied to this topic are quite small and limited by many things such
as the range of development, present in the range of 80cm and has a scanning
angle of 60 degrees. Besides, the sensor only detects flames and does not
detect smoke. But if a larger model is developed, households will be much
more suitable for this system because the housing space is small in scope and
can be identified more accurately, not affected by factors outside. Also the
model can send warning messages to the user.


Station mode in wifi connection. To connect wireless devices (such as
smartphones, laptops) or wired devices (such as desktop computers) to a local
area network (LAN), we use a device called an Access Point (access point). ).
Devices connected to the Access Point are called Stations.


Figure 1.6: Connect wireless devices

In the family, the router/modem device that has the function of transmitting
WiFi is an Access Point for stations such as phones and computers to connect
to. Then those Routers/Modems connect to the internet via fiber optic network.
Each Access Point has a specific SSID (Service Set IDentifier) or we often call
it Wifi Name. Stations connect to APs according to TCP/IP model, so to
distinguish Stations and APs in a network we use IP Address.


Expected results

After doing the topic, the final product that I can bring is a fire alarm system
with sirens, warning lights and can send automatic messages via sms.
Programmable arduino to connect arduino with fire alarm sensor, and can
output the results to the web. The sensor devices can work well receiving and
receiving the signal to successfully output to the web. Besides, the signal
transmission lines can be stable and the sensor works stably to give the most
accurate warning.


Chapter 2: Design and Construction
2.1. The block diagram of the system

Central controller

Flame sensor

Warning speaker and
light led

2.1.1. Block A
- Block A inlcude a USB port to connect to a computer and the main component
is the ESP32. As the control center of the system, this controller is the main
body to help us program the output devices as we want by the programming
software. The output also cannot output the desired signal. Besides, the main
function of the module is to receive and transmit wifi for the device.

Figure 2.1: ESP32

The main component that I use is ESP32. ESP32 is a system-on-chip
microcontroller (SoC). With built-in Wifi, Bluetooth and Bluetooth LE helps to

ensure the flexibility of the module. Wifi connection is guaranteed in a large
radius and while using Bluetooth allows the user to easily detect a module and
connect it to a smartphone. Besides, the configuration of ESP32 is very diverse
such as CPU running 32bit system, processing speed of 160MHz up to
240MHz and clock speed of reading flash chip 40MHz to 80MHz. Support 2
wireless communication, support all kinds of communication, built-in sensor
on ESP32 chip and in addition very fast processing speed.

This is pinout of ESP32:

Figure 2.2: ESP32 pinout

Specifications of ESP32:
● Single-core or dual-core 32bit LX6 processor with up to 240MHz
● 520 KB SRAM, 448 KB ROM and 16 KB SRAM RTC
● Supports 802.11b/g/n wifi connection with speed up to 150Mbps
● Support for both classic Bluetooth V4.2 and BLE specifications.
● 34 programmable GPIOs
● 18 channels of 12bit SAR ADC and 2 channels of 8bit DAC
● Serial connections including 4xSPI, 2xI2C and 3xUART
● Ethernet MAC for physical LAN communication
● 1 host controller for SD/SDIO/MMC and 1 slave controller for SDIO/SPI

● PWM motor and 16 led PWM channels
● Secure Boot and Flash Encryption
● Cryptographic hardware acceleration for AES, Hash (SHA-2), RSA, ECC

and RNG
● Operating temperature: -40 +85 degrees
● Operating voltage: 2.2-3.6V

The ESP32’s hardware would be more user-friendly if it could be programmed
in more than one way. Here are some commonly used programming

environments: Arduino IDE, PlatformIO IDE, LUA, MicroPython, Espressif
IDF and JavaScript.


Principle diagram of ESP32: We connect 2 Leds to 2 pins 26 and 27. Or any
other GPIO pin can be set as OUTPUT.

Figure 2.3: Principle diagram ESP32

Strengths of ESP32 compared to other series:
● It can be said that ESP32 is the perfect upgrade of ESP8266, with ESP8266

suitable for small and cost-effective projects. ESP32 is suitable for more

complex projects, higher processing speed and more powerful peripheral
● ESP8266 is 17 GPIO pins, 10-bit resolution ADC, 8 soft PWM channels

while ESP 32 has up to 30/36 GPIO pins, 18 12-bit resolution ADC
channels, 16 soft PWM channels, Touch Sensor, Hall Effect Sensor,
Ethernet MAC Interface, Built-in Temperature Sensor.
● Regarding the ESP32 memory, there is an additional 4MB of External Flash

and 520KB of SRAM (static random access memory) of which 8 KB of
high-speed RTC RAM - 8 KB of low-speed RTC RAM (used in DeepSleep

● ESP32 supports Bluetooth 4.2 and BLE (Bluetooth Low Energy). The

support for bluetooth makes ESP32 can interact with devices such as
keyboard, mouse, phone when there is no wifi.
● Ultra Low Power solves the power problem for the ESP because using Wi-

Fi will be very power-hungry, especially when we use the battery to
calculate it very carefully.
● In addition, ESP32 is being favored by many domestic and foreign

companies, so mastering this chip line will help you earn a better income is
2.1.2. Block B
- The main components used in block B include a flame sensor and a 5VDC


Figure 2.4: Flame sensor

First we talk about the flame sensor. The flame sensor are often used for
fire detection applications such as: fire fighting robots, fire sensors, etc. The
flame sensor have a detection range of about 80cm, a scanning angle of 60
degrees and in addition have the best fire detectors are those with
wavelengths from 760nm-1100nm. The flame sensor has 2 signal outputs is
Digital and Analog. Flame sensor with main functions such as:
● Ability to detect fire or light source of similar wavelength
● Using YG1006 infrared sensor with fast response speed and high

● Integrated IC LM393 to convert ADC, create 2 outputs both digital and

analog, very flexible in use
● Variable resistor to customize sensor sensitivity
● Can be applied in fire alarm systems, fire fighting robots,…

Specifications of flame sensor:

● Power supply: 3.3V-5VDC
● Consumption current: 15mA
● Output signal: Digital 3.3-5VDC depending on power supply or Analog
● Distance: 80cm
● Scanning angle: 60 degrees
● Dimensions: 3.2x1.4cm

Pin diagram of flame sensor:
● Vcc: 3.3V-5V
● GND: Power Supply Ground
● Aout (AO): Analog Output
● Dout (DO): Digital Output


Principle diagram of flame sensor:

Figure 2.5: Principle diagram of flame sensor

Next, we will step into a brief overview of the buzzer. The buzzer speaker
is a siren product commonly used in electronic circuits, designed to be
compact, suitable for use with alarms and audio signals for signals. Buzzer
is a device that makes a whistle or beep sound. There are many types but
the most basic is the piezoelectric buzzer, which is a flat piece


piezoelectric material with two electrodes. This type of buzzer requires
oscillators (or microcontrollers) to drive it. If you use DC voltage, it just
rattles. They are used in locations where sound output is required but are
not concerned with faithful sound reproduction, such as microwave ovens,
fire alarm and electronic toys. They are cheap and loud without using a lot
of energy. They are also very thin, so can be used in flat objects like
greeting cards.

Figure 2.6: Buzzer

The piezoelectric element also generates a voltage when there is pressure.
Therefore, the piezoelectric buzzer can also be used as a pressure sensor or
microphone. The more complex buzzer consists of an oscillator circuit and
a speaker, so when the voltage is applied we will get a beep or a whistle.
Sonalert is a common brand name for these devices, so you’ll sometimes

hear the word “Sonalert” used to refer to any type of horn or horn module.
There is also an electric horn, which uses a coil and an electromotive

contact. When the coil is energized, the contact is pulled towards the coil,
but it quickly closes the circuit and the contact returns to its original
position creating a loud sound. (If you add a piece of iron to this set, you
will get an electric bell). You can make a buzzer with an electrical relay by
connecting the coil in series with the normally closed contact, although it
will probably not be loud. Electric bells are commonly used in alarm
systems, doorbells, and school bells.

5VDC buzzer has long life, stable performance, good quality, compactly
manufactured, suitable for design with compact buzzer circuits, alarm
circuits .Specifications of buzzer:
● Power: 3.5V – 5.5VDC
● Consumption current: <25mA
● Resonance frequency: 2300Hz ± 500Hz
● Sound Amplitude: >80dB
● Operating temperature: -20°C to 70°C
● Dimensions: Diameter 12mm, height 9.7mm


Next I will show you the schematic of the buzzer. Diagram showing in
conventional notation all the components of a product such as an
instrument, electrical or electronic device, and the relationships between the
elements, giving a concept of the working principle of the product. Energy

efficiency is the basis for creating equivalent diagrams, assembly diagrams,
printed circuit diagrams and for drafting product design, manufacturing,
assembly, adjustment, inspection and repair documents.


Figure 2.7: Principle diagram buzzer
2.2. General principle diagram

Figure 2.8: General principle diagram


Chapter 3: Algorithm and Control
3.1 System operation
- A brief overview of the system’s operation. The system works basedon
arduino, the arduino will interact with surrounding devices through
electronic sensors, motors and lights. After the arduino can interact with the
surrounding devices, we start to program the arduino through the arduino
IDE programming software, this is considered the process of loading code
into the arduino and then the arduino will provide data to the alarm sensor
fire, then the fire alarm sensor will work as a programming part and will
output the signal through the buzzer speaker and led light.

Programming ESP32 Webserver in Station mode. In this article we use
ESP32 to create a webserver, storing html files. In it, there are buttons for
us to control the led with a computer browser. Prepare:

● ESP32 development board
● 2x 5mm LED
● 2x 330 Ohm and
● Breadboard
● Cord


3.2. Algorithm flowchart of ESP32

Figure 3.1: Algorithm flowchart of ESP32
Step 1: Starting the process, we will proceed to define the configuration of the
Step 2: Next we will proceed to connect wifi or internet to esp32


Step 3: After connecting to wifi, we will start connecting to export to the web server
Step 4: After connecting to the web server, we will check if the connection is
successful. If there is no error, we will exchange data with the server and if there is an
error, we will return to check the connection.
Step 5: Once the data has been exchanged on the server, we will check the programs, if
there are no errors, we will proceed to send the status of the devices to the server, if the
device status is not stable, we will return to step check the connection and if stable then
end the process. If there is an error in the program check, we will go through an extra step
of controlling the device on demand and then we will go to the next step to send the
status of the devices to server.