← All Projects

Gas Leak Detection System with MQ-2 Sensor

275 viewsFebruary 20, 2026
ArduinoMQ-2GasSafetyBuzzerLED

A safety-critical gas leak detection system using the MQ-2 smoke and gas sensor. Detects LPG, propane, methane, and smoke. Triggers an audible alarm via buzzer and a visual LED alert when gas concentration exceeds the set threshold.

Components & Supplies

×1Arduino Uno R3
×1MQ-2 Gas/Smoke Sensor
×1Active Buzzer
×1Red LED (5mm)
×1220Ω Resistor
×1Breadboard

Circuit Connections

ComponentPinPinComponent
ArduinoA0AOUTMQ-2
Arduino5VVCCMQ-2
ArduinoGNDGNDMQ-2
ArduinoD7+Buzzer
ArduinoGND-Buzzer
ArduinoD13Anode (+)LED
ArduinoGNDCathode (-)LED

Overview

The MQ-2 sensor detects combustible gases and smoke. Its analog output voltage increases proportionally with gas concentration. This project reads the analog value, compares it to a calibrated threshold, and activates both a buzzer and a red LED when dangerous levels are detected.

The serial monitor also logs readings continuously for data analysis. This is a foundational project for home safety and IoT smoke detection systems.

Safety & Calibration

Important safety notes:

  • The MQ-2 needs a 24-48 hour burn-in period on first use for accurate readings.
  • Allow 2-3 minutes warm-up each time you power on before trusting readings.
  • The threshold value (400 in this sketch) should be calibrated based on your environment. Test with a lighter (without flame) to simulate gas.
  • This is a hobby project — do NOT rely on it as your sole gas safety device.
arduinoGas Detector Sketch
const int mq2Pin = A0;
const int buzzerPin = 7;
const int ledPin = 13;
const int threshold = 400;

void setup() {
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.println("MQ-2 Gas Detector Starting...");
  Serial.println("Warming up sensor (2 min)...");
  delay(120000);
  Serial.println("Ready!");
}

void loop() {
  int gasValue = analogRead(mq2Pin);
  Serial.print("Gas Level: ");
  Serial.println(gasValue);

  if (gasValue > threshold) {
    Serial.println("*** GAS LEAK DETECTED! ***");
    digitalWrite(ledPin, HIGH);
    // Alarm pattern
    for (int i = 0; i < 5; i++) {
      digitalWrite(buzzerPin, HIGH);
      delay(200);
      digitalWrite(buzzerPin, LOW);
      delay(100);
    }
  } else {
    digitalWrite(ledPin, LOW);
    digitalWrite(buzzerPin, LOW);
  }

  delay(1000);
}