LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsTurn the board into a spirit level with a bubble that moves on screen and LEDs that confirm when a surface is flat. An accelerometer at rest measures only gravity, and gravity always points down, so the way that 9.8 m/s² is shared between the X, Y and Z axes tells you how the board is tilted. atan2() converts those components into pitch and roll angles, and unlike plain atan() it gets the quadrant right, which matters once the board passes vertical. The bubble is simply those two angles drawn as an offset from the centre of a circle.
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_061_digital_spirit_level.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 greenLed = 27;
int redLed = 26;
int buzzer = 33;
float levelTolerance = 1.5; // Degrees
float pitch = 0;
float roll = 0;
void setup()
{
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("OLED not found");
while (true) { }
}
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
if (!mpu.begin())
{
display.clearDisplay();
display.setCursor(0, 28);
display.print("MPU6050 not found");
display.display();
while (true) { }
}
mpu.setAccelerometerRange(MPU6050_RANGE_2_G);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
}
void loop()
{
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
// Gravity components become tilt angles
float newPitch = atan2(a.acceleration.y,
sqrt(a.acceleration.x * a.acceleration.x +
a.acceleration.z * a.acceleration.z)) * 180.0 / PI;
float newRoll = atan2(-a.acceleration.x, a.acceleration.z) * 180.0 / PI;
pitch = pitch * 0.8 + newPitch * 0.2;
roll = roll * 0.8 + newRoll * 0.2;
bool isLevel = (abs(pitch) < levelTolerance && abs(roll) < levelTolerance);
digitalWrite(greenLed, isLevel);
digitalWrite(redLed, !isLevel);
Serial.print("Pitch ");
Serial.print(pitch, 1);
Serial.print(" Roll ");
Serial.println(roll, 1);
display.clearDisplay();
display.setCursor(0, 0);
display.print("SPIRIT LEVEL");
// Bubble vial
int cx = 96;
int cy = 32;
display.drawCircle(cx, cy, 26, SSD1306_WHITE);
display.drawCircle(cx, cy, 6, SSD1306_WHITE);
int bx = cx + constrain((int)(roll * 1.2), -22, 22);
int by = cy + constrain((int)(pitch * 1.2), -22, 22);
display.fillCircle(bx, by, 4, SSD1306_WHITE);
display.setCursor(0, 16);
display.print("Pitch");
display.setCursor(0, 26);
display.print(pitch, 1);
display.print((char)247);
display.setCursor(0, 40);
display.print("Roll");
display.setCursor(0, 50);
display.print(roll, 1);
display.print((char)247);
if (isLevel)
{
display.setCursor(0, 8);
display.print("LEVEL");
if ((millis() / 800) % 2 == 0)
{
tone(buzzer, 1500, 60);
}
}
display.display();
delay(40);
}
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).
An accelerometer at rest measures only gravity, and gravity always points down, so the way that 9.8 m/s² is shared between the X, Y and Z axes tells you how the board is tilted. atan2() converts those components into pitch and roll angles, and unlike plain atan() it gets the quadrant right, which matters once the board passes vertical. The bubble is simply those two angles drawn as an offset from the centre of a circle.
The bubble sits off centre when the board is tilted. Level the board and the bubble drops into the middle circle. The green LED lights and a soft beep confirms level within 1.5 degrees.
Yes. It is project 61 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), 2 × 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_061_digital_spirit_level.ino).
About ₹1,052 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Accelerometer pitch and roll; Why atan2() is used instead of atan(); Extracting orientation from the gravity vector; Smoothing an IMU reading before displaying it.
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.