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.
ESP32 (30 pin)
MQ2
MQ-4
MQ-7 Breakout
Battery 12V
#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
}
#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
}