Gas Sensor IoT Project Using ESP32 and Blynk

This IoT-based gas detection system is designed for real-time monitoring of harmful gases using an ESP32 microcontroller, a gas sensor, and Blynk IoT platform. The setup provides alerts and enables remote control for safety applications in homes, factories, and laboratories.

Hardware Components

  1. ESP32 – Microcontroller with built-in Wi-Fi for IoT communication.
  2. MQ Series Gas Sensor (MQ-2, MQ-135, etc.) – Detects gases like methane, LPG, carbon monoxide, or smoke.
  3. Buzzer – Sounds an alarm if gas levels exceed the threshold.
  4. OLED Display (Optional) – Shows real-time gas concentration.
  5. Relay Module (Optional) – Can trigger ventilation fans in case of high gas concentration.
  6. Power Supply (5V DC) – Provides power to the ESP32 and sensors.

Working Principle

  • The MQ-series gas sensor detects gas concentration and sends analog/digital signals to the ESP32.
  • The ESP32 processes this data and determines if the gas level surpasses a predefined safety threshold.
  • If the gas levels are too high, the system:
    • Activates the buzzer to alert people.
    • Sends notifications to the Blynk IoT app via Wi-Fi.
    • Optionally triggers a fan or ventilation system using a relay module.
  • Real-time data is displayed on an OLED screen (if included).

Connections

ComponentESP32 Pin
Gas Sensor VCC3V3
Gas Sensor GNDGND
Gas Sensor AOUTGPIO34
Gas Sensor DOUTGPIO35
Buzzer PositiveGPIO32
Buzzer GroundGND

CODE

#define BLYNK_TEMPLATE_ID "TMPL3YX0Qp2HY"
#define BLYNK_TEMPLATE_NAME "gas sensor"
#define BLYNK_AUTH_TOKEN "BSxx9fQ5YjSKC_lap_3CBv_0LfycDQIl"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "BSxx9fQ5YjSKC_lap_3CBv_0LfycDQIl";

//Enter your WIFI SSID and password
char ssid[] = "Shivam";
char pass[] = "shivam2724";

#define sensor 34
#define buzzer 23

  
BlynkTimer timer;

 

void setup() {
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
 pinMode(buzzer, OUTPUT);
  pinMode(sensor, INPUT);
}

//Get the ultrasonic sensor values
void GASLevel() {
  int value = analogRead(sensor);
  value = map(value, 0, 4095, 0, 100);

  if (value >= 25) {
    digitalWrite(buzzer, HIGH);
    WidgetLED LED(V1);
    LED.on();
  } else {
    digitalWrite(buzzer, LOW);
    WidgetLED LED(V1);
    LED.off();
  }

  Blynk.virtualWrite(V0, value);
  Serial.println(value);
 
}

void loop() {
  GASLevel();
  Blynk.run();//Run the Blynk library
  delay(200);
}
gas-sensor-IOT

Features & Benefits

Real-time monitoring – Live data collection & alerts.
IoT notifications – Get alerts on your smartphone via Blynk.
Automated safety measures – Can trigger an alarm or ventilation system.
Low-cost & efficient – Uses affordable components for practical applications.

For your gas sensor project on an ESP32 using Blynk, here are the required libraries:

Blynk Library: Facilitates communication with the Blynk IoT platform.
Installation: Open the Arduino IDE Library Manager (Sketch > Include Library > Manage Libraries), search for “Blynk”, and install Blynk by Volodymyr Shymanskyy.
Alternatively, you can download it from the Blynk GitHub repository.

WiFi Library: For connecting the ESP32 to Wi-Fi.
This is included with the ESP32 board support package in Arduino. To install or update it, go to Tools > Board > Boards Manager, search for ESP32, and install or update the package.
Blynk Timer: This is part of the Blynk library and enables interval-based tasks.

Summary of Libraries:
Blynk by Volodymyr Shymanskyy
WiFi (part of the ESP32 core package)
With these libraries, your code should compile successfully and enable communication between the ESP32, gas sensor, buzzer, and Blynk IoT platform.

Leave a Reply

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

More Articles & Posts