0% found this document useful (0 votes)
3 views

Design of an IoT System for Gas Alarm and Explosion Prevention

Uploaded by

longcva12345678
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Design of an IoT System for Gas Alarm and Explosion Prevention

Uploaded by

longcva12345678
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Group 5

Nguyễn Minh Nhựt-22119023


Vũ Đào Tấn Long-22119017

Design of an IoT System for Gas Alarm and Explosion Prevention

Chapter 1: Overview of the Research Topic


1.1 Reason for choosing the topic
Today, with the remarkable development of science and technology, electronics have been applied in
many fields in practice to meet the needs of health care and the protection of human life and property.
As human living standards improve, the use of gas stoves or gas products as cooking fuel has become
common. Besides the convenience of gas, another concern is the safety of its use. When people are
exposed to gas (beyond a certain allowable concentration) for a long time, they can easily get gas
poisoning and it can be fatal. Moreover, gas leaking into the air can easily catch fire and cause
explosions, seriously affecting the safety of users and those around them. Therefore, detecting and
handling gas leaks is essential for frequent gas users. This is especially true for students who often use
low-quality mini gas cylinders that can leak gas at any time. From this idea and the actual situation, I
find this is a good topic with high applicability and development potential, so I chose this topic.
To overcome gas issues, we have created a gas leak warning device. This device helps us easily
recognize gas leaks and is used in buildings and households
1.2 Topic introduction
Our research topic aims to detect gas leaks and prevent fires to protect people and property. The main
content of the project is that when gas is detected, the device will trigger an alarm to alert household
members of the gas leak for them to address the issue. It will also activate a ventilation fan by
switching a relay when gas is detected. In the event of a fire, the room temperature usually increases
rapidly while the humidity drops below a pre-set threshold. The device will then turn on a water pump
to spray the room, reducing the temperature and extinguishing the fire

Chapter 2: theoretical basis of components

2.1. INFORMATION ABOUT ESP – 8266


 ESP - 8266
- The ESP8266 is a popular and versatile microcontroller developed by Espressif Systems. It is widely
used in IoT (Internet of Things) applications due to its low cost, low power consumption, and built-in
Wi-Fi connectivity. Here are some key features of the ESP8266:
- Microcontroller: The ESP8266 is based on a 32-bit Tensilica L106 microcontroller, which runs at
clock speeds up to 80 MHz.
- Wi-Fi Connectivity: One of the standout features of the ESP8266 is its integrated Wi-Fi module,
which allows it to connect to Wi-Fi networks and communicate with other devices over the internet.
- GPIO Pins: The ESP8266 features a number of General Purpose Input/Output (GPIO) pins, which can
be used to connect to external sensors, actuators, and other peripheral devices.
- Memory: The ESP8266 typically comes with 512KB to 4MB of flash memory for program storage, as
well as 64KB of instruction RAM and 96KB of data RAM.
- Programming: The ESP8266 can be programmed using the Arduino IDE, as well as other
development environments such as MicroPython and Lua.
- Community Support: The ESP8266 has a large and active community of developers, which has
contributed to its popularity and the availability of libraries and resources.
- -> Overall, the ESP8266 is a powerful and cost-effective microcontroller that is well-suited for a wide
range of IoT applications, from home automation to industrial monitoring and control.
 Features of the ESP-8266:
- Microcontroller: The ESP8266 is based on a 32-bit Tensilica L106 microcontroller, running at clock
speeds up to 80 MHz.
- Wi-Fi Connectivity: It features integrated 802.11 b/g/n Wi-Fi connectivity, allowing it to connect to
Wi-Fi networks and communicate with other devices over the internet.
- GPIO Pins: The ESP8266 has a number of General-Purpose Input/Output (GPIO) pins, which can be
used to interface with external sensors, actuators, and other devices.
- Memory: It typically comes with 512KB to 4MB of flash memory for program storage, as well as
64KB of instruction RAM and 96KB of data RAM.
- Programming: The ESP8266 can be programmed using the Arduino IDE, as well as other
development environments such as MicroPython and Lua.
- Low Power Consumption: The ESP8266 is designed for low power consumption, making it suitable
for battery-powered applications.
- Community Support: The ESP8266 has a large and active community of developers, which has
contributed to its popularity and the availability of libraries and resources.
- Cost-Effective: The ESP8266 is relatively inexpensive, making it an attractive option for projects
with budget constraints.
- - > Overall, the ESP8266 is a versatile and cost-effective microcontroller with integrated Wi-Fi,
making it well-suited for a wide range of IoT applications.
 ESP-8266 Hardware Part:
The ESP8266 module includes several key hardware components that enable its functionality:
- Microcontroller: The heart of the ESP8266 is a 32-bit Tensilica L106 microcontroller running at
speeds up to 80 MHz. This microcontroller is responsible for executing program instructions, managing
GPIO pins, and interfacing with other hardware components.
- Wi-Fi Module: The ESP8266 features an integrated 802.11 b/g/n Wi-Fi module, which allows it to
connect to Wi-Fi networks and communicate with other devices over the internet.
- Memory: The ESP8266 typically comes with 512KB to 4MB of flash memory for program storage. It
also has 64KB of instruction RAM and 96KB of data RAM.
- GPIO Pins: The ESP8266 module has several GPIO pins that can be used for digital input/output,
analog input, and other purposes. These pins allow the ESP8266 to interface with external sensors,
actuators, and other devices.
- Power Supply: The ESP8266 can be powered using a 3.3V power supply. It is important to note that
the ESP8266 is not 5V tolerant, so care must be taken when interfacing it with 5V systems.
- Antenna: Some ESP8266 modules come with an onboard antenna for Wi-Fi communication. Others
may require an external antenna for improved signal strength and range.
- Serial Interface: The ESP8266 can communicate with other devices using a serial interface (UART).
This interface is commonly used for programming the ESP8266 and for serial communication with
other devices.
- - > Overall, the ESP8266 hardware is designed to be compact, cost-effective, and easy to use, making
it a popular choice for IoT projects and embedded systems.
 Power Supply Digital Power Supply ESP8266:
- As the operating voltage range of ESP8266 is 3V to 3.6V, the board comes with an LDO (low
dropout) voltage regulator to keep the voltage steady at 3.3V. It can reliably supply up to 600mA. It has
three 3v3 pins along with 4 GND pins. The power supply is via the onboard MicroB USB connector.
Alternatively, if you have a regulated 5V voltage source, the VIN pin is used to directly supply the
ESP8266. Moreover, it requires 80mA Operating Current and 20 µA during Sleep Mode.
 Peripherals and I/O pin of ESP8266:
- The ESP8266 microcontroller module features a variety of peripherals and I/O (Input/Output) pins,
making it suitable for a wide range of IoT (Internet of Things) applications. Here are some of the key
peripherals and I/O features of the ESP8266:
- GPIO (General Purpose Input/Output) Pins: The ESP8266 typically includes several GPIO pins that
can be used for digital input/output. These pins can be used to interface with sensors, LEDs, relays, and
other external devices.
- UART (Universal Asynchronous Receiver/Transmitter): The ESP8266 includes one or more UART
interfaces, which can be used for serial communication with other devices. UART is commonly used
for debugging and programming the ESP8266.
- SPI (Serial Peripheral Interface): The ESP8266 includes one or more SPI interfaces, which can be
used to communicate with SPI-compatible devices such as sensors, displays, and SD cards.
- I2C (Inter-Integrated Circuit): The ESP8266 includes one or more I2C interfaces, which can be used
to communicate with I2C-compatible devices such as sensors, EEPROMs, and real-time clocks.
- ADC (Analog-to-Digital Converter): The ESP8266 includes one or more ADC channels, which can
be used to measure analog voltages from sensors or other external devices.
- PWM (Pulse-Width Modulation): The ESP8266 includes one or more PWM channels, which can be
used to generate PWM signals for controlling things like LEDs, motors, and servos.
- I2S (Inter-IC Sound): Some variants of the ESP8266 include an I2S interface, which can be used for
digital audio input and output.
- Deep Sleep Wake-Up GPIOs: The ESP8266 includes several GPIO pins that can be used to wake up
the device from deep sleep mode. These peripherals and I/O features make the ESP8266 a versatile
microcontroller for a wide range of IoT applications, allowing it to interface with various sensors,
actuators, and other devices.
 Switch And Indicator
- The ESP8266 module itself does not typically include on-board switches or LED indicators.
However, development boards and modules based on the ESP8266 often include these components for
easier prototyping and debugging. Here are some common features you might find on such boards:
- Reset Switch: A reset switch is often included to reset the ESP8266 module without having to power
cycle it. This can be useful during development and testing.
- Flash Button: Some development boards include a flash button that puts the ESP8266 into
programming mode, allowing you to easily upload new firmware to the module.
- User Button: A user button can be included for general-purpose use in your application. You can
program the ESP8266 to respond to button presses in a variety of ways.
- LED Indicators: Development boards often include LEDs that can be controlled by the ESP8266.
These LEDs can be used for status indicators, debugging, or as general-purpose indicators in your
application.
- - > These features can vary depending on the specific development board or module you are using. It's
a good idea to consult the documentation for your specific board to see what features are included and
how to use them.
 ESP8266 Communication
The ESP8266 supports serial communication, which allows it to communicate with a device using the
UART (Universal Asynchronous Receiver/Transmitter interface. Here's other brief overview of how
serial communication works with ESP8266:
UART PIN: The ESP8266 has several GPIO pins that can be used for serial communication. These
pins are typically labeled TX (transmit) and RX (receive).
Serial Library: To use serial communication with the ESP8266, you can use the Serial library in the
Arduino IDE of other development environments. This library provides functions for sending and
receiving serial data.
Baud Rate: When using serial communication, you need to specify the baud rate, which determines
the speed of communication. The ESP8266 supports baud rates ranging from 300 to 115200 baud.
Serial Begin: To initialize serial communication, you use the Serial.begin() function, specifying the
desired baud rate. For example - Serial.begin(9600): initializes serial communication at a baud rate of
9600.
Serial.print() and Serial.println(): These functions are used to send data over the serial connection.
Serial.print() sends data as is, while Serial.println() adds a newline character at the end of the data.
Serial.read(): This function reads incoming serial data. It returns the next byte of incoming data, or -1 if
no data is available.
Serial.available(): This function returns the number of bytes available for reading from the serial buffer
 ESP8266 pin IO:
Label GPIO Input Output Notes

HIGH at boot
no PWM or I2C
D0 GPIO16 no interrupt used to wake up from deep
support
sleep

D1 GPIO5 OK OK often used as SCL (I2C)

D2 GPIO4 OK OK often used as SDA (I2C)

connected to FLASH button,


D3 GPIO0 pulled up OK
boot fails if pulled LOW

HIGH at boot
D4 GPIO2 pulled up OK connected to on-board LED,
boot fails if pulled LOW

D5 GPIO14 OK OK SPI (SCLK)

D6 GPIO12 OK OK SPI (MISO)

D7 GPIO13 OK OK SPI (MOSI)

pulled to SPI (CS)


D8 GPIO15 OK
GND Boot fails if pulled HIGH

RX GPIO3 OK RX pin HIGH at boot

HIGH at boot
TX GPIO1 TX pin OK debug output at boot, boot fails
if pulled LOW

A0 ADC0 Analog Input X

2.2. MQ2 gas sensor


MQ2 is a gas sensor, used to detect combustible gases. It is made of semiconductor SnO2. This
material has low sensitivity to clean air. But when in the environment there is a combustible substance,
its conductivity changes immediately. Thanks to this feature, people add a simple circuit to convert this
sensitivity to voltage.
When the environment is clean, the sensor output voltage is low, and the output voltage value increases
as the concentration of combustible gas around MQ2 increases. MQ2 works very well in the
environment of LPG, H2, and other combustible gases. It is widely used in industry and civil use due to
its simple circuit and low cost.

2.3. Fire sensor


Fire detection sensors are often used in fire alarm systems. The detection range is about 80cm, the
scanning angle is 60 degrees. The best type to detect fire is the type with a wavelength of 760nm -
1100nm. The circuit is integrated with IC LM393 to compare and create the signal level. We can adjust
the sensitivity with a potentiometer.
-Power: 3.3V – 5V, 15mA
-Output: Digital
-Distance: 80cm
-Scanning angle: 60 degrees
-Size: 3.2 x 1.4cm

Chapter 3 System design


3.1. Overview Diagram of the System
In a household kitchen, when gas leaks into the environment reaching a certain concentration, a fire
could occur if there is a spark. Based on this, the hardware system with the ESP8266 microcontroller
is designed to collect data on gas and ambient temperature using the MQ-2 gas sensor (Hanwei
Electronics Co. Ltd., 2021) and the DS18B20 temperature sensor (Dallas Semiconductors, 2021),
both commonly available in the domestic market.

Overview Diagram of the System


The operating principle of the system is illustrated in figure. Accordingly, the IoT system
continuously updates environmental signals from the gas and temperature sensors. When one of
these parameters exceeds the necessary threshold, the system will send an SMS directly to the
homeowner's phone and trigger an alarm. Finally, to ensure safety, the system will automatically cut
off the power to devices connected to the system's power relay.
3.2 Algorithm design

The system algorithm is as follows:


Step 1: Initialize sensor
Step 2: Read the gas sensor value
Step 3: Read the fire sensor value
Step 4: Check the data just read if the gas concentration exceeds the threshold or there is a fire warning
signal. If correct, the system turns on the warning buzzer and sends warning data to the wifi block. If
incorrect, turn off the warning buzzer
Step 5: Finish

3.3 block diagram of the entire system

Tasks and functions of blocks:

-Power block: Is the most basic block, it provides current to all components in the circuit. It
creates a stable voltage that satisfies voltage and current specifications.
-Central processing block: This is the central processing unit, whose task is to
• Read data from sensor block
• Data exchange communication with wifi block
• Output control signal to display block to display information
• Output signal to control alarm block for timely warning
-Wifi block: Connect to wifi and perform the following tasks
• Receive control signals on your phone and directly control peripheral devices
• Receive data from the central processing unit to send data to phone
-Sensor block: Includes
• Gas sensor to detect gas leaks and fire alarm
• Fire sensor to detect fire spots
Operating principle of the entire system
• Fire monitoring system: The system is based on a fire sensor and a gas sensor. These two
sensors collect data and send it to the central processing unit. If a fire is detected, the central
processing unit will control the siren to sound an alarm. At the same time, the central processing
unit sends a warning signal to the wifi unit and issues a warning on the App to the homeowner.
• Device control system: Controlling devices via the internet, sends control data to the wifi
block, upon receiving the data, the wifi block will control the corresponding devices to turn on
and off.

3.4 Hardware design

Solfware used:
Arduino IDE: The Arduino IDE supports programming the ESP8266 using the Arduino programming
language. You can use the ESP8266 Arduino core, which provides libraries and examples specifically
for the ESP8266.
Proteus: Used for circuit design.

#include <ESP8266WiFi.h> // Thư viện cho module WiFi ESP8266


int GasSensor = A0; // Chân A0 cho cảm biến gas
int flameSensor = D0; // Chân D0 cho cảm biến lửa
#define GreenLED D4 // Đèn LED xanh ở chân D4
#define RedLED D5 // Đèn LED đỏ ở chân D5
#define GreenLED1 D1 // Đèn LED xanh thứ 2 ở chân D1
#define RedLED1 D2 // Đèn LED đỏ thứ 2 ở chân D2
#define Buzzer D7 // Còi báo động ở chân D7

void setup() {
Serial.begin(115200); // Khởi tạo giao tiếp Serial với tốc độ 115200 bps
pinMode(GasSensor, INPUT); // Đặt chế độ chân GasSensor là INPUT
pinMode(GreenLED, OUTPUT); // Đặt chế độ chân GreenLED là OUTPUT
pinMode(RedLED, OUTPUT); // Đặt chế độ chân RedLED là OUTPUT
pinMode(GreenLED1, OUTPUT); // Đặt chế độ chân GreenLED1 là OUTPUT
pinMode(RedLED1, OUTPUT); // Đặt chế độ chân RedLED1 là OUTPUT
pinMode(Buzzer, OUTPUT); // Đặt chế độ chân Buzzer là OUTPUT
}
void loop() {
int gasValue = analogRead(GasSensor); // Đọc giá trị cảm biến gas
int flameValue = digitalRead(flameSensor); // Đọc giá trị cảm biến lửa
Serial.print("Gas Value: "); // In giá trị gas lên Serial Monitor
Serial.println(gasValue);
Serial.print("Flame Value: "); // In giá trị lửa lên Serial Monitor
Serial.println(flameValue);
if (gasValue < 200) {
digitalWrite(GreenLED1, HIGH); // Bật đèn LED xanh thứ 2
digitalWrite(RedLED1, LOW); // Tắt đèn LED đỏ thứ 2
digitalWrite(Buzzer, LOW); // Tắt còi báo động
} else {
digitalWrite(GreenLED1, LOW); // Tắt đèn LED xanh thứ 2
digitalWrite(RedLED1, HIGH); // Bật đèn LED đỏ thứ 2
digitalWrite(Buzzer, HIGH); // Bật còi báo động
}
if (flameValue == 1) {
digitalWrite(GreenLED, HIGH); // Bật đèn LED xanh
digitalWrite(RedLED, LOW); // Tắt đèn LED đỏ
digitalWrite(Buzzer, LOW); // Tắt còi báo động
} else {
digitalWrite(GreenLED, LOW); // Tắt đèn LED xanh
digitalWrite(RedLED, HIGH); // Bật đèn LED đỏ
digitalWrite(Buzzer, HIGH); // Bật còi báo động
}
}

You might also like