Build a Gas Leakage Detector Alarm
LPG cylinders are used in most homes in Bangladesh, so a gas alarm is a genuinely useful project. The MQ-2 sensor detects LPG, smoke and methane, and the Arduino sounds an alarm when the level rises.
What You Need:
- 1x Arduino Uno R3 or Arduino Nano
- 1x MQ-2 Gas Sensor Module
- 1x 5V buzzer
- 1x Red LED + 220Ω resistor
- 1x 5V Relay (optional, for a DC exhaust fan)
- Jumper Wires
1. Wiring
- MQ-2 VCC → 5V, GND → GND, A0 → A0
- Buzzer + → D8, LED → D7, relay IN → D6
2. The Code
const int threshold = 400; // adjust after testing
void setup() {
Serial.begin(9600);
pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
delay(20000); // MQ-2 needs time to heat up
}
void loop() {
int gas = analogRead(A0);
Serial.println(gas);
bool danger = gas > threshold;
digitalWrite(7, danger);
digitalWrite(6, danger ? LOW : HIGH); // fan on
if (danger) { tone(8, 2000, 300); }
delay(500);
}3. Calibration
Leave the sensor powered for a few minutes in clean air and note the Serial Monitor value. Set threshold about 150 above that. Test carefully with a lighter's gas (unlit) held near the sensor.
Important: This is a learning project, not a certified safety device. Keep proper ventilation in your kitchen.
Need help? Stuck on wiring or code? Message us on WhatsApp at +880 1577-098376 and we will help you with your project.
