LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsBearings and loose mounts show up as extra vibration long before a motor fails. The TDK ICM-42688-P is a low-noise 6-axis IMU used in drones and wearables. The ESP32 samples its accelerometer, computes the RMS vibration over half a second and the tilt angle, learns a baseline for 30 seconds after start-up, and switches a buzzer and relay when vibration doubles or the tilt changes by more than 5 degrees.
Fit the sensor only with the machine stopped and locked out.
Tick anything you already have and the total updates.
ICM-42688 6-axis IMU module
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB 5 V adapter near the machine.
machine_alarm.inoVerify & upload in Electrolark#include <ICM42688.h>
ICM42688 imu(Wire, 0x68);
const int BUZZER = 25, RELAY = 26;
const float VIB_FACTOR = 2.0, TILT_LIMIT = 5.0;
float baseRms = 0, baseTilt = 0;
void sample(float& rms, float& tilt) {
float sum = 0, ax = 0, ay = 0, az = 0; const int N = 200;
float mx = 0, my = 0, mz = 0;
for (int i = 0; i < N; i++) {
imu.getAGT();
float x = imu.accX(), y = imu.accY(), z = imu.accZ(); // g
mx += x; my += y; mz += z;
float mag = sqrt(x * x + y * y + z * z) - 1.0; // remove gravity
sum += mag * mag;
delayMicroseconds(2500);
}
rms = sqrt(sum / N);
ax = mx / N; ay = my / N; az = mz / N;
tilt = atan2(sqrt(ax * ax + ay * ay), az) * 180.0 / PI;
}
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
pinMode(BUZZER, OUTPUT); pinMode(RELAY, OUTPUT);
if (imu.begin() < 0) { Serial.println("IMU not found"); while (true) delay(1000); }
float r, t;
for (int i = 0; i < 60; i++) { sample(r, t); baseRms += r; baseTilt += t; } // about 30 s
baseRms /= 60; baseTilt /= 60;
Serial.printf("baseline rms %.4f g, tilt %.1f deg\n", baseRms, baseTilt);
}
void loop() {
float rms, tilt;
sample(rms, tilt);
bool alarm = rms > baseRms * VIB_FACTOR || fabs(tilt - baseTilt) > TILT_LIMIT;
digitalWrite(BUZZER, alarm); digitalWrite(RELAY, alarm);
Serial.printf("rms %.4f g tilt %.1f %s\n", rms, tilt, alarm ? "ALARM" : "ok");
}
Check SDA/SCL and that the module's address pin gives 0x68.
The baseline was learned with the machine off; restart with it running normally.
Lower VIB_FACTOR, and make sure the module is screwed or glued, not taped.
It shows a rising vibration trend; log the RMS daily and act when it climbs.
The library's defaults (±16 g, 1 kHz) are fine for motors.
Yes, post the alarm to a phone with the ESP32's Wi-Fi.
6 parts: ESP32-WROOM-32 38-Pin Development Board, Generic 601N1-ICM42688 6-Axis Gyroscope Accelerometer Module – I2C/SPI/UART Interface, Buzzer Module 3.3–5V, 5V Relay Module with Optocoupler, 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 intermediate project and takes about 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (machine_alarm.ino).
About ₹1,186 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
RMS vibration as a health signal; Tilt from an accelerometer; Learning a baseline instead of fixed limits.
Fit the sensor only with the machine stopped and locked out.
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.