LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsA PIR sensor's output stays high while it sees movement. The program counts each rising edge, then ignores the sensor for five seconds so one person walking in front does not count several times. The OLED shows the total and the time since the last visitor. Count rises for pets and curtains in a draught too, so place it where only people pass.
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 adapter.
main.pyimport time
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
pir = Pin(16, Pin.IN)
LOCKOUT_MS = 5000
count = 0
last = time.ticks_ms() - LOCKOUT_MS
prev = 0
while True:
now = time.ticks_ms()
v = pir.value()
if v == 1 and prev == 0 and time.ticks_diff(now, last) > LOCKOUT_MS:
count += 1
last = now
prev = v
oled.fill(0)
oled.text("Visitors", 0, 0)
oled.text(str(count), 0, 16)
oled.text("Last: %ds ago" % (time.ticks_diff(now, last) // 1000), 0, 48)
oled.show()
time.sleep_ms(100)
Move the sensor away from heaters, fans and windows.
Reduce LOCKOUT_MS and check the PIR sensitivity knob.
Check the I2C wires and driver install.
No. It counts movement events, so it is an estimate.
Yes, append timestamps to a text file, but write sparingly to protect the flash.
Sun and wind cause false triggers. Keep it indoors.
5 parts: Raspberry Pi Pico, HC-SR501 PIR Motion Detector Sensor Module, 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 45 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (main.py).
About ₹667 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Detecting a rising edge; Using a lock-out time; Showing elapsed seconds.
Ideas that reuse this build: Pico PIR intruder alarm. 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.