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.
Every part for this build comes in the Geekobot Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 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.
The brain of every Explorer Kit project
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 segment
HC-SR04 ultrasonic distance sensor
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
explorer_kit_28_motion_alarm.inoVerify & upload in Electrolarkint trigPin = 9;
int echoPin = 10;
int buzzer = 8;
int led = 7;
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 the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
Turn it round: the long leg (anode) goes to the pin side through the 220 ohm resistor, the short leg to GND.
The active buzzer has a + leg: it goes to the pin, 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 and check TRIG and ECHO are not swapped.
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 61 in the Geekobot Explorer 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 Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
8 parts: Generic Nano CH340 Development Board (Soldered), USB Cable, 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 and Arduino Nano IO Expansion Shield (328P Compatible). 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 (explorer_kit_28_motion_alarm.ino).
About ₹542 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.
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.