LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsMeasure how hard the board is being moved by combining all three acceleration axes into a single magnitude. Motion in three dimensions cannot be judged from one axis, because a shake along X and a shake along Z are equally vigorous. Pythagoras in three dimensions gives the answer: the magnitude is the square root of the sum of the squares. At rest that magnitude equals gravity, about 9.8 m/s², so subtracting 9.8 leaves the movement alone, which is why the meter reads zero on a still table regardless of which way up it is.
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_064_motion_intensity_meter.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 ledPins[5] = {12, 14, 27, 26, 25};
float intensity = 0;
float peak = 0;
unsigned long peakTime = 0;
void setup()
{
for (int i = 0; i < 5; i++)
{
pinMode(ledPins[i], 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_8_G);
mpu.setFilterBandwidth(MPU6050_BAND_44_HZ);
}
void loop()
{
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
float x = a.acceleration.x;
float y = a.acceleration.y;
float z = a.acceleration.z;
// 3D vector magnitude, then remove gravity
float magnitude = sqrt(x * x + y * y + z * z);
float movement = abs(magnitude - 9.81);
// Fast attack, slow decay
if (movement > intensity)
{
intensity = movement;
}
else
{
intensity = intensity * 0.9 + movement * 0.1;
}
if (intensity > peak)
{
peak = intensity;
peakTime = millis();
}
else if (millis() - peakTime > 3000)
{
peak = peak * 0.98;
}
int level = constrain(map(intensity * 10, 0, 150, 0, 5), 0, 5);
for (int i = 0; i < 5; i++)
{
digitalWrite(ledPins[i], i < level);
}
Serial.print("Movement ");
Serial.print(movement, 2);
Serial.print(" Intensity ");
Serial.println(intensity, 2);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("MOTION INTENSITY");
display.setTextSize(3);
display.setCursor(0, 14);
display.print(intensity, 1);
display.setTextSize(1);
display.setCursor(72, 24);
display.print("m/s2");
display.setCursor(0, 42);
display.print("Peak ");
display.print(peak, 1);
display.setCursor(64, 42);
if (intensity < 0.3) display.print("STILL");
else if (intensity < 2) display.print("GENTLE");
else if (intensity < 6) display.print("MODERATE");
else display.print("VIGOROUS");
display.drawRect(0, 52, 128, 10, SSD1306_WHITE);
display.fillRect(1, 53, constrain((int)(intensity * 8), 0, 126), 8, SSD1306_WHITE);
display.display();
delay(20);
}
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.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Check SDA on GPIO21 and SCL on GPIO22 and power it from 3V3. The AD0 pin must stay unconnected (address 0x68).
Motion in three dimensions cannot be judged from one axis, because a shake along X and a shake along Z are equally vigorous. Pythagoras in three dimensions gives the answer: the magnitude is the square root of the sum of the squares. At rest that magnitude equals gravity, about 9.8 m/s², so subtracting 9.8 leaves the movement alone, which is why the meter reads zero on a still table regardless of which way up it is.
A still board reads close to 0.0 with the verdict STILL. Gentle movement lights one or two LEDs and shows GENTLE. A firm shake lights all five and reads VIGOROUS.
Yes. It is project 64 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.
9 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), 5 × Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), 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 6 steps.
No. This page has the complete, tested code (titan_kit_064_motion_intensity_meter.ino).
About ₹1,070 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Vector magnitude calculation; Removing gravity from a three-axis reading; Why one axis is not enough for motion; Attack and decay applied to a sensor signal.
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.