Community project

Mini Gas Leak Alarm

Photo of Mini Gas Leak Alarm
Generated with AI

Aki

Published November 25, 2026

This Arduino-based gas leak alarm monitors air quality using an MQ-2 gas sensor and sounds a piezo buzzer when gas levels rise above a baseline threshold. The project includes a TMP36 temperature sensor for environmental monitoring and status LEDs to indicate system state. Builders will receive a complete wiring diagram, parts list, step-by-step assembly instructions, and Arduino firmware with serial output for real-time sensor readings.

The guide covers sensor warm-up procedures, baseline calibration in clean air, and manual alarm demonstration. This educational project teaches sensor interfacing, analog signal processing, and alarm logic on the Arduino Uno platform. Note that this is a relative-response demonstration system rather than a calibrated gas concentration detector.

Wiring diagram

Wiring diagram for Mini Gas Leak Alarm
Loading diagram…

Gather all the parts

QtyComponent
1

MQ-2 Gas Sensor

Analog combustible-gas and smoke sensor module. Detects LPG, propane, methane, hydrogen, alcohol, and smoke using a heated tin-dioxide (SnO2) sensing element whose resistance falls as gas concentration rises. The breakout board provides an analog output (AO) proportional to concentration plus a digital output (DO) that trips when concentration crosses an onboard potentiometer threshold. Requires a 5 V supply for the internal heater and a 20-30 s warm-up before readings stabilise; the AO voltage is relative, so the sensor needs a clean-air baseline calibration rather than reporting an absolute ppm value.

1

TMP36 TO-92 temperature sensor

2.7–5.5V analog sensor; output 500mV + 10mV per degree Celsius.

1

Piezo Buzzer

Small passive piezo buzzer (TDK PS1240) for beeps, tones and alerts. It has no built-in oscillator, so drive one lead with a 3-30 V square wave from a microcontroller pin using tone() or PWM and connect the other lead to ground. It is loudest around 4 kHz and works from about 2 to 10 kHz; driving both leads in antiphase roughly doubles the volume.

1

LED

red

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

330 Ω

Through-hole resistor (current-limiting in series with an LED)

1

LED

green

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

330 Ω

Through-hole resistor (current-limiting in series with an LED)

Assemble it in 5 steps

1. Check the chosen parts

This build uses an Arduino Uno, a four-pin MQ-2 module, a TMP36 TO-92 temperature sensor and a small passive piezo buzzer. Use a breadboard and jumper wires; unplug USB before wiring.

  • Educational prototype only. Use a certified gas alarm for protection. MQ-2 responds to several combustible gases and smoke; it cannot identify which gas is present. Do not test with a lighter or deliberately release gas.

2. Connect the gas module

MQ-2 VCC → Uno 5V (power), GND → GND (return), AO → A0 (gas reading). Leave DO disconnected. Follow printed labels, not pin position. This is a module, not the bare six-legged sensor.

  • The sensor heater gets hot. Keep it clear of flammable materials; never operate this unprotected prototype in a potentially explosive atmosphere.

3. Connect the temperature sensor

For the TMP36 TO-92, with its flat printed face toward you and legs pointing down: left → 5V (power), middle → A1 (temperature), right → GND (return). Keep it away from the MQ-2 heater.

  • This wiring is only for TMP36, not an unidentified temperature sensor. Reversed power can damage it.

4. Connect the buzzer and both LEDs

Piezo SIG → D9 (sound), other lead → GND. D6 → existing 330 Ω resistor → red LED long leg (positive); red short leg → GND. D7 → a second 330 Ω resistor → green LED long leg; green short leg → GND. Each LED needs its own resistor.

  • Use a passive piezo, not a high-current magnetic buzzer directly on the pin.

5. Warm up and manually enable the demonstration alarm

Power through USB. Condition a new MQ-2 in clean air for at least 48 hours. After each restart wait at least three minutes and until gas_raw readings stabilize. Open serial output at 9600 baud. Only in known clean air, send C to store the current baseline and enable gas monitoring. This baseline is lost on restart. Green means powered, not ready or safe. Red and buzzer pulse when gas_raw rises 100 counts above baseline; they clear below baseline plus 50. TMP36 readings are displayed only and no longer trigger the buzzer. There is no startup beep.

  • The relative thresholds are demonstration settings, not ppm or validated butane safety limits. MQ-2 responds to several gases and smoke; it cannot identify butane. Calibration with known test gas and proper equipment is needed for quantitative detection.
  • Never set a baseline in suspected contaminated air; this could hide gas. Gas alarm is disabled until you send C after warm-up. Never release lighter fuel or use a flame to test this project.
  • If TMP36 physically gets hot, disconnect power and fix its wiring even though its reading no longer triggers the alarm.
  • No battery backup or guaranteed fault detection. Use a certified detector for safety. If you suspect a leak, leave and follow local emergency guidance.

Review all connections

1. Connections between "gas" and "Arduino"

FunctiongasArduino
powerVCC5V
groundGNDGND
analogAOGPIO 14

2. Connections between "temp" and "Arduino"

FunctiontempArduino
powerVCC5V
analogOUTGPIO 15
groundGNDGND

3. Connections between "sound" and "Arduino"

FunctionsoundArduino
pwmSIGGPIO 9
groundGNDGND

4. Connections between "led_resistor" and "Arduino"

Functionled_resistorArduino
digitalP1GPIO 6
digitalP2 → LED ANODEEXT

5. Connections between "light" and "Arduino"

FunctionlightArduino
groundGNDGND

6. Connections between "green_resistor" and "Arduino"

Functiongreen_resistorArduino
digitalP1GPIO 7
digitalP2 → LED ANODEEXT

7. Connections between "green_light" and "Arduino"

Functiongreen_lightArduino
groundGNDGND

Deploy the firmware

#include <Arduino.h>
// Educational relative-response alarm, not a calibrated concentration detector.
const unsigned long WARMUP_MS = 180000UL;
const int RISE_ON = 100, RISE_OFF = 50;
unsigned long lastSample = 0;
int gas = 0, baseline = 0;
bool armed = false, alarm = false;
void setup() {
  pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(9, OUTPUT);
  digitalWrite(6, LOW); digitalWrite(7, HIGH); noTone(9);
  Serial.begin(9600);
  Serial.println(F("DEMO MQ2 gas-only alarm. TMP36 is display-only."));
  Serial.println(F("Condition new sensor >=48h. Warmup >=3min; wait for stable readings."));
  Serial.println(F("In known clean air ONLY, send C to set baseline and arm. No lighter tests."));
}
void loop() {
  unsigned long now = millis();
  if (now - lastSample >= 250) {
    lastSample = now;
    analogRead(A0); gas = analogRead(A0);
    analogRead(A1);
    float c = (analogRead(A1) * (5.0f / 1023.0f) - 0.5f) * 100.0f;
    if (armed) {
      if (gas >= baseline + RISE_ON) alarm = true;
      if (gas <= baseline + RISE_OFF) alarm = false;
      if (gas >= 1000 || gas <= 5) alarm = true;
    }
    Serial.print(F("gas_raw=")); Serial.print(gas);
    Serial.print(F(" temp_C=")); Serial.print(c, 1);
    Serial.print(F(" baseline=")); Serial.print(baseline);
    Serial.println(now < WARMUP_MS ? F(" WARMING: alarm disabled") :
      !armed ? F(" NOT ARMED: stable clean air, send C") :
      alarm ? F(" ALARM: gas rise or sensor fault") : F(" MONITORING (demo)"));
  }
  while (Serial.available()) {
    char command = Serial.read();
    if (command == 'C' || command == 'c') {
      if (now < WARMUP_MS) Serial.println(F("Wait for warmup and stable clean-air readings."));
      else if (gas <= 5 || gas > 850) Serial.println(F("Baseline rejected: check sensor and clean air."));
      else {
        baseline = gas; armed = true; alarm = false;
        Serial.println(F("Baseline set. Relative thresholds +100 ON, +50 OFF; NOT ppm."));
      }
    }
  }
  bool pulse = alarm && now % 500 < 250;
  digitalWrite(6, pulse);
  static bool sounding = false;
  if (pulse != sounding) {
    sounding = pulse;
    if (sounding) tone(9, 4000); else noTone(9);
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik