This guide shows you how to build an intelligent IoT geyser safety system that watches a geyser's water temperature, current and water flow, cuts the power automatically when something is unsafe, and uploads the readings to the cloud over Wi-Fi. It is a student and final year project — a working safety prototype you can demonstrate with a small load.
Safety warning — read first: this project controls 220V AC mains electricity, which can kill. Build it only with adult supervision, never touch the relay's mains terminals while power is connected, and enclose the finished unit in an insulated box. Test it first with a small load (a 60W bulb) — never with a real geyser. Connecting a real geyser's mains wiring is a job for a qualified electrician only.
Also important: this is a student prototype, not a certified safety device. It demonstrates how geyser safety monitoring works — it does not make a real geyser safe, and it does not replace a proper thermostat, pressure valve or electrician.

This project uses the ESP32 only. The safety upload needs Wi-Fi, and the flow sensor, temperature sensor and current sensor all need to be read together in one sketch. The Arduino Uno has no Wi-Fi, so it cannot run the IoT part of this code. The earlier version of this post listed "Arduino Uno / ESP32 / ESP8266" — that was misleading, and it is corrected here.
The system does not monitor pressure or current leakage — there is no pressure sensor and no leakage sensor in this design, and the earlier version of this post wrongly claimed it addressed those risks.
0x27)| Component | ESP32 Pin |
|---|---|
| DS18B20 data (DQ) | GPIO 4 (with a 4.7kΩ pull-up resistor from DQ to 3.3V — without it the sensor reads −127°C) |
| DS18B20 VCC / GND | 3.3V / GND |
| ACS712 OUT | GPIO 34 (analog) |
| ACS712 VCC / GND | 5V / GND |
| YF-S201 signal (yellow) | GPIO 5, through a voltage divider: signal → 10kΩ → GPIO 5, and 20kΩ from GPIO 5 to GND (the sensor outputs 5V pulses; the ESP32 pins accept 3.3V, so the divider brings the signal down safely) |
| YF-S201 red / black | 5V / GND |
| Relay IN | GPIO 26 |
| Buzzer + | GPIO 25 (buzzer − to GND) |
| LCD SDA | GPIO 21 |
| LCD SCL | GPIO 22 |
| LCD VCC / GND | 5V / GND |
| Component | Price / link |
|---|---|
| ESP32 Dev Module | ESP32 30-Pin Wi-Fi Bluetooth Development Board — Rs 1,100 |
| 1-Channel Relay Module 5V | 1-Channel Relay Module for Arduino Projects 5V — Rs 155 |
| Active Buzzer | Active Piezo Buzzer 3V-12V — Rs 35 |
The DS18B20, ACS712, YF-S201, 16×2 LCD and 12V SMPS do not have individual listings in the QKZEE shop — they are available at the Hall Road shop on request.
Once a cut-off triggers, the heater stays off until you press the reset button on the ESP32 — it does not switch itself back on.
/*
Intelligent IoT Geyser Safety System
Board: ESP32 Dev Module.
DS18B20 temperature (GPIO 4) + ACS712-30A current (GPIO 34)
+ YF-S201 flow sensor (GPIO 5, via 10k/20k divider)
+ relay (GPIO 26) + buzzer (GPIO 25) + 16x2 I2C LCD (SDA 21, SCL 22).
Uploads temperature, current, flow and total litres to ThingSpeak.
Safety cut-offs: temp > 75 C, dry run, current > 15 A, sensor fault.
*/
#include <WiFi.h>
#include <HTTPClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";
const char* thingSpeakApiKey = "YOUR_THINGSPEAK_WRITE_API_KEY";
#define TEMP_PIN 4
#define FLOW_PIN 5
#define CURRENT_PIN 34
#define RELAY_PIN 26
#define BUZZER_PIN 25
// Most relay modules are ACTIVE-LOW: LOW switches the relay ON.
// If your module is active-high, swap RELAY_ON and RELAY_OFF below.
#define RELAY_ON LOW
#define RELAY_OFF HIGH
#define TEMP_LIMIT 75.0 // degrees C
#define CURRENT_LIMIT 15.0 // amps
#define FLOW_MIN 0.1 // litres per minute
#define DRY_RUN_SECONDS 10
OneWire oneWire(TEMP_PIN);
DallasTemperature tempSensor(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);
volatile unsigned long pulseCount = 0;
void IRAM_ATTR countPulse() { pulseCount++; }
bool heaterOn = false;
bool cutOff = false;
String cutOffReason = "";
unsigned long noFlowSince = 0;
float totalLitres = 0;
float readCurrentRMS() {
// ACS712-30A: 2.5 V at 0 A, 66 mV per amp. ESP32 ADC reference is 3.3 V.
// Sample for 200 ms (10 mains cycles) and compute the RMS current.
unsigned long start = millis();
float sumSq = 0;
int samples = 0;
while (millis() - start < 200) {
int adc = analogRead(CURRENT_PIN);
float volts = adc * 3.3 / 4095.0;
float amps = (volts - 2.5) / 0.066;
sumSq += amps * amps;
samples++;
}
return sqrt(sumSq / samples);
}
void triggerCutOff(String reason) {
heaterOn = false;
cutOff = true;
cutOffReason = reason;
digitalWrite(RELAY_PIN, RELAY_OFF);
digitalWrite(BUZZER_PIN, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("CUT-OFF!");
lcd.setCursor(0, 1);
lcd.print(reason);
Serial.println("CUT-OFF: " + reason);
}
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(RELAY_PIN, RELAY_OFF);
digitalWrite(BUZZER_PIN, LOW);
pinMode(FLOW_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(FLOW_PIN), countPulse, RISING);
tempSensor.begin();
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Geyser Safety");
lcd.setCursor(0, 1);
lcd.print("Starting...");
delay(2000);
lcd.clear();
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected");
}
void loop() {
// --- Read temperature ---
tempSensor.requestTemperatures();
float temperature = tempSensor.getTempCByIndex(0);
// --- Read flow: pulses in the last second ---
// YF-S201: about 7.5 pulses per second per litre/minute.
noInterrupts();
unsigned long pulses = pulseCount;
pulseCount = 0;
interrupts();
float flowRate = pulses / 7.5; // litres per minute
totalLitres += flowRate / 60.0; // litres in this second
// --- Read current ---
float current = readCurrentRMS();
// --- Decide: start the heater only if everything is safe ---
if (!cutOff && !heaterOn && temperature > -100 && temperature < TEMP_LIMIT) {
heaterOn = true;
digitalWrite(RELAY_PIN, RELAY_ON);
}
// --- Safety checks ---
if (!cutOff) {
if (temperature <= -100) {
triggerCutOff("SENSOR FAULT");
} else if (temperature > TEMP_LIMIT) {
triggerCutOff("OVERHEAT!");
} else if (current > CURRENT_LIMIT) {
triggerCutOff("OVERCURRENT!");
} else if (heaterOn && flowRate < FLOW_MIN) {
if (noFlowSince == 0) noFlowSince = millis();
if (millis() - noFlowSince > DRY_RUN_SECONDS * 1000UL) {
triggerCutOff("DRY RUN!");
}
} else {
noFlowSince = 0;
}
}
// --- Display ---
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.print(temperature, 1);
lcd.print("C ");
lcd.print(current, 1);
lcd.print("A ");
lcd.setCursor(0, 1);
if (cutOff) {
lcd.print(cutOffReason);
} else {
lcd.print(heaterOn ? "HEATER ON " : "HEATER OFF");
lcd.print(" F:");
lcd.print(flowRate, 1);
lcd.print(" ");
}
Serial.print("Temp: ");
Serial.print(temperature);
Serial.print(" C | Current: ");
Serial.print(current);
Serial.print(" A | Flow: ");
Serial.print(flowRate);
Serial.print(" L/min | Total: ");
Serial.print(totalLitres);
Serial.println(" L");
// --- Upload to ThingSpeak every 20 seconds ---
static unsigned long lastUpload = 0;
if (millis() - lastUpload > 20000 && WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = "http://api.thingspeak.com/update?api_key=" + String(thingSpeakApiKey)
+ "&field1=" + String(temperature)
+ "&field2=" + String(current)
+ "&field3=" + String(flowRate)
+ "&field4=" + String(totalLitres);
http.begin(url);
Serial.print("ThingSpeak response: ");
Serial.println(http.GET());
http.end();
lastUpload = millis();
}
delay(1000);
}T: 62.5C 9.2A (temperature and current)HEATER ON F: 2.1 (heater state and flow in L/min) — or the cut-off reason, e.g. OVERHEAT!The ESP32 board, relay module and buzzer are available at QKZEE Technologies, Shop 20, 1st Floor, Al-Khalil Center, Hall Road, Lahore, and online at qkzeetech.com with delivery all over Pakistan — see the links above. The DS18B20, ACS712, YF-S201, 16×2 LCD and 12V SMPS are available at the Hall Road shop on request.
If the temperature reads −127°C, or the flow stays at 0, message us — tell us what the Serial Monitor shows and which step you are on, and we will help you find the fault. For anything involving mains wiring, ask an adult or an electrician — do not guess.
Chat on WhatsApp Watch on YouTube
Can I use an Arduino Uno for this project?
No. The safety upload needs Wi-Fi, and all three sensors must be read together in one sketch. The Uno has no Wi-Fi. Use the ESP32 as shown in this guide.
Does this system protect against pressure risks or current leakage?
No. There is no pressure sensor and no leakage sensor in this design. It monitors temperature, current and water flow only. The earlier version of this post wrongly claimed it covered pressure and leakage — that has been corrected.
Why the ACS712 30A version?
Because a geyser draws about 9A, and the 30A version's 66 mV per amp keeps the sensor output inside the ESP32's 3.3V ADC range. The 5A and 20A versions have different sensitivities and will read wrong with this sketch.
Why does the flow sensor need a voltage divider?
The YF-S201 outputs 5V pulses, but the ESP32 pins accept 3.3V. The 10kΩ + 20kΩ divider brings the signal down to about 3.3V so it cannot damage the ESP32.
Why does the heater not switch itself back on after a cut-off?
By design. A safety cut-off must stay off until a person checks the fault and restarts the system — an automatic restart could switch a faulty heater back on. Press the ESP32 reset button to restart.
Is this safe to connect to a real geyser?
Only a qualified electrician should wire a real geyser's mains. This is a student prototype: test it with a small load like a 60W bulb first, and treat it as a demonstration of how safety monitoring works — not as a certified safety device.
Where can I buy the parts in Pakistan?
From QKZEE Technologies on Hall Road, Lahore, or online at qkzeetech.com with Cash on Delivery across Pakistan — see the component links above.
Building an intelligent IoT geyser safety system with an ESP32, a temperature sensor, a current sensor and a flow sensor is a strong final year project: it combines three different sensors, safety logic that cuts power on its own, and Wi-Fi upload to a cloud dashboard. Follow the wiring above, test with a small load first, and you will have live temperature, current and flow figures on ThingSpeak to show your teachers and judges.