LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsA piezo knock sensor makes a voltage when it is tapped or vibrated. The Pico's analog input reads it, and the program counts every spike above a threshold. A short dead time after each tap prevents one knock from being counted several times while the table rings. The OLED shows the total and a taps-per-minute figure, which turns it into a tapping speed game.
Tick anything you already have and the total updates.
Piezo knock sensor
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB power adapter or power bank.
main.pyimport time
from machine import Pin, I2C, ADC
from ssd1306 import SSD1306_I2C
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
adc = ADC(26)
THRESHOLD = 12000 # 0-65535
DEAD_MS = 100
count = 0
stamps = []
last = 0
while True:
v = adc.read_u16()
now = time.ticks_ms()
if v > THRESHOLD and time.ticks_diff(now, last) > DEAD_MS:
last = now
count += 1
stamps.append(now)
stamps = [s for s in stamps if time.ticks_diff(now, s) < 60000]
oled.fill(0)
oled.text("Taps: %d" % count, 0, 0)
oled.text("Per min: %d" % len(stamps), 0, 24)
oled.show()
time.sleep_ms(10)
Increase DEAD_MS.
Lower THRESHOLD and press the sensor against the surface.
Raise THRESHOLD and keep the sensor away from vibration.
Yes. Count taps for 10 seconds and show the best score.
It is ADC0, one of the Pico's analog inputs.
Yes, as 0 to 65535 with read_u16().
5 parts: Raspberry Pi Pico, Elecrow Crowtail-Knock Sensor Module – Piezoelectric Vibration Detection, 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 ₹739 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading an analog input on the Pico; Debouncing a vibration sensor; Calculating a rate from timestamps.
Ideas that reuse this build: Pico reaction game. 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.