LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsThe MS5837-02BA is a high-resolution absolute pressure sensor from TE for 0.3 to 1.2 bar, with a gel-protected port. Air pressure falls about 12 Pa per metre near sea level, and this sensor sees changes of a few pascals, so it can tell a step from a floor. The Blue Robotics MS5837 library supports this model. The sketch zeroes at start-up and shows relative height, the floor number (3 m per floor) and the air pressure.
Tick anything you already have and the total updates.
TE MS5837-02BA absolute pressure sensor module
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB, or a power bank to carry it.
altimeter.inoVerify & upload in Electrolark#include <Wire.h>
#include <MS5837.h>
#include <Adafruit_SSD1306.h>
MS5837 sensor;
Adafruit_SSD1306 oled(128, 64, &Wire);
const float FLOOR_M = 3.0;
float p0 = 0, pf = 0;
float readPa() { sensor.read(); return sensor.pressure() * 100; } // mbar to Pa
void setup() {
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
while (!sensor.init()) delay(1000);
sensor.setModel(MS5837::MS5837_02BA);
for (int i = 0; i < 20; i++) { p0 += readPa(); delay(50); }
p0 /= 20; pf = p0;
}
void loop() {
pf = 0.9 * pf + 0.1 * readPa(); // smooth
float h = 44330.0 * (1 - pow(pf / p0, 0.1903));
oled.clearDisplay(); oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(2); oled.setCursor(0, 0); oled.print(h, 1); oled.print(" m");
oled.setCursor(0, 24); oled.print("Floor "); oled.print((int)round(h / FLOOR_M));
oled.setTextSize(1); oled.setCursor(0, 52); oled.print(pf / 100, 1); oled.print(" hPa "); oled.print(sensor.temperature(), 1); oled.print(" C");
oled.display();
delay(100);
}
Check SDA and SCL and that the module is on 3.3 V.
Weather changes air pressure; zero it again at the start of each walk.
Air currents and warmth affect it; keep it in a small vented box.
This 02BA version only reaches 1.2 bar, about 2 m of water; use the 30BA version for diving.
About 2-3 cm of height with smoothing.
You are near the middle of a floor height; round down instead if you prefer.
5 parts: TE Connectivity MS5837-02BA21 Absolute Pressure Sensor Module, 0.3-1.2 bar, Digital I²C, ESP32-WROOM-32 38-Pin Development Board, 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 5 steps.
No. This page has the complete, tested code (altimeter.ino).
About ₹1,094 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
How pressure changes with height; Relative altitude from a zero point; Filtering a noisy signal.
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.