How To Make LPG Gas Leakage Detector Using MQ-2 Gas Sensor & ESP8266 NodeMcu

February 01, 2022


Description

In this article, we are going to make an IoT project which will be very interesting. In this article, I'll show you How to make a gas leakage detector Using an MQ-2 Gas sensor with a NodeMcu ESP8266 Wi-Fi Module. In this project, we mainly use the MQ-2 gas sensor to detect the LPG gas & smoke. We'll start by reading the gas sensor output using NodeMCU. Then send that data to the Blynk application. Finally, We will be able to Display the gas value in the form of a Gauge, it also shows the notification when gas will get detected. This project is very useful to avoid accidents in homes & Industrial areas. You'll also find in the project that you can use this technique to create another application in your android phone to read any type of gas over a Blynk platform. I've added the circuit diagram, pictures, and videos of the project.
You must have already heard about the LPG gas leakage cases. Sometimes it happens that there is a leakage in the LPG cylinder and people get suffocated because of the high concentration of LPG in the air which leads to death or severe health issues. There are many ways to detect such gases and alarms are also available with sensors that detect those gases already present. We can use these devices for our home safety purpose too as this is an affordable way to detect any dangers from our home's surrounding air.

Watch out the video If reading bores you.

How It Works

In this project, we have used an MQ-2 gas sensor to detect the LPG gas, Alcohol, or Smoke, in the surrounding environment. The gas sensor's working principle is completely based on the resistance between the electrodes of the sensor. So, If there is an LPG gas or Alcohol in the air the resistance between two electrodes of the gas sensor gets increased according to the gas presence and we have used NodeMcu as a microcontroller that reads the analog value from the gas sensor and converts it into a digital value and continuously sends to the Blynk platform. After that, we check the input value, and when it's more than a specific value, then we can detect the gas in the surrounding. In our Programming, I have set the gas value 200 & when this value goes above 200 then we get a notification on the smartphone by the Blynk Application. Which is "Gas Detected" You can change the gas value as per your requirements.

Material Required

Circuit Diagram

Circuit Diagram

Blynk Application Setup

Follow the following steps to set up the Blynk Application.

  • Install The Blynk application on your smartphone.
  • Create an account on the Blynk application.
  • Click on Create New Project.
  • Now you'll get a pop-up notification of the Token number on your screen.
  • Now give a name to the project as per your choice.
  • Select the Hardware as (NodeMcu) & Connection type as (Wi-Fi) then click on create button.
  • Now add Gauge from the widget box.
  • Set name to the Gause as "Gas Value", Select Pin >> Virtual >> V2, Push >> 1 Sec
  • Now add Notification from the widget box.

Esp8266 Board Installation

Refer the following tutorial to Install ESP8266 board in arduino IDE.

Arduino Code

Before uploading code to ESP8266, install the following libraries in your arduino IDE
Library ( ESP8266wifi.h )

/*
 * Hello, welcome back to Techno-E-Solution
 * Project Name:- LPG Gas Leakage Detector Using MQ-2 Gas Sensor & ESP8266 NodeMcu
 * Project video :- https://youtu.be/m2QufB-bap8
 */
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
char auth[] = "Auth Token"; //Enter Authentication code sent by Blynk on your regested email
 

char ssid[] = "----------"; // Enter WIFI Name Here
char pass[] = "----------"; // Enter WIFI Password Here
 
 
int mq2 = A0; // smoke sensor is connected with the analog pin A0 
int data = 0; 
void setup() 
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, getSendData);
}
 
void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}
 
void getSendData()
{
data = analogRead(mq2); 
  Blynk.virtualWrite(V2, data);
 
  if (data > 200 )
  {
    Blynk.notify("Smoke Detected!"); 
  }
 
}

You can Buy me a coffee If you got this article helpful.

If You have any questions about this tutorial please do not hesitate to comment or ask in the comments below. Thank You!