LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsDetect a deliberate shake, several strong movements in quick succession, and use it as a command. A single jolt could be the board being set down; a shake is several jolts within a short window. The sketch counts spikes above a high-G threshold and requires three of them inside 1200 ms before it declares a shake. Requiring a pattern rather than a single event is what separates an intentional gesture from an accident, and it is why phones use exactly this technique for shake-to-undo.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
LEDs from the kit's red, green, yellow and blue packs
220 ohm resistors: one in series with every LED
MPU6050 motion sensor: 3-axis accelerometer and gyroscope on I2C
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_065_shake_detection.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
Adafruit_MPU6050 mpu;
int led = 25;
int buzzer = 33;
float spikeThreshold = 14.0; // m/s2 above gravity
int spikesNeeded = 3;
unsigned long windowLength = 1200;
int spikeCount = 0;
unsigned long windowStart = 0;
unsigned long lastSpike = 0;
int shakeCount = 0;
bool ledState = false;
void setup()
{
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) { } }
display.setTextColor(SSD1306_WHITE);
if (!mpu.begin())
{
display.clearDisplay();
display.setCursor(0, 28);
display.print("MPU6050 not found");
display.display();
while (true) { }
}
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setFilterBandwidth(MPU6050_BAND_94_HZ);
}
void loop()
{
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
float magnitude = sqrt(a.acceleration.x * a.acceleration.x +
a.acceleration.y * a.acceleration.y +
a.acceleration.z * a.acceleration.z);
float movement = abs(magnitude - 9.81);
// Count a spike, but not the same one twice
if (movement > spikeThreshold && millis() - lastSpike > 90)
{
lastSpike = millis();
if (spikeCount == 0 || millis() - windowStart > windowLength)
{
windowStart = millis();
spikeCount = 1;
}
else
{
spikeCount = spikeCount + 1;
}
Serial.print("Spike ");
Serial.print(spikeCount);
Serial.print(" at ");
Serial.println(movement, 1);
if (spikeCount >= spikesNeeded)
{
shakeCount = shakeCount + 1;
spikeCount = 0;
ledState = !ledState; // The shake command
digitalWrite(led, ledState);
tone(buzzer, 1200, 150);
Serial.println("SHAKE DETECTED");
}
}
if (spikeCount > 0 && millis() - windowStart > windowLength)
{
spikeCount = 0; // Window expired
}
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("SHAKE DETECTOR");
display.setTextSize(2);
display.setCursor(0, 14);
display.print("Shakes ");
display.print(shakeCount);
display.setTextSize(1);
display.setCursor(0, 36);
display.print("Force ");
display.print(movement, 1);
display.print(" m/s2");
display.setCursor(0, 46);
display.print("Spikes ");
display.print(spikeCount);
display.print("/");
display.print(spikesNeeded);
if (spikeCount > 0)
{
display.setCursor(64, 46);
display.print((windowLength - (millis() - windowStart)));
display.print("ms");
}
display.setCursor(0, 56);
display.print("LED is ");
display.print(ledState ? "ON" : "OFF");
display.display();
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
Turn it round: the long leg (anode) goes to the GPIO side through the 220 ohm resistor, the short leg to GND.
This project needs the passive buzzer (the one that plays notes), not the active one.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
A single jolt could be the board being set down; a shake is several jolts within a short window. The sketch counts spikes above a high-G threshold and requires three of them inside 1200 ms before it declares a shake. Requiring a pattern rather than a single event is what separates an intentional gesture from an accident, and it is why phones use exactly this technique for shake-to-undo.
Gentle handling registers no spikes at all. One sharp jolt shows Spikes 1/3 with a countdown. Three jolts within 1.2 seconds: SHAKE DETECTED, the buzzer sounds and the LED toggles.
Yes. It is project 65 of 120 in the Geekobot Titan Kit, in level 11 (Motion and IMU). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
10 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), Buzzer Module 3.3–5V, 0.96" OLED Display 128x64, GY-521 MPU6050 6-Axis Gyro and Accelerometer Module and ESP32 38-Pin Expansion Board. 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 45 minutes. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_065_shake_detection.ino).
About ₹1,037 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
High-G acceleration spike detection; Requiring a pattern of events, not a single one; Time windows that expire; Preventing one physical jolt from counting twice.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
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.