Circuit Diagram:
MQ2 Gas and Smoke Leak Detection Alarm System with Arduino UNO
Hardware Wire Bus Distribution Index
Wire your MQ2 electrochemical gas sensor, safety indicators, and active audio transducer according to this hardware pin map:
| Peripheral Component Pin | Target Controller Location | Signal System Purpose |
|---|---|---|
| MQ2 Sensor VCC | 5V Power Rail Pin | Internal Heater & Logic Module Main Power Supply |
| MQ2 Sensor AOUT (Analog) | Analog Input Pin A0 | Gas Concentration Variable Voltage Output Bus |
| MQ2 Sensor GND | GND Pin Terminal | Common Circuit Ground Reference |
| Green LED Anode (+) | Digital Pin 2 | Clean Environment Operational Safety Light |
| Red LED Anode (+) | Digital Pin 3 | Active Leak Gas Concentration Hazard Light |
| Piezo Buzzer Positive Wire | Digital Pin 4 | 1000Hz Constant Acoustic Threat Alert Siren |
| LED Cathodes / Buzzer Negative | GND (LEDs via Resistors) | Isolated Common Safety Ground Return Tracks |
⚠️ SENSOR PREHEATING VOLTAGE NOTE: The MQ2 gas sensor utilizes an internal heating coil to induce chemical reduction on its tin dioxide ($SnO_2$) sensing layer. Because this element draws significant current, run your main VCC directly from a stable power terminal to prevent local processing drops on the controller.
System Brief Explanation
- Electrochemical Resistance Conversion: The MQ2 sensor updates its internal resistance based on local gas densities. The board samples this analog voltage fluctuation continually on the 10-bit ADC channel
A0. - Threshold Evaluation Routing: While ambient air values float around
300inside the virtual sandbox, crossing the code threshold limit of400alters the operational flag immediately, disabling the safe green track to flash the hazard alert elements and cycle the audio alarm.
Source Firmware Application
Review the primary C++ code file container block below. The control utilities are hosted inside the top panel frame for instant deployment copying:
📁 mq2_gas_alarm.ino
Arduino C++
// Define Pin Allocations
const int gasSensorPin = A0; // MQ2 Analog pin
const int greenLedPin = 2; // Safe Status LED
const int redLedPin = 3; // Alarm Status LED
const int buzzerPin = 4; // Piezo Alarm
// Set the gas threshold limit
// In Wokwi, default clean air sits around 300.
const int gasThreshold = 400;
void setup() {
// Initialize digital pins as outputs
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Set the gas pin as input
pinMode(gasSensorPin, INPUT);
// Initialize the Serial Monitor
Serial.begin(9600);
Serial.println("--- MQ2 Gas Detection System Active ---");
}
void loop() {
// Read the analog value from the MQ2 sensor
int gasValue = analogRead(gasSensorPin);
// Print value to screen so you can find your ideal threshold
Serial.print("Current Gas Level: ");
Serial.println(gasValue);
// Check if gas levels cross the danger zone
if (gasValue > gasThreshold) {
// DANGER: Gas Detected!
digitalWrite(greenLedPin, LOW); // Turn off green
digitalWrite(redLedPin, HIGH); // Turn on red
// Play a distinct 1000Hz frequency alarm sound
tone(buzzerPin, 1000);
Serial.println("[ALERT] Gas Leak Detected! Alarm sounding!");
}
else {
// SAFE: Normal Environment
digitalWrite(greenLedPin, HIGH); // Green stays on
digitalWrite(redLedPin, LOW); // Red stays off
// Silence the alarm
noTone(buzzerPin);
}
// Wait 300ms before reading again
delay(300);
}
Project Video Demonstration
Watch the smoke detector assess atmospheric levels, output telemetry points to the terminal screen, and sound the safety alert:

Comments
Post a Comment