Protect your kitchen or workshop: this MQ-2 based detector sounds a loud alarm and lights a red LED the moment it sniffs LPG, smoke or other combustible gases.
What you’ll build
The MQ-2 sensor outputs a voltage that rises with gas concentration. The Arduino Nano compares it against a calibrated threshold and, when exceeded, drives an active buzzer and red LED. A green LED shows the air is clean.
Components you’ll need
| Component | Qty | Price |
|---|---|---|
| Arduino Nano ATmega328P Compatible Board | 1 | ₹149 |
| Gas Sensor MQ-2 | 1 | ₹99 |
| Active Buzzer | 1 | ₹299 |
| 5mm Red LED | 1 | ₹149 |
| 5mm Green LED | 1 | ₹19 |
| 220 Ohm 1/4W | 2 | ₹98 |
| 400 Point Breadboard | 1 | ₹299 |
| Total | ₹1,112 |
Step-by-step guide
- Wire the MQ-2: VCC to 5V, GND to GND, A0 to the Nano’s A0. Let it pre-heat for 2–3 minutes before trusting readings.
- Connect the buzzer to D8 and GND.
- Wire the red LED to D9 and the green LED to D10, each through a 220Ω resistor to GND.
- Upload the sketch and open the Serial Monitor to watch the baseline reading in clean air.
- Briefly press an unlit lighter near the sensor — the reading should spike and the alarm fire.
- Set THRESHOLD roughly 100–150 points above your clean-air baseline and re-upload.
The code
Clean-air baselines differ between sensors, so calibrate THRESHOLD using the Serial Monitor before relying on the alarm.
const int mq2=A0, buzzer=8, redLed=9, greenLed=10;
const int THRESHOLD = 400; // calibrate in clean air first!
void setup(){
pinMode(buzzer,OUTPUT); pinMode(redLed,OUTPUT); pinMode(greenLed,OUTPUT);
Serial.begin(9600);
}
void loop(){
int gas = analogRead(mq2);
Serial.println(gas);
bool danger = gas > THRESHOLD;
digitalWrite(redLed, danger);
digitalWrite(greenLed, !danger);
digitalWrite(buzzer, danger);
delay(300);
}Build this project
Add all 7 required components to your cart in one click — total ₹1,112.
Add all components to cart