LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsThe MPU6050 contains an accelerometer. When it sits still, gravity points straight down, and the angle of that direction tells you how far the board is tilted. The sketch reads the raw acceleration, converts it to a tilt angle, and sounds a buzzer when the angle stays over 30 degrees for two seconds. The two-second delay ignores a quick knock. This is a simple hobby alert, not a safety device for people.
This is a hobby alarm. Do not rely on it for personal safety on ladders or scaffolding.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB power bank.
tilt_alarm.inoVerify & upload in Electrolark#include <Wire.h>
const uint8_t MPU = 0x68;
const int BUZZER = 25;
const float LIMIT_DEG = 30.0;
const unsigned long HOLD_MS = 2000;
unsigned long overSince = 0;
void readAccel(float &ax, float &ay, float &az) {
Wire.beginTransmission(MPU); Wire.write(0x3B); Wire.endTransmission(false);
Wire.requestFrom(MPU, (uint8_t)6);
int16_t x = (Wire.read() << 8) | Wire.read();
int16_t y = (Wire.read() << 8) | Wire.read();
int16_t z = (Wire.read() << 8) | Wire.read();
ax = x / 16384.0; ay = y / 16384.0; az = z / 16384.0; // in g at +-2 g range
}
void setup() {
Serial.begin(115200);
pinMode(BUZZER, OUTPUT);
Wire.begin(21, 22);
Wire.beginTransmission(MPU); Wire.write(0x6B); Wire.write(0); Wire.endTransmission(true); // wake the sensor
}
void loop() {
float ax, ay, az;
readAccel(ax, ay, az);
float tilt = atan2(sqrt(ax * ax + ay * ay), az) * 180.0 / PI; // angle from vertical
if (tilt > LIMIT_DEG) {
if (overSince == 0) overSince = millis();
if (millis() - overSince > HOLD_MS) digitalWrite(BUZZER, HIGH);
} else {
overSince = 0;
digitalWrite(BUZZER, LOW);
}
Serial.println(tilt);
delay(50);
}
Check the I2C wiring and that the sensor was woken (register 0x6B set to 0).
Raise HOLD_MS or LIMIT_DEG.
Check the pin and whether your module is active or passive.
It measures from vertical, so mount it flat when you power it.
Yes. Add an OLED like in the spirit level project.
No. Do not rely on a hobby alert for personal safety.
5 parts: ESP32-WROOM-32 38-Pin Development Board, GY-521 MPU6050 6-Axis Gyro and Accelerometer Module, Buzzer Module 3.3–5V, 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 1.5 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (tilt_alarm.ino).
About ₹652 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading raw MPU6050 registers over I2C; Calculating tilt from acceleration; Using a hold time to avoid false alarms.
Ideas that reuse this build: ESP32 OLED spirit level. They are listed under Take it further on this page.
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.
Learning project. Check every circuit and the datasheet of each part before you power it up.