LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsInstead of waking on a timer, the ESP32 can wake when a pin changes. This sketch puts the board into deep sleep and uses ext0 wake-up on GPIO 33, wired to a PIR sensor. When someone moves the PIR output goes high, the board wakes, increases a counter kept in RTC memory, prints the event count and goes back to sleep. Only RTC-capable pins (such as 32 or 33) can wake the ESP32. The PIR itself still draws a little current, so this suits a mains-powered or large-battery set-up.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger or a power bank.
pir_wake.inoVerify & upload in Electrolark#include <esp_sleep.h>
const gpio_num_t PIR_PIN = GPIO_NUM_33;
RTC_DATA_ATTR int events = 0; // survives deep sleep
void setup() {
Serial.begin(115200);
delay(300);
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_EXT0) {
events++;
Serial.printf("Motion event number %d\n", events);
delay(5000); // let the PIR output fall again before sleeping
} else {
Serial.println("Power-up: arming the motion wake-up");
}
esp_sleep_enable_ext0_wakeup(PIR_PIN, 1); // wake when the pin goes HIGH
Serial.println("Sleeping...");
esp_deep_sleep_start();
}
void loop() {}
The PIR output is still high. The sketch waits 5 seconds; increase it, or lengthen the PIR's hold time with its potentiometer.
Use an RTC pin such as 32 or 33 and check the PIR output goes to 3.3 V logic high.
A power cycle or the EN button clears RTC memory. Only a wake from deep sleep keeps it.
RTC-capable pins such as GPIO 32, 33, 34, 35, 36, 39 and others listed for your board.
The HC-SR501 wants 5 V for its sensor, but its output is 3.3 V logic.
A bare ESP32 can sleep for months, but the PIR and a dev board's regulator draw more, so measure it.
4 parts: ESP32-WROOM-32 38-Pin Development Board, HC-SR501 PIR Motion Detector Sensor Module, 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 (pir_wake.ino).
About ₹518 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Wake-up from deep sleep with esp_sleep_enable_ext0_wakeup; Counting events in RTC_DATA_ATTR memory; Why only RTC pins can wake the chip.
Ideas that reuse this build: ESP32 deep-sleep battery temperature node. 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.