Gas Sensor (MQ-2): Build a Gas Leak Alarm, Demo It Safely

· 4 min read · Sensors Beginner12+ with adult

Author: Tekko BD Team

What the MQ-2 gas sensor detects, why burn-in matters, the buzzer alarm circuit and code, plus the rules that keep a science-fair demo safe.

A cylinder leaking in the kitchen, fumes in the garage. Many accidents like these would end sooner if a cheap sensor could shout in time. At hobby level, the MQ-2 gas sensor does that job. It detects LPG, propane, methane, hydrogen, alcohol vapour and smoke. In this project we build a gas leak detector around it: gas or smoke arrives, a buzzer sounds.

Warning

This is a learning project, not a certified safety device. Real protection needs certified detectors. And for the demo: never use open flame or a live gas stream — follow the "safe test" rules below, and keep an adult nearby.

What you need

  • MQ-2 gas sensor module
  • Active buzzer module (or passive + tone code)
  • Arduino Uno
  • Jumper wires
  • Test gas or smoke: see "The safe test" below
MQ2 Gas / Smoke SensorMQ2 Gas / Smoke Sensor৳170View details
Active Buzzer Module - YL44Active Buzzer Module - YL44৳60View details
Arduino UNO R3Arduino UNO R3৳910View details
Jumper Wire Kit (M-M)Jumper Wire Kit (M-M)৳90View details

Prices can change; check Tekko for the latest.

How the gas sensor works

Inside the MQ-2 sits a heated tin-dioxide (SnO₂) sensing layer. In clean air its resistance is high. Combustible gas molecules lower it, and the module turns that change into an analog voltage on A0. The sensor only works while its heater is on, which is why the module feels warm to the touch. That is normal.

MQ-2 pinout: VCC, GND, D0, A0
MQ-2 pins: VCC, GND, D0 (digital), A0 (analog)

Gas sensor burn-in: where most projects go wrong

A fresh MQ-2 reads all over the place. The rule: before first use, power the sensor on its own for 24–48 hours, no circuit needed. That is burn-in. Before every measurement, also let it warm up for at least 10–15 minutes. Skip this and nobody can tell you when the alarm will fire on fair day.

Step — wiring and code

MQ-2: VCC → 5V, GND → GND, A0 → A0. Buzzer: + → pin 8, − → GND.

cpp
const int GAS = A0;
const int BUZZ = 8;
const int ALARM_AT = 400;   // set from your measured baseline

void setup() {
  pinMode(BUZZ, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int value = analogRead(GAS);
  Serial.println(value);

  if (value > ALARM_AT) {
    digitalWrite(BUZZ, HIGH);        // gas or smoke!
  } else {
    digitalWrite(BUZZ, LOW);
  }
  delay(200);
}

Watch the Serial Monitor for 10–15 minutes while the sensor warms up. The range it settles in (e.g. 120–200) is your baseline. Set ALARM_AT at around twice the baseline.

To compare your wiring, Tekko Sim runs a version of this circuit free in the browser. It has an LED next to the buzzer.

Tekko Sim gas-leakage-detector circuit: Uno and MQ-2
gas-leakage-detector: the MQ-2's A0 into an Uno analog input, with a buzzer and LED

The safe test — demo rules

  • Safe: one short spray of deodorant from a few feet away, or one short press of an unlit gas lighter near the sensor — no flame anywhere in the room. Nothing more is needed; the reading jumps within seconds.
  • Not safe: testing a cylinder leak, burning anything to make smoke, lighting a lighter, pouring solvent. Open a window on demo day.

Verify it works

The baseline sits steady with a small wobble. When the safe test gas arrives the number jumps, crosses ALARM_AT, and the buzzer sounds. Fan the air and the number falls and the buzzer stops.

Common problems

  1. Pinned at 1023, never comes down — burn-in not done, or the wrong heater voltage. Leave it powered for 24 hours and look again.
  2. No response at all — check you did not mix up A0 and D0. The code reads A0, so the wire goes to A0, not D0.
  3. Alarms in a still room — threshold too low, or cooking vapour or perfume near the sensor. Raise ALARM_AT and put the sensor in open air.
  4. Numbers slowly decay — the sensor is cooling. Keep it powered for the whole measurement.

One box instead

Rather not gather the parts one by one? The Gas Leakage Detector Kit packs the MQ-2, buzzer and connecting parts together. The kit page lists exactly what is and is not in the box.

FAQ

Does the MQ-2 detect carbon monoxide? Not reliably. That is the MQ-7's job. The MQ-2 is better with combustible gases and smoke.

Does the heater really stay on all the time? The heater is what makes the sensor work, and it draws ≈150 mA. On a battery project, power it only while measuring.

What does the D0 potentiometer do? It sets the threshold of the module's own comparator, so D0 flips high or low without any Arduino. We read analog and choose the limit in code, so we do not need it.

More from Tekko

Sources

  • Module silkscreen markings and standard SnO₂ practice; ask on WhatsApp for the datasheet.

Want it as one kit?

Gas Leakage Detector Kit (MQ-2) — An MQ-2 sensor reads LPG and smoke in the air. Above the limit set in the code, the Arduino lights a red LED and sounds a buzzer.

See the kit

Try it free before you buy

This project runs free in Tekko Sim, right in your browser — before you spend a taka.

Gas Leakage Detector using Arduino (MQ-2) — Run in Sim

#sensor#mq2#gas#science-fair#arduino