How to make a IoT based gas leakage monitoring system With Nodemcu and Blynk

iot based gas leakage monitoring system

Hello, welcome back. In this tutorial, we will learn how to make a gas leakage monitoring system using the Nodemcu board and Blynk app. This project mainly uses the MQ2 gas sensor and it’s based on IoT technology. That is, we can monitor everything in this security system on the mobile phone using the Internet. Also, we can do this project at a low cost. Therefore it can be used mainly for the home. This project will be more of a cover for accidents caused by gas leaks. Keep reading.

How does this security system work?

When power ON this security system, The Nodemcu board connects to the interface created in the Blynk app via the Blynk cloud. Then the system should be activated by the button created in the Blynk app interface. In this case, when a gas leak occurs, it is detected by the MQ2 sensor. Then the buzzer and LED are activated. At the same time, it notifies your smartphone via a push notification. Also, we can see the gas values on the LCD and Blynk app interface. In the absence of a gas leak, the green LED bulb turns ON and operates normally this security system.

Okey, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. To do this, use the circuit diagram below.

iot based gas leakage monitoring system

Step 3

Thirdly, let’s setup the Blynk app interface.

  • Firstly, download and install the Blynk app to the smartphone. Then, sign up for the Blynk app using your Gmail address. Now, click the New project button.
iot based gas leakage monitoring system
  • Secondly, enter your project name as you like. Then, select the device and connection. After, click the “confirm” button.
iot based gas leakage monitoring system
  • Now we add the widget to the interface. To do so, click on the “+” icon in the corner.
iot based gas leakage monitoring system
  • Then, add the styled button, Gauge, and Notification widgets to the interface. After, arrange these widgets as you like.
  • OK, now click on the widget one by one and change the settings. First, click the Widget button and name it as you like. Then set the output to V1 and mode to switch.
iot based gas leakage monitoring system
  • Now, click the Gauge widget and name it as you like. Then change the input to V0 and the values from 0 to 100.
iot based gas leakage monitoring system
  • Finally, click the Notification Widget and change the priority to HIGH.
iot based gas leakage monitoring system

Step 4

OK, Blynk app is ready. Now, let’s creates the program for this project. It is as follows.

/*GAS detector security system.
 * https://srituhobby.com
 */
 
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = " ";// Enter your Auth token
char ssid[] = " ";//Enter your WIFI SSIS
char pass[] = " ";//Enter your WIFI password
BlynkTimer timer;
int pinValue = 0;

#define Buzzer D5
#define Green D6
#define Red D7
#define Sensor A0

void setup() {
  Serial.begin(9600);
  lcd.backlight();
  lcd.init();
  pinMode(Green, OUTPUT);
  pinMode(Red, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  pinMode(Sensor, INPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(100L, notifiaction);
}
BLYNK_WRITE(V0) {
  pinValue = param.asInt();
}

void notifiaction() {
  int sensor = analogRead(Sensor);
  Serial.println(sensor);
  sensor = map(sensor, 0, 1024, 0, 100);
  if (pinValue == 1) {
    if (sensor <= 50) {
      digitalWrite(Green, HIGH);
      digitalWrite(Red, LOW);
      digitalWrite(Buzzer, LOW);
      lcd.setCursor(0, 1);
      lcd.print("Gas value:Normal");
    } else if (sensor > 50) {
      Blynk.notify("Warning! Gas leak detected");
      digitalWrite(Green, LOW);
      digitalWrite(Red, HIGH);
      digitalWrite(Buzzer, HIGH);
      lcd.setCursor(0, 1);
      lcd.print("Gas value:High  ");
    }
    lcd.setCursor(0, 0);
    lcd.print("Value : ");
    lcd.print(sensor);
    Blynk.virtualWrite(V1, sensor);
  } else {
    digitalWrite(Red, LOW);
    digitalWrite(Buzzer, LOW);
    digitalWrite(Green, LOW);
    lcd.clear();
  }
}

void loop() {
  Blynk.run();
  timer.run();
}

Code explanation

Firstly, libraries are included. Also, an object is created for the I2C library, which includes the LCD width and length.

#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

Secondly, enter your Blynk Auth token and WIFI connections details.

char auth[] = "wVkwRQu8-_IMn-WtLtLXHnJ-NISyLkjW";// Enter your Auth token
char ssid[] = "srituhobby";//Enter your WIFI SSIS
char pass[] = "1234";//Enter your WIFI password

After, the LED, buzzer, and sensor pins are defined.

#define Buzzer D5
#define Green D6
#define Red D7
#define Sensor A0

In the setup function, the serial monitor, Blynk library, and LCD display begin. After, the above pins are set as the output and input pins. Also, the main notification function is called. This function is described below.

void setup() {
  Serial.begin(9600);
  lcd.backlight();
  lcd.init();
  pinMode(Green, OUTPUT);
  pinMode(Red, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  pinMode(Sensor, INPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(100L, notifiaction);
}

This code retrieves values from the Button Widget.

BLYNK_WRITE(V0) {
  pinValue = param.asInt();
}

This is the main code part of this program. First, the values are taken from the sensor and these values are put into the integer variable. Later, these values are converted from 0 to 100. Next, the button value is checked. If the button value is 1, the main program is run. If the button value is 0, the system is turned off. Also, if the sensor value is less than or equal to 50, the green LED turns ON and prints on the LCD as “Gas value:Normal”. Then, if the sensor value is greater than 50. the red LED and buzzer activated. Also, the push notification is received on the smartphone as “Warning! Gas leak detected”.

void notifiaction() {
  int sensor = analogRead(Sensor);
  Serial.println(sensor);
  sensor = map(sensor, 0, 1024, 0, 100);
  if (pinValue == 1) {
    if (sensor <= 50) {
      digitalWrite(Green, HIGH);
      digitalWrite(Red, LOW);
      digitalWrite(Buzzer, LOW);
      lcd.setCursor(0, 1);
      lcd.print("Gas value:Normal");
    } else if (sensor > 50) {
      Blynk.notify("Warning! Gas leak detected");
      digitalWrite(Green, LOW);
      digitalWrite(Red, HIGH);
      digitalWrite(Buzzer, HIGH);
      lcd.setCursor(0, 1);
      lcd.print("Gas value:High  ");
    }
    lcd.setCursor(0, 0);
    lcd.print("Value : ");
    lcd.print(sensor);
    Blynk.virtualWrite(V1, sensor);
  } else {
    digitalWrite(Red, LOW);
    digitalWrite(Buzzer, LOW);
    digitalWrite(Green, LOW);
    lcd.clear();
  }
}

In the loop function, the Blynk library and timer are run.

void loop() {
  Blynk.run();
  timer.run();
}

Step 5

Lastly, select board and port. After, upload this code.

Now, click the run button on the Blynk app interface. Okey, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

iot based gas leakage monitoring system

How to make a IoT based gas leakage monitoring system With Nodemcu and Blynk

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Select your currency
USD United States (US) dollar
EUR Euro
Scroll to Top