LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsThe MPU6050 sits on the Pico's I2C bus. MicroPython reads its raw acceleration registers with i2c.readfrom_mem, and the program calculates the angle from vertical using math.atan2. If the angle stays over the limit for two seconds, the buzzer sounds. The hold time ignores quick bumps. It is a hobby alert, not a safety device.
This is a hobby alarm. Do not rely on it for personal safety.
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.
main.pyimport time, math
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
MPU = 0x68
i2c.writeto_mem(MPU, 0x6B, b"\x00") # wake the sensor
buzzer = Pin(15, Pin.OUT)
LIMIT_DEG = 30
HOLD_MS = 2000
over_since = None
def s16(hi, lo):
v = (hi << 8) | lo
return v - 65536 if v > 32767 else v
while True:
d = i2c.readfrom_mem(MPU, 0x3B, 6)
ax = s16(d[0], d[1]) / 16384
ay = s16(d[2], d[3]) / 16384
az = s16(d[4], d[5]) / 16384
tilt = math.degrees(math.atan2(math.sqrt(ax * ax + ay * ay), az))
now = time.ticks_ms()
if tilt > LIMIT_DEG:
if over_since is None:
over_since = now
if time.ticks_diff(now, over_since) > HOLD_MS:
buzzer.value(1)
else:
over_since = None
buzzer.value(0)
time.sleep_ms(50)
The MPU6050 was not found. Check wiring and address 0x68.
The board is mounted tilted. Power it up flat.
Check GP15 and whether the buzzer is active or passive.
No, the registers are read directly.
Yes, add an OLED.
A degree or two when still; vibration adds noise.
5 parts: Raspberry Pi Pico, 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 hour. The build on this page has 6 steps.
About ₹662 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading raw I2C registers in MicroPython; Calculating tilt with atan2; Hold-time alarms.
This is a hobby alarm. Do not rely on it for personal safety.
Ideas that reuse this build: Pico ADXL345 spirit level OLED. 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.