LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsUse the ultrasonic sensor as a tripwire: if the distance in front of it changes suddenly, sound the alarm. A plain distance threshold would fire at anything closer than, say, 50 cm, including a wall. Instead the sketch records a baseline when it starts and then watches for change. If a new reading differs from the baseline by more than the tolerance, something has moved into the beam. abs() is used so the alarm reacts whether the object came closer or moved away.
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
HC-SR04 ultrasonic distance 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_028_motion_detection_alarm.inoVerify & upload in Electrolarkint trigPin = 32;
int echoPin = 5;
int buzzer = 33;
int led = 25;
long baseline = 0;
int tolerance = 15; // cm of change that counts as movement
long readDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2;
}
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
delay(2000); // Stand clear while it calibrates
baseline = readDistance();
Serial.print("Baseline distance: ");
Serial.println(baseline);
}
void loop()
{
long distance = readDistance();
long change = abs(distance - baseline);
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" Change: ");
Serial.println(change);
if (change > tolerance)
{
for (int i = 0; i < 5; i++)
{
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
delay(120);
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
delay(120);
}
}
delay(150);
}
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.
Point the sensor at a flat object 5 to 200 cm away, check TRIG and ECHO are not swapped, and that ECHO goes through the 1k and 2k divider.
A plain distance threshold would fire at anything closer than, say, 50 cm, including a wall. Instead the sketch records a baseline when it starts and then watches for change. If a new reading differs from the baseline by more than the tolerance, something has moved into the beam. abs() is used so the alarm reacts whether the object came closer or moved away.
Serial Monitor prints the baseline once at startup. Distance and Change print continuously. Wave your hand across the beam: the buzzer pulses five times and the LED flashes.
Yes. It is project 28 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.
10 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, HC-SR04 Ultrasonic Range Finder Sensor Module for Arduino, Carbon Film Resistor 1/4W 5% (Pack of 10) and ESP32 38-Pin Expansion Board. 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 6 steps.
No. This page has the complete, tested code (titan_kit_028_motion_detection_alarm.ino).
About ₹818 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Ultrasonic distance thresholds; Calibrating a baseline at startup; Detecting change rather than absolute value; Using abs() for two-sided comparison.
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.