Gas Sensor (MQ-2): Build a Gas Leak Alarm, Demo It Safely
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
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.
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.
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.
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
- Pinned at 1023, never comes down — burn-in not done, or the wrong heater voltage. Leave it powered for 24 hours and look again.
- 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.
- 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.
- 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
- Sensors category — the whole MQ series, including MQ-2 and MQ-7
- Modules category — buzzers, relays, displays
- Kits category — ready-packed projects
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 kitTry 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


