LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsMeasure a person's height by mounting the sensor above them and subtracting their head clearance from the mounting height. Sound travels about 343 metres per second at room temperature, which is 0.0343 cm per microsecond, and the pulse makes a round trip, hence the division by two. That speed changes with temperature by roughly 0.6 m/s per degree, so the sketch includes the correction. Taking the median of nine readings rather than the average is deliberate: a single wild reflection would drag an average off, but it cannot move the middle value.
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
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_093_digital_height_measurement.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 measureButton = 12;
int buzzer = 33;
float mountHeight = 200.0; // Sensor height above the floor in cm
float airTemperature = 25.0; // Used to correct the speed of sound
float lastHeight = 0;
float tallest = 0;
int measurements = 0;
float speedPerMicrosecond()
{
// 331.3 + 0.606 * T metres per second, converted to cm per us
float metresPerSecond = 331.3 + 0.606 * airTemperature;
return metresPerSecond / 10000.0;
}
float singleReading()
{
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 * speedPerMicrosecond() / 2.0;
}
float medianDistance()
{
float samples[9];
int valid = 0;
for (int i = 0; i < 9; i++)
{
float d = singleReading();
if (d > 0)
{
samples[valid] = d;
valid = valid + 1;
}
delay(40);
}
if (valid == 0) return -1;
// Sort, then take the middle value
for (int i = 0; i < valid - 1; i++)
{
for (int j = 0; j < valid - 1 - i; j++)
{
if (samples[j] > samples[j + 1])
{
float swap = samples[j];
samples[j] = samples[j + 1];
samples[j + 1] = swap;
}
}
}
return samples[valid / 2];
}
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(measureButton, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) { } }
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
}
void loop()
{
if (digitalRead(measureButton) == LOW)
{
display.clearDisplay();
display.setCursor(0, 24);
display.print("Stand still...");
display.display();
tone(buzzer, 900, 100);
delay(600);
float headGap = medianDistance();
if (headGap > 0)
{
lastHeight = mountHeight - headGap;
measurements = measurements + 1;
if (lastHeight > tallest) tallest = lastHeight;
tone(buzzer, 1600, 200);
Serial.print("Head gap ");
Serial.print(headGap, 1);
Serial.print("cm height ");
Serial.print(lastHeight, 1);
Serial.println("cm");
}
delay(500);
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("HEIGHT MEASURE");
if (lastHeight > 0)
{
display.setTextSize(3);
display.setCursor(0, 14);
display.print(lastHeight, 1);
display.setTextSize(1);
display.setCursor(96, 24);
display.print("cm");
int feet = (int)(lastHeight / 30.48);
int inches = (int)((lastHeight / 2.54) - feet * 12);
display.setCursor(0, 42);
display.print("That is ");
display.print(feet);
display.print("ft ");
display.print(inches);
display.print("in");
}
else
{
display.setTextSize(2);
display.setCursor(0, 20);
display.print("READY");
}
display.setCursor(0, 54);
display.print("N=");
display.print(measurements);
display.print(" tallest ");
display.print(tallest, 0);
display.print("cm");
display.display();
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.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
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).
Sound travels about 343 metres per second at room temperature, which is 0.0343 cm per microsecond, and the pulse makes a round trip, hence the division by two. That speed changes with temperature by roughly 0.6 m/s per degree, so the sketch includes the correction. Taking the median of nine readings rather than the average is deliberate: a single wild reflection would drag an average off, but it cannot move the middle value.
Press the button and a beep tells the person to stand still. Nine readings are taken and the median used. The height appears in centimetres and also in feet and inches.
Yes. It is project 93 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.
10 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Tactile Push Button Switch, 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) 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 45 minutes. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_093_digital_height_measurement.ino).
About ₹929 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Speed of sound mathematics; Temperature correction for acoustic measurement; Median filtering to reject wild readings; Converting between metric and imperial units.
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.