Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32 and MQ-2 Gas Sensor with Wi-Fi Notification and Battery Power

View and Edit Project In Cirkit DesignerImage of ESP32 and MQ-2 Gas Sensor with Wi-Fi Notification and Battery Power

Circuit Documentation

Summary

This circuit is designed to detect gas leakage using an MQ-2 gas sensor and an ESP32 microcontroller. When gas is detected above a certain threshold, a buzzer is activated, and a notification is sent via the Blynk platform. The circuit is powered by a 12V battery and includes a TP4056 module for charging a 18650 Li-Ion battery.

Component List

  1. MQ-2 Gas Sensor

    • Description: Gas sensor for detecting LPG, i-butane, propane, methane, alcohol, Hydrogen, and smoke.
    • Pins: GND, VCC, ANALOG, Digital
  2. ESP32 Microcontroller

    • Description: A low-power system on a chip microcontroller with integrated Wi-Fi and dual-mode Bluetooth.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
  3. Buzzer

    • Description: An audio signaling device.
    • Pins: GND, IN
  4. 18650 Li-Ion Battery

    • Description: Rechargeable lithium-ion battery.
    • Pins: Positive, Negative
  5. TP4056 Charging Module

    • Description: Lithium battery charger module with overcharge protection.
    • Pins: OUT-, B-, B+, OUT+, IN-, IN+
  6. 12V Battery

    • Description: Power source for the circuit.
    • Pins: -, +

Wiring Details

MQ-2 Gas Sensor

ESP32 Microcontroller

Buzzer

18650 Li-Ion Battery

TP4056 Charging Module

12V Battery

Code Documentation

#define BLYNK_TEMPLATE_ID "YourTemplateID"
#define BLYNK_DEVICE_NAME "YourDeviceName"
#define BLYNK_AUTH_TOKEN "YourAuthToken"

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "YourSSID";
char pass[] = "YourPassword";

const int gasSensorPin = 34; // Analog pin connected to MQ-2 A0
const int buzzerPin = 25;    // Digital pin connected to Buzzer Signal
const int threshold = 300;   // Threshold value for gas detection

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pinMode(gasSensorPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  Blynk.run();
  int gasLevel = analogRead(gasSensorPin);
  Serial.print("Gas Level: ");
  Serial.println(gasLevel);

  if (gasLevel > threshold) {
    digitalWrite(buzzerPin, HIGH);
    Blynk.notify("Gas Leakage Detected!");
  } else {
    digitalWrite(buzzerPin, LOW);
  }
}

This code initializes the ESP32 microcontroller, connects it to a Wi-Fi network, and sets up the Blynk platform for remote notifications. The gas sensor's analog output is read, and if the gas level exceeds a predefined threshold, the buzzer is activated, and a notification is sent via Blynk.