Build it step by step
0 of 5 doneBurn in the sensor
A new MQ-2 should be powered for a few hours before its readings settle.
Wire the sensor
VCC, GND and AO to A0. The sensor gets warm: that is the heater.
Wire the outputs
Buzzer on D8, red LED on D9, green LED on D10, each LED with 220 Ω.
Upload in clean air
Upload and wait for the 60 s warm-up. Note the baseline in the serial monitor.
Test safely
Hold an unlit lighter near the sensor and press the button for one second, away from flames. The alarm should sound.
How do you build an LPG gas leak alarm?
An MQ-2 sensor watches the air near a gas cylinder and sounds a buzzer and red light when the reading rises. You need Arduino Uno R3, MQ-2 gas and smoke sensor module, Active buzzer 5 V, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, 5 V 2 A USB adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 5 steps and about 50 minutes.
- Level
- Beginner
- Time
- About 50 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- SensorsBuy
- Motors & ActuatorsBuy
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm green × 1
- PassivesBuyResistor 220 Ω × 2
- PowerBuyThe heater draws about 150 mA
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| MQ-2 VCC / GND | Uno 5V / GND | Heater and sensor power |
| MQ-2 AO | Uno A0 | Gas level |
| Uno D8 | Buzzer + (buzzer − to GND) | Alarm sound |
| Uno D9 | 220 Ω, red LED, GND | Alarm light |
| Uno D10 | 220 Ω, green LED, GND | Normal light |
Code
Arduino IDE, board "Arduino Uno". No extra libraries. Start it in clean air, because the first reading becomes the baseline.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int GAS = A0, BUZZER = 8, RED = 9, GREEN = 10;
int baseline = 0;
const int MARGIN = 150; // how far above clean air counts as a leak
void setup() {
pinMode(BUZZER, OUTPUT); pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT);
Serial.begin(9600);
Serial.println("Warming up for 60 s...");
for (int i = 0; i < 60; i++) { digitalWrite(GREEN, i % 2); delay(1000); }
long sum = 0;
for (int i = 0; i < 20; i++) { sum += analogRead(GAS); delay(100); }
baseline = sum / 20;
Serial.print("Clean air baseline: "); Serial.println(baseline);
}
void loop() {
int v = analogRead(GAS);
bool leak = v > baseline + MARGIN;
digitalWrite(GREEN, !leak); digitalWrite(RED, leak);
digitalWrite(BUZZER, leak && (millis() / 250) % 2); // beeping, not a constant tone
Serial.print("gas="); Serial.print(v); Serial.println(leak ? " LEAK" : "");
delay(100);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Warming up for 60 s...
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| During warm-up | Green LED blinks once a second |
| Clean air after warm-up | Green LED on, reading close to the baseline |
| Unlit lighter gas near the sensor | Reading rises by 200 or more, red LED and beeping buzzer |
| Gas cleared | Back to green within 30 to 60 s |
If it does not work
The alarm goes off at start-up
It was not warmed up or started in dirty air. Restart in fresh air.
Very slow response
Check the module's heater is warm. A cold sensor means no 5 V.
Reading stuck at 1023
AO and DO swapped, or the module's sensitivity trimmer is at one end.
This is a learning project
For a real kitchen, also fit a certified LPG detector. Never test with an open flame.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the LPG gas leak alarm?
Arduino Uno R3, MQ-2 gas and smoke sensor module, Active buzzer 5 V, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, 5 V 2 A USB adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). 5 V 2 A USB adapter: The heater draws about 150 mA.
How long does the LPG gas leak alarm take to build?
About 50 minutes for a beginner maker, in 5 steps.
How do I know the LPG gas leak alarm works?
During warm-up: Green LED blinks once a second. Clean air after warm-up: Green LED on, reading close to the baseline. Unlit lighter gas near the sensor: Reading rises by 200 or more, red LED and beeping buzzer.
The alarm goes off at start-up: what should I check?
It was not warmed up or started in dirty air. Restart in fresh air.
Very slow response: what should I check?
Check the module's heater is warm. A cold sensor means no 5 V.
Reading stuck at 1023: what should I check?
AO and DO swapped, or the module's sensitivity trimmer is at one end.
This is a learning project: what should I check?
For a real kitchen, also fit a certified LPG detector. Never test with an open flame.
