LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsThe TFMini-S is a small time-of-flight LiDAR that measures 0.1-12 m and streams 9-byte frames over UART at 115200 baud: two 0x59 header bytes, distance, signal strength, temperature and a checksum. The ESP32 parses the frames, shows the distance on an OLED and holds the value when you press a button. Signal strength tells you when a reading cannot be trusted, for example on black or shiny surfaces.
Tick anything you already have and the total updates.
TFMini-S micro LiDAR, UART
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB power bank.
tfmini_meter.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
void big(const String& top, const String& value, const String& unit) {
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(1); oled.setCursor(0, 0); oled.print(top);
oled.setTextSize(3); oled.setCursor(0, 20); oled.print(value);
oled.setTextSize(1); oled.print(" "); oled.print(unit);
oled.display();
}
HardwareSerial lidar(2);
const int BTN = 14;
int dist = 0, strength = 0;
bool hold = false, lastBtn = HIGH;
bool readFrame() {
while (lidar.available() >= 9) {
if (lidar.read() != 0x59) continue;
if (lidar.peek() != 0x59) continue;
uint8_t b[9]; b[0] = 0x59; lidar.readBytes(b + 1, 8);
uint8_t sum = 0; for (int i = 0; i < 8; i++) sum += b[i];
if (sum != b[8]) continue;
dist = b[2] | (b[3] << 8); // cm
strength = b[4] | (b[5] << 8);
return true;
}
return false;
}
void setup() {
lidar.begin(115200, SERIAL_8N1, 16, 17);
pinMode(BTN, INPUT_PULLUP);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
bool b = digitalRead(BTN);
if (lastBtn == HIGH && b == LOW) hold = !hold;
lastBtn = b;
if (readFrame() && !hold) {
bool ok = strength >= 100 && strength != 65535;
big(hold ? "HOLD" : (ok ? "Distance" : "Weak signal"), ok ? String(dist / 100.0, 2) : "--", "m");
}
delay(20);
}
The target is too far, too dark or at a steep angle; aim at a light, flat surface.
Swap green and white wires; the LiDAR's TX goes to the ESP32's RX.
The TFMini-S cannot measure closer than 10 cm.
Yes, though strong sunlight shortens the range.
It is a Class 1 eye-safe infrared laser.
Yes, take two readings and multiply them in code.
6 parts: ESP32-WROOM-32 38-Pin Development Board, Benewake TFMini-S Micro LiDAR Sensor UART, Range: 0.1m~12m, Tactile Push Button Switch, 0.96" OLED Display 128x64, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (tfmini_meter.ino).
About ₹4,181 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Parsing a binary UART protocol with a checksum; Time-of-flight distance sensing; Using signal strength to reject bad readings.
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.