LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsTrack humidity over time with the same rolling history, adding a running average and a record of the extremes. Three different summaries of the same data appear here, and each answers a different question. The instant reading says what is happening now. The average over the stored window says what has been typical. The all-time minimum and maximum say what the extremes were, and they survive even after those readings have scrolled off the graph, which is why they are kept in separate variables rather than being recalculated from the array.
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_045_humidity_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);
int resetButton = 12;
float history[POINTS];
int stored = 0;
float recordLow = 100;
float recordHigh = 0;
unsigned long lastSample = 0;
void addReading(float value)
{
if (value < recordLow) recordLow = value;
if (value > recordHigh) recordHigh = value;
if (stored < POINTS)
{
history[stored] = value;
stored = stored + 1;
return;
}
for (int i = 0; i < POINTS - 1; i++)
{
history[i] = history[i + 1];
}
history[POINTS - 1] = value;
}
float average()
{
if (stored == 0) return 0;
float total = 0;
for (int i = 0; i < stored; i++)
{
total = total + history[i];
}
return total / stored;
}
void setup()
{
pinMode(resetButton, INPUT_PULLUP);
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 (digitalRead(resetButton) == LOW)
{
stored = 0;
recordLow = 100;
recordHigh = 0;
Serial.println("History cleared");
delay(400);
}
if (millis() - lastSample > 3000)
{
lastSample = millis();
float h = dht.readHumidity();
if (!isnan(h))
{
addReading(h);
Serial.println(h);
}
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("HUMIDITY LOG");
if (stored > 0)
{
display.setCursor(80, 0);
display.print(history[stored - 1], 0);
display.print("%");
display.setCursor(0, 12);
display.print("Avg ");
display.print(average(), 1);
display.print("%");
display.setCursor(64, 12);
display.print("L");
display.print(recordLow, 0);
display.print(" H");
display.print(recordHigh, 0);
// Bar graph of the stored window
for (int i = 0; i < stored; i++)
{
int x = 27 + i;
int barHeight = map(history[i], 0, 100, 0, 34);
display.drawLine(x, 60, x, 60 - barHeight, SSD1306_WHITE);
}
display.drawLine(26, 26, 26, 60, SSD1306_WHITE);
display.drawLine(26, 60, 127, 60, SSD1306_WHITE);
display.setCursor(0, 24);
display.print("100");
display.setCursor(6, 54);
display.print("0");
}
else
{
display.setCursor(0, 30);
display.print("Collecting data...");
}
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.
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 that DATA goes to the GPIO in the sketch, and wait two seconds between reads: the DHT11 is slow.
Three different summaries of the same data appear here, and each answers a different question. The instant reading says what is happening now. The average over the stored window says what has been typical. The all-time minimum and maximum say what the extremes were, and they survive even after those readings have scrolled off the graph, which is why they are kept in separate variables rather than being recalculated from the array.
A bar chart fills from the left, one bar every 3 seconds. The header shows the latest humidity as a percentage. Avg 58.4% with L42 H71 for the all-time records.
Yes. It is project 45 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.
8 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Tactile Push Button Switch, 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 6 steps.
No. This page has the complete, tested code (titan_kit_045_humidity_trend_tracker.ino).
About ₹875 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Historical data tracking; Running averages across an array; Keeping records separate from the rolling window; Bar charts as an alternative to line graphs.
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.