LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsMeasure and display precise inclination angles, with a calibration step that zeroes the sensor against a known flat surface. No sensor is perfectly mounted, and no board is perfectly flat, so a raw reading of 1.8 degrees on a genuinely level table is normal. Calibration fixes that by recording the current angles as the new zero and subtracting them from every future reading. This offset-based approach is how almost all instruments are zeroed, from kitchen scales to surveying equipment, and it costs two variables.
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
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_062_tilt_angle_measurement.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 calibrateButton = 12;
int holdButton = 14;
float pitchOffset = 0;
float rollOffset = 0;
float pitch = 0;
float roll = 0;
bool holding = false;
float heldPitch = 0;
float heldRoll = 0;
void readAngles()
{
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
float p = atan2(a.acceleration.y,
sqrt(a.acceleration.x * a.acceleration.x +
a.acceleration.z * a.acceleration.z)) * 180.0 / PI;
float r = atan2(-a.acceleration.x, a.acceleration.z) * 180.0 / PI;
pitch = pitch * 0.85 + (p - pitchOffset) * 0.15;
roll = roll * 0.85 + (r - rollOffset) * 0.15;
}
void calibrate()
{
display.clearDisplay();
display.setCursor(0, 24);
display.print("Calibrating...");
display.setCursor(0, 36);
display.print("Keep still");
display.display();
pitchOffset = 0;
rollOffset = 0;
float sumP = 0;
float sumR = 0;
for (int i = 0; i < 100; i++)
{
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
sumP += atan2(a.acceleration.y,
sqrt(a.acceleration.x * a.acceleration.x +
a.acceleration.z * a.acceleration.z)) * 180.0 / PI;
sumR += atan2(-a.acceleration.x, a.acceleration.z) * 180.0 / PI;
delay(15);
}
pitchOffset = sumP / 100.0;
rollOffset = sumR / 100.0;
Serial.print("Offsets set to ");
Serial.print(pitchOffset);
Serial.print(" / ");
Serial.println(rollOffset);
pitch = 0;
roll = 0;
}
void setup()
{
pinMode(calibrateButton, INPUT_PULLUP);
pinMode(holdButton, INPUT_PULLUP);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
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);
calibrate();
}
void loop()
{
readAngles();
if (digitalRead(calibrateButton) == LOW)
{
calibrate();
delay(300);
}
if (digitalRead(holdButton) == LOW)
{
holding = !holding;
if (holding)
{
heldPitch = pitch;
heldRoll = roll;
}
delay(300);
}
float showPitch = holding ? heldPitch : pitch;
float showRoll = holding ? heldRoll : roll;
display.clearDisplay();
display.setCursor(0, 0);
display.print("TILT MEASURE");
if (holding)
{
display.setCursor(86, 0);
display.print("HELD");
}
display.setTextSize(2);
display.setCursor(0, 14);
display.print("X ");
display.print(showPitch, 1);
display.print((char)247);
display.setCursor(0, 34);
display.print("Y ");
display.print(showRoll, 1);
display.print((char)247);
display.setTextSize(1);
display.setCursor(0, 56);
display.print("D3 zero D4 hold");
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.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
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).
No sensor is perfectly mounted, and no board is perfectly flat, so a raw reading of 1.8 degrees on a genuinely level table is normal. Calibration fixes that by recording the current angles as the new zero and subtracting them from every future reading. This offset-based approach is how almost all instruments are zeroed, from kitchen scales to surveying equipment, and it costs two variables.
A short Calibrating... message at startup. On a flat table both axes read close to 0.0°. Tilt the board and the angles change to a tenth of a degree.
Yes. It is project 62 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.
8 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), 2 × Tactile Push Button Switch, 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_062_tilt_angle_measurement.ino).
About ₹1,000 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
IMU maths and calibration; Zeroing an instrument with stored offsets; Averaging many samples for a stable calibration; Hold functions for taking a measurement away from the bench.
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.