Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Based Gas Detection System with Wi-Fi Notification

Image of ESP32-Based Gas Detection System with Wi-Fi Notification

Circuit Documentation

Summary

This circuit is designed to monitor gas levels using various gas sensors (MQ2, MQ-4, and MQ-7) and an ESP32 microcontroller. The ESP32 reads the sensor data and sends notifications via the Blynk platform if gas levels exceed a predefined threshold. The circuit is powered by a 12V battery.

Component List

  1. ESP32 (30 pin)

    • Description: A powerful microcontroller with WiFi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  2. MQ2

    • Description: Gas sensor for detecting LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke.
    • Pins: VCC, GND, AOUT, DOUT
  3. MQ-4

    • Description: Gas sensor for detecting methane (CH4).
    • Pins: A0, D0, GND, VCC
  4. MQ-7 Breakout

    • Description: Gas sensor for detecting carbon monoxide (CO).
    • Pins: VCC, GND, DO, AO
  5. Battery 12V

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

Wiring Details

ESP32 (30 pin)

  • D34: Connected to MQ2 AOUT and MQ-4 A0
  • D35: Connected to MQ2 DOUT and MQ-4 D0
  • D25: Connected to MQ-7 Breakout AO
  • D26: Connected to MQ-7 Breakout DO
  • GND: Connected to Battery 12V -, MQ2 GND, MQ-4 GND, and MQ-7 Breakout GND
  • Vin: Connected to Battery 12V +
  • 3V3: Connected to MQ2 VCC, MQ-4 VCC, and MQ-7 Breakout VCC

MQ2

  • AOUT: Connected to ESP32 D34 and MQ-4 A0
  • DOUT: Connected to ESP32 D35 and MQ-4 D0
  • GND: Connected to ESP32 GND, Battery 12V -, MQ-4 GND, and MQ-7 Breakout GND
  • VCC: Connected to ESP32 3V3, MQ-4 VCC, and MQ-7 Breakout VCC

MQ-4

  • A0: Connected to MQ2 AOUT and ESP32 D34
  • D0: Connected to MQ2 DOUT and ESP32 D35
  • GND: Connected to ESP32 GND, Battery 12V -, MQ2 GND, and MQ-7 Breakout GND
  • VCC: Connected to ESP32 3V3, MQ2 VCC, and MQ-7 Breakout VCC

MQ-7 Breakout

  • AO: Connected to ESP32 D25
  • DO: Connected to ESP32 D26
  • GND: Connected to ESP32 GND, Battery 12V -, MQ2 GND, and MQ-4 GND
  • VCC: Connected to ESP32 3V3, MQ2 VCC, and MQ-4 VCC

Battery 12V

  • +: Connected to ESP32 Vin
  • -: Connected to ESP32 GND, MQ2 GND, MQ-4 GND, and MQ-7 Breakout GND

Code

Sketch (sketch.ino)

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Blynk Auth Token
char auth[] = "YourAuthToken";

// Your WiFi credentials
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

// Pin definitions
const int MQ2_DOUT_PIN = 35;
const int MQ2_AOUT_PIN = 34;
const int MQ4_DOUT_PIN = 35;
const int MQ4_AOUT_PIN = 34;
const int MQ7_DOUT_PIN = 26;
const int MQ7_AOUT_PIN = 25;

// Threshold values
const int THRESHOLD = 300;

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);

  pinMode(MQ2_DOUT_PIN, INPUT);
  pinMode(MQ2_AOUT_PIN, INPUT);
  pinMode(MQ4_DOUT_PIN, INPUT);
  pinMode(MQ4_AOUT_PIN, INPUT);
  pinMode(MQ7_DOUT_PIN, INPUT);
  pinMode(MQ7_AOUT_PIN, INPUT);
}

void loop() {
  Blynk.run();

  int mq2_digital = digitalRead(MQ2_DOUT_PIN);
  int mq2_analog = analogRead(MQ2_AOUT_PIN);
  int mq4_digital = digitalRead(MQ4_DOUT_PIN);
  int mq4_analog = analogRead(MQ4_AOUT_PIN);
  int mq7_digital = digitalRead(MQ7_DOUT_PIN);
  int mq7_analog = analogRead(MQ7_AOUT_PIN);

  if (mq2_analog > THRESHOLD || mq4_analog > THRESHOLD || mq7_analog > THRESHOLD) {
    Blynk.notify("Gas level above threshold!");
  }

  delay(1000); // Wait for 1 second before next reading
}

Documentation (documentation.txt)

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// Blynk Auth Token
char auth[] = "YourAuthToken";

// Your WiFi credentials
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

// Pin definitions
const int MQ2_DOUT_PIN = 35;
const int MQ2_AOUT_PIN = 34;
const int MQ4_DOUT_PIN = 35;
const int MQ4_AOUT_PIN = 34;
const int MQ7_DOUT_PIN = 26;
const int MQ7_AOUT_PIN = 25;

// Threshold values
const int THRESHOLD = 300;

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);

  pinMode(MQ2_DOUT_PIN, INPUT);
  pinMode(MQ2_AOUT_PIN, INPUT);
  pinMode(MQ4_DOUT_PIN, INPUT);
  pinMode(MQ4_AOUT_PIN, INPUT);
  pinMode(MQ7_DOUT_PIN, INPUT);
  pinMode(MQ7_AOUT_PIN, INPUT);
}

void loop() {
  Blynk.run();

  int mq2_digital = digitalRead(MQ2_DOUT_PIN);
  int mq2_analog = analogRead(MQ2_AOUT_PIN);
  int mq4_digital = digitalRead(MQ4_DOUT_PIN);
  int mq4_analog = analogRead(MQ4_AOUT_PIN);
  int mq7_digital = digitalRead(MQ7_DOUT_PIN);
  int mq7_analog = analogRead(MQ7_AOUT_PIN);

  if (mq2_analog > THRESHOLD || mq4_analog > THRESHOLD || mq7_analog > THRESHOLD) {
    Blynk.notify("Gas level above threshold!");
  }

  delay(1000); // Wait for 1 second before next reading
}