From this article, we will learn how to make a gas leak detector based on the MQ-2 sensor with an event notification function on a smartphone. The master uses ESP8266 and the famous Blynk app to transfer data. This application is used in many projects of the “Internet of Things”.
Tools and materials: -NodeMcu ESP8266; -MQ-2 gas sensor; -Project board; -Jumpers;
-Computer with software;
Step one: how it works
The device uses an MQ-2 gas sensor, which detects gases such as alcohol vapors, smoke, hydrogen, methane, propane, butane. The sensor has an analog and digital output. A signal is sent to the digital output when a certain gas concentration threshold is exceeded, which is adjusted by a trimming resistor. A NodeMcu ESP8266 is used as a microcontroller, which also has Wi-Fi. The gas value is set by software . The MCU sends these values to the smartphone to the Blynk app. When the amount of gas increases above 200, the application displays a “Gas detected” notification.
< img class = "aligncenter" alt = "How to independently make a gas leak alarm with an alert on a smartphone" src = "https://usamodelkina.ru/uploads/posts/2021-04/1617373767_fydv1zpkmuloghb.jpg"/> Step the second: the scheme
The installation scheme is very simple.
NodeMcu —- MQ-2 sensor
A0 & gt; & gt; A0 (analog output)
G & gt; & gt; GND
3v3 & gt; & gt; VCC
Step three: installing and configuring the BLYNK application
The Blynk app allows you to create a convenient remote control for a wide range of microcomputers and microcontrollers.
To install it, follow these steps:
Install the Blynk app from the Google Play store.
Create an account on Blynk.
Create a new one project.
Get a token to your email.
Give a name to the project.
Select the equipment (NodeMcu) and the type of connection (WIFI) and click the” Create “button. < br> Add a sensor using the widget window.
Name the sensor “Gas Value”, select Pin & gt; Virtual & gt; V2, Push & gt; 1Sec.
Add a notification using the widget window.
Now the application is configured.
Step four: code
Now you need to install the code on the microcontroller.
Add the Blynk library to the Arduino development environment, as well as the NodeMcu library: Sketch-Include Library-Manage libraries-Type Blynk-Install (same for other libraries)
Copy the code below and upload to Arduino Nano. The code is commented and you need to provide data for WIFI and BLYNK.
/* * Hello, welcome back to Techno-E-Solution * Here is the arduino code for the Project * Add following libraries in your Arduino IDE * Here is the complete Project making video & # 58; - https & # 58; //youtu .be/m2QufB-bap8 */#include & lt; ESP8266WiFi.h & gt; #include & lt; BlynkSimpleEsp8266.h & gt; BlynkTimer timer; #define BLYNK_PRINT Serial //Comment this out to disable prints and save space char auth & # 91; & # 93; = & # 34; Auth Token & # 34 ;; //Enter Authentication code sent by Blynk on your regested email char ssid & # 91; & # 93; = & # 34; ---------- & # 34 ;; //Enter WIFI Name Here char pass & # 91; & # 93; = & # 34; ---------- & # 34 ;; //Enter WIFI Password Here int mq2 = A0; //smoke sensor is connected with the analog pin A0 int data = 0; void setup () & # 123; Serial.begin (115200); Blynk.begin (auth, ssid, pass); timer.setInterval (1000L, getSendData); } void loop () & # 123; timer.run (); //Initiates SimpleTimer Blynk.run (); } void getSendData () & # 123; data = analogRead (mq2); Blynk.virtualWrite (V2, data); if (data & gt; 200) & # 123; Blynk.notify (& # 34; Smoke Detected! & # 34;); }}
Everything is ready. For practically little money, we get a workable device that may save lives. Of course, you also need a case and a power supply, but this is at the discretion of users.
The whole process of assembling and testing the device can be watched in the video.