LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsDraw a battery symbol that fills and empties, with an animated charging bolt and a low-battery warning. A progress bar is two rectangles: an outline that never changes and a filled one whose width is the percentage scaled to the bar's inner width. That single map() call is the whole trick, and it works for battery meters, loading bars, volume sliders and level gauges alike. The charging animation is a second idea, a counter that advances every frame and wraps with %, so the fill repeatedly sweeps across regardless of the actual level.
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
10k potentiometer: a knob the ESP32 reads on an analog pin
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_038_oled_battery_level_indicat.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int chargeButton = 13;
int buzzer = 33;
bool charging = false;
int animation = 0;
unsigned long lastBeep = 0;
void drawBattery(int percent)
{
int x = 24;
int y = 18;
int w = 80;
int h = 30;
display.drawRect(x, y, w, h, SSD1306_WHITE);
display.fillRect(x + w, y + 9, 4, 12, SSD1306_WHITE); // Terminal nub
int innerWidth = w - 6;
int fill = map(percent, 0, 100, 0, innerWidth);
if (charging)
{
// Sweep the fill across to show charging
fill = map(animation, 0, 100, 0, innerWidth);
}
if (fill > 0)
{
display.fillRect(x + 3, y + 3, fill, h - 6, SSD1306_WHITE);
}
// Percentage text, inverted where it overlaps the fill
display.setTextSize(2);
display.setCursor(x + 18, y + 8);
display.setTextColor(SSD1306_INVERSE);
display.print(percent);
display.print("%");
display.setTextColor(SSD1306_WHITE);
}
void setup()
{
analogReadResolution(10); // ESP32 is 12-bit; use 0-1023 like the examples
pinMode(chargeButton, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("OLED not found");
while (true) { }
}
}
void loop()
{
int percent = map(analogRead(34), 0, 1023, 0, 100);
if (digitalRead(chargeButton) == LOW)
{
charging = !charging;
delay(300);
}
animation = (animation + 4) % 101;
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
if (charging)
{
display.print("CHARGING");
}
else if (percent < 20)
{
display.print("LOW BATTERY");
}
else
{
display.print("BATTERY");
}
drawBattery(percent);
display.setTextSize(1);
display.setCursor(0, 56);
if (percent < 20 && !charging)
{
display.print("Please charge now");
if (millis() - lastBeep > 3000)
{
lastBeep = millis();
tone(buzzer, 1500, 120);
}
}
else
{
display.print("Status: OK");
}
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.
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).
A progress bar is two rectangles: an outline that never changes and a filled one whose width is the percentage scaled to the bar's inner width. That single map() call is the whole trick, and it works for battery meters, loading bars, volume sliders and level gauges alike. The charging animation is a second idea, a counter that advances every frame and wraps with %, so the fill repeatedly sweeps across regardless of the actual level.
A battery outline fills as you turn the knob. The percentage sits inside the bar in inverted text. Below 20 percent the header reads LOW BATTERY and the buzzer chirps every 3 seconds.
Yes. It is project 38 of 120 in the Geekobot Titan Kit, in level 8 (OLED graphics). 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), Tactile Push Button Switch, Buzzer Module 3.3–5V, 0.96" OLED Display 128x64, 16mm Rotary Potentiometer (Linear) 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 30 minutes. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_038_oled_battery_level_indicat.ino).
About ₹865 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Graphical progress bars; Mapping a percentage onto a pixel width; Inverted text over a filled shape; Simple frame-counter animation with %.
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.