Smoke/Gas detector

Description

This project aims to develop a Smoke/Combustible Gas detector using ESP32 and MQ-2 sensor. ThingSpeak provides data ingestion and storage for the sensor, with the possibility to build Matlab algorithms to make the system smarter. When a certain threshold is exceeded ESP32 sends an email alert to signal the owner of the building/apartment that a gas leakage has occurred. Also to set up Wifi credentials without hardcoding the SSID and password directly in code, a prior bluetooth connection is established via smartphone, using Bluetooth Terminal HC-05 application.

Hardware Implementation

The hardware schematic contains the following devices:

- ESP32-WROOM-32 (integrated Wifi and Bluetooth), ADC with 12-bits resolution (values between 0-4095)
- MQ-2 Smoke/Combustible Gas sensor. For this application we will use the analog output (AO) pin to measure the gas level in the room.
- 5V battery, or any device that can provide 5V (e.g. Arduino Uno 5V pin)

Software Implementation

The following steps describe the functionality of the project:

- boot/reboot device
- introduce Wifi credentials and connect to it
- read data coming from MQ-2 sensor
- publish data on ThingSpeak
- if value is above threshold enter in 'aware state' (read 5 times and see if 2 high values above the threshold are met, if so it means that gas is detected in the room)
- if gas detected in room send email to the owner.
Down below you can check the software diagram.

software_diagram.png

Wifi Connection

The Wifi connection is set up using Bluetooth using Bluetooth Teminal HC-5 application. [1]
First connect to the Bluetooth device using the app and give Wifi credentials (SSID and password). After that the Wifi connection is established and the Bluetooth connection is disabled. Wifi and Bluetooth use the same antenna on ESP32 devices and they cannot coexist. The Wifi credentials are saved and loaded every time the ESP device is powered. If you want to change the credentials just reboot the device and introduce them again in application.


The EEPROM (electrically erasable programmable read-only memory) saves the last introduced Wifi credentials until new ones are introduced in app and tries to connect to them when device is booted.

ThingSpeak Data Ingestion

Every time data is read from the sensor it is saved online through ThingSpeak API along with Wifi received signal strength indicator (RSSI). I used a ThingSpeak private channel to do that, and data can also be viewed in real time on mobile phone with ThingView Free app.

Email Alert

The project has the feature to send an alert email to the apartment owner using IFTTT service. [2]
The email address is hardcoded in the json that is sent by the http post request via Webhook. A gmail address was created prior to sending the alert. This is the email address used to send messages to the hardcoded owner address.

Conclusions

This project is a good application to monitor the gas level in a room. You have the possibility to view in real time the values collected by the sensor via ThingSpeak platform service and to receive an email alert if the threshold has been exceeded. Also, you have the possibility to connect to Wifi from any place because the SSID and password are not hardcoded in the source code. You can connect to the device via Bluetooth prior to a Wifi connection and set-up the credentials.
For IoT beginners it is a good way to start. The project is rather simple when it comes to hardware, but it focuses more on the connectivity and infrastructure side making it more reliable and easy to use.

Further Improvements

It will be interesting to have all setup done with a configuration file (json) sent via an application from smartphone and to set the Wifi credentials along with the email address and ThingSpeak channel information and not have them hardcoded.

Resources

iothings/proiecte/2021/gasdetector.txt · Last modified: 2022/01/24 15:47 by narcisa.guran
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0