LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsStore a rolling history of temperature readings and draw them as a live graph on the OLED. The history array holds one reading per screen column. When it fills up, every value shifts one place left and the newest lands at the end, the oldest simply falls off. The graph then auto-scales: it finds the smallest and largest values currently stored and maps that range onto the plot height, so a half-degree wobble fills the screen just as a ten-degree swing would. Auto-scaling is what makes a small graph readable.
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
DHT11 temperature and humidity sensor
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_044_temperature_trend_tracker.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define DHTPIN 13
#define DHTTYPE DHT11
#define POINTS 100
Adafruit_SSD1306 display(128, 64, &Wire, -1);
DHT dht(DHTPIN, DHTTYPE);
float history[POINTS];
int stored = 0;
unsigned long lastSample = 0;
unsigned long interval = 3000;
void addReading(float value)
{
if (stored < POINTS)
{
history[stored] = value;
stored = stored + 1;
return;
}
for (int i = 0; i < POINTS - 1; i++) // Shift everything left
{
history[i] = history[i + 1];
}
history[POINTS - 1] = value;
}
void drawGraph()
{
if (stored < 2)
{
return;
}
float lowest = history[0];
float highest = history[0];
for (int i = 1; i < stored; i++)
{
if (history[i] < lowest) lowest = history[i];
if (history[i] > highest) highest = history[i];
}
if (highest - lowest < 1.0) // Never squash a flat line
{
highest = highest + 0.5;
lowest = lowest - 0.5;
}
int plotTop = 20;
int plotBottom = 60;
display.drawLine(24, plotTop, 24, plotBottom, SSD1306_WHITE);
display.drawLine(24, plotBottom, 127, plotBottom, SSD1306_WHITE);
display.setCursor(0, plotTop - 3);
display.print(highest, 1);
display.setCursor(0, plotBottom - 6);
display.print(lowest, 1);
for (int i = 1; i < stored; i++)
{
int x1 = 25 + (i - 1);
int x2 = 25 + i;
int y1 = map(history[i - 1] * 10, lowest * 10, highest * 10, plotBottom, plotTop);
int y2 = map(history[i] * 10, lowest * 10, highest * 10, plotBottom, plotTop);
display.drawLine(x1, y1, x2, y2, SSD1306_WHITE);
}
}
void setup()
{
Serial.begin(9600);
dht.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("OLED not found");
while (true) { }
}
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
}
void loop()
{
if (millis() - lastSample > interval)
{
lastSample = millis();
float t = dht.readTemperature();
if (!isnan(t))
{
addReading(t);
Serial.println(t);
}
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("TEMP TREND");
if (stored > 0)
{
display.setCursor(70, 0);
display.print(history[stored - 1], 1);
display.print("C");
display.setCursor(0, 10);
if (stored > 4)
{
float change = history[stored - 1] - history[stored - 5];
if (change > 0.2) display.print("Rising");
else if (change < -0.2) display.print("Falling");
else display.print("Steady");
}
display.setCursor(70, 10);
display.print(stored);
display.print(" points");
}
drawGraph();
display.display();
delay(200);
}
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.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Check that DATA goes to the GPIO in the sketch, and wait two seconds between reads: the DHT11 is slow.
The history array holds one reading per screen column. When it fills up, every value shifts one place left and the newest lands at the end, the oldest simply falls off. The graph then auto-scales: it finds the smallest and largest values currently stored and maps that range onto the plot height, so a half-degree wobble fills the screen just as a ten-degree swing would. Auto-scaling is what makes a small graph readable.
A line graph builds up from the left, one point every 3 seconds. The axis labels show the current highest and lowest values. The header reads Rising, Falling or Steady.
Yes. It is project 44 of 120 in the Geekobot Titan Kit, in level 9 (Environmental science). 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.
6 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Dupont Jumper Wires (40 pcs), 0.96" OLED Display 128x64, Generic DHT11 Digital Temperature & Humidity Sensor 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 30 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (titan_kit_044_temperature_trend_tracker.ino).
About ₹850 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Data logging into arrays; Shifting an array to make a rolling window; Auto-scaling a graph to its own data; Detecting a trend by comparing across samples.
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.