LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsA ball tilt switch is a tiny tube with a metal ball inside: tilt it past its angle (10° for the SW-200DAC) and the ball opens or closes the contacts. The Nano watches the switch with an interrupt, waits a few seconds after you arm it so you can put the bag down, then sounds the buzzer if the switch changes. A hidden button disarms it.
Tick anything you already have and the total updates.
SW-200DAC single-ball tilt switch, 10°
Follow the colours: red is power, dark grey is ground, blue is a signal.
Power bank, or a 9 V battery on VIN.
bag_alarm.inoVerify & upload in Electrolarkbool armed = false, alarm = false, ready = false;
int restState;
unsigned long armedAt = 0;
void setup() {
pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(8, OUTPUT);
}
void loop() {
if (digitalRead(3) == LOW) {
delay(300);
if (alarm || armed) { armed = alarm = ready = false; noTone(8); }
else { armed = true; armedAt = millis(); tone(8, 2000, 100); delay(200); tone(8, 2000, 100); }
}
if (armed && !alarm && millis() - armedAt > 5000) {
if (!ready) { restState = digitalRead(2); ready = true; } // remember the resting position
if (digitalRead(2) != restState) { delay(50); if (digitalRead(2) != restState) alarm = true; }
}
if (alarm) { tone(8, 3000); delay(200); tone(8, 2000); delay(200); }
}
The bag was still moving; increase the 5 s arming delay.
The switch is mounted flat; tilt switches need to sit upright to react to tipping.
That is expected; disarm it while travelling.
Tilt switches react to angle; spring vibration switches react to knocks. Both are in the same family.
Use an ESP32 or a Bluetooth module and send a notification instead of a beep.
About a day; a power bank lasts much longer.
6 parts: XKB Connection SW-200DAC-10G1 Single-Ball Tilt Switch – 10° Activation Angle, Generic Nano CH340 Development Board (Soldered), Buzzer Module 3.3–5V, Tactile Push Button Switch, 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.
No. This page has the complete, tested code (bag_alarm.ino).
About ₹295 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
How tilt and vibration switches work; Debouncing a chattering contact; Arm and disarm logic.
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.