LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsThe MPU6500 is a 6-axis motion sensor (accelerometer plus gyroscope), the successor of the MPU6050. When it lies still, its accelerometer measures only gravity, and the share of gravity on each axis gives the tilt angle. The sketch talks to the chip directly over I2C, waking it and reading six bytes from its accelerometer registers, so you can see exactly what a library does.
Tick anything you already have and the total updates.
MPU6500 6-axis motion sensor module
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB or a small power bank.
tilt_level.inoVerify & upload in Electrolark#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const uint8_t MPU = 0x68;
float OFF_X = 0, OFF_Y = 0;
void readAccel(float &ax, float &ay, float &az) {
Wire.beginTransmission(MPU); Wire.write(0x3B); Wire.endTransmission(false);
Wire.requestFrom(MPU, (uint8_t)6);
int16_t x = Wire.read() << 8 | Wire.read();
int16_t y = Wire.read() << 8 | Wire.read();
int16_t z = Wire.read() << 8 | Wire.read();
ax = x / 16384.0; ay = y / 16384.0; az = z / 16384.0; // +-2 g range
}
void setup() {
Wire.begin();
Wire.beginTransmission(MPU); Wire.write(0x6B); Wire.write(0); Wire.endTransmission(); // wake up
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); oled.setTextColor(WHITE);
}
void loop() {
float sx = 0, sy = 0, sz = 0;
for (int i = 0; i < 20; i++) { float x, y, z; readAccel(x, y, z); sx += x; sy += y; sz += z; delay(5); }
float pitch = atan2(sx, sqrt(sy * sy + sz * sz)) * 57.3 - OFF_X;
float roll = atan2(sy, sqrt(sx * sx + sz * sz)) * 57.3 - OFF_Y;
oled.clearDisplay();
oled.drawCircle(96, 32, 28, WHITE); oled.drawCircle(96, 32, 4, WHITE);
oled.fillCircle(96 + constrain(roll * 3, -24, 24), 32 - constrain(pitch * 3, -24, 24), 4, WHITE);
oled.setTextSize(1); oled.setCursor(0, 10); oled.print("X "); oled.print(pitch, 1);
oled.setCursor(0, 30); oled.print("Y "); oled.print(roll, 1);
oled.setCursor(0, 50); oled.print(fabs(pitch) < 0.3 && fabs(roll) < 0.3 ? "LEVEL" : "");
oled.display();
}
The chip is still asleep or at another address (0x69 if AD0 is high).
Vibration from a fan or table; average more samples.
The sensor is not perfectly square on its board; set OFF_X and OFF_Y.
About 0.1-0.3 degrees after zeroing, enough for shelves and printer beds.
Many work, but the MPU6500's ID is different, so some refuse to start; raw reads always work.
The gyro measures turning speed; for still tilt the accelerometer is the right sensor.
5 parts: Generic MPU6500 6-Axis Gyro Accelerometer DMP Motion Sensor Module – I2C/SPI, Generic Nano CH340 Development Board (Soldered), 0.96" OLED Display 128x64, 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.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
About ₹533 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Measuring tilt from gravity; Reading sensor registers over I2C without a library; Averaging to reduce noise.
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.