LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsWork out how fast something is moving by measuring how much the distance changed and how long that took. Speed is change in distance divided by change in time, the definition of a rate, and the first derivative in disguise. Working in signed values keeps the direction: a negative speed means the object is approaching, a positive one that it is retreating. Because dividing two noisy numbers amplifies noise badly, the interval is kept at a full 100 ms and the result is heavily smoothed; a shorter interval gives a faster but far wilder reading.
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_097_object_speed_estimator.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int trigPin = 32, echoPin = 5;
int greenLed = 27, redLed = 26, buzzer = 33;
float lastDistance = 0;
unsigned long lastTime = 0;
float speedCmS = 0;
float fastestApproach = 0;
float readDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH, 30000);
if (duration == 0) return -1;
return duration * 0.0343 / 2.0;
}
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) { } }
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
lastDistance = readDistance();
lastTime = millis();
}
void loop()
{
float distance = readDistance();
if (distance < 0)
{
delay(80);
return;
}
unsigned long now = millis();
unsigned long elapsed = now - lastTime;
if (elapsed >= 100)
{
float change = distance - lastDistance; // cm
float seconds = elapsed / 1000.0;
float instant = change / seconds; // cm per second
// Heavy smoothing - dividing noisy numbers is noisy
speedCmS = speedCmS * 0.7 + instant * 0.3;
lastDistance = distance;
lastTime = now;
if (-speedCmS > fastestApproach)
{
fastestApproach = -speedCmS;
}
Serial.print("Distance ");
Serial.print(distance, 1);
Serial.print(" speed ");
Serial.println(speedCmS, 1);
}
bool approaching = (speedCmS < -3);
bool retreating = (speedCmS > 3);
digitalWrite(redLed, approaching);
digitalWrite(greenLed, retreating);
if (approaching && abs(speedCmS) > 40 && (millis() / 400) % 2 == 0)
{
tone(buzzer, 1600, 120);
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("SPEED ESTIMATOR");
display.setTextSize(2);
display.setCursor(0, 12);
display.print(abs(speedCmS), 0);
display.setTextSize(1);
display.print(" cm/s");
display.setCursor(0, 32);
display.print("= ");
display.print(abs(speedCmS) * 0.036, 2);
display.print(" km/h");
display.setCursor(0, 42);
display.print("Distance ");
display.print(distance, 0);
display.print("cm");
display.setCursor(0, 52);
if (approaching) display.print("<<< APPROACHING");
else if (retreating) display.print("RETREATING >>>");
else display.print("Stationary");
display.setCursor(80, 52);
display.print("pk ");
display.print(fastestApproach, 0);
display.display();
}
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.
This project needs the passive buzzer (the one that plays notes), not the active one.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Speed is change in distance divided by change in time, the definition of a rate, and the first derivative in disguise. Working in signed values keeps the direction: a negative speed means the object is approaching, a positive one that it is retreating. Because dividing two noisy numbers amplifies noise badly, the interval is kept at a full 100 ms and the result is heavily smoothed; a shorter interval gives a faster but far wilder reading.
A still object shows Stationary with a speed near zero. Move your hand towards the sensor: <<< APPROACHING with the red LED. Move it away: RETREATING >>> with the green LED.
Yes. It is project 97 of 120 in the Geekobot Titan Kit, in level 14 (Distance). 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), 2 × Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), Buzzer Module 3.3–5V, 0.96" OLED Display 128x64, HC-SR04 Ultrasonic Range Finder Sensor Module for Arduino, 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 45 minutes. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_097_object_speed_estimator.ino).
About ₹961 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Delta distance over delta time, velocity; Signed values to preserve direction; Why dividing noisy readings needs heavy smoothing; Tracking a peak approach speed.
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.