LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsRead an MQ2 gas sensor and raise an audible alarm when smoke or combustible gas appears. Inside the MQ2 is a tin-dioxide element whose resistance falls when certain gases touch it. The module converts that into a voltage on AO, so the reading climbs as the air gets dirtier. The sensor's heater needs about twenty seconds to stabilise after power-up, which is why the sketch shows a warming-up message before it starts judging anything.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
LEDs from the kit's red, green, yellow and blue packs
220 ohm resistors: one in series with every LED
16x2 LCD with I2C backpack: four wires, two lines of text
MQ-2 smoke and gas sensor
1k and 2k resistors: drop a 5V signal to the 3.3V an ESP32 pin can take
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_030_smoke_detection_alarm.inoVerify & upload in Electrolark#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int gasPin = 34;
int buzzer = 33;
int led = 25;
int alarmLevel = 400;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
analogReadResolution(10); // ESP32 is 12-bit; use 0-1023 like the examples
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Warming up...");
for (int i = 20; i > 0; i--)
{
lcd.setCursor(0, 1);
lcd.print(i);
lcd.print(" s ");
delay(1000);
}
lcd.clear();
}
void loop()
{
int gasLevel = analogRead(gasPin);
Serial.print("Gas level: ");
Serial.println(gasLevel);
lcd.setCursor(0, 0);
lcd.print("Gas: ");
lcd.print(gasLevel);
lcd.print(" ");
lcd.setCursor(0, 1);
if (gasLevel > alarmLevel)
{
lcd.print("!! SMOKE ALARM !!");
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
delay(200);
}
else
{
lcd.print("Air: Clean ");
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
delay(500);
}
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
Turn it round: the long leg (anode) goes to the GPIO side through the 220 ohm resistor, the short leg to GND.
The active buzzer has a + leg: it goes to the GPIO, the other to GND. Peel off the sticker on top if it has one.
Turn the small contrast pot on the back of the I2C board. If still blank, change 0x27 in the sketch to 0x3F.
Inside the MQ2 is a tin-dioxide element whose resistance falls when certain gases touch it. The module converts that into a voltage on AO, so the reading climbs as the air gets dirtier. The sensor's heater needs about twenty seconds to stabilise after power-up, which is why the sketch shows a warming-up message before it starts judging anything.
A 20-second countdown while the sensor heats up. Gas: 180 / Air: Clean in normal room air. Hold a blown-out match near the sensor: the value jumps and !! SMOKE ALARM !! appears with a pulsing buzzer.
Yes. It is project 30 of 120 in the Geekobot Titan Kit, in level 6 (Security and access). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
11 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), PCB Mounted Active Buzzer Module, LCD1602 16x2 Character LCD Display, Generic MQ-2 Smoke LPG Butane Hydrogen Gas Sensor Module – 5V Analog/Digital Output, Carbon Film Resistor 1/4W 5% (Pack of 10), plus 1 more. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 30 minutes. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_030_smoke_detection_alarm.ino).
About ₹951 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Gas sensor analog reading; Why chemical sensors need a warm-up period; Setting an alarm level from observed values; Displaying a live number alongside a status.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
See the smoke level live on a crisp screen and get a loud warning when it spikes.
An infrared eye that spots an open flame and raises the alarm.
Walk into the room and it sounds the alarm: the classic first security build.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.