How to Build an Intelligent IoT Geyser Safety System for Student and Final Year Projects in Lahore, Pakistan

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.

Intelligent IoT Geyser Safety System Circuit Diagram

Why the ESP32 Only

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.

What the System Monitors

  • Water temperature (DS18B20) — overheating cut-off
  • Current drawn (ACS712) — overcurrent cut-off
  • Water flow (YF-S201) — dry-run cut-off: if the heater is on but no water is flowing, the element is heating air, so power is cut

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.

Hardware Used

  • ESP32 Dev Module
  • DS18B20 temperature sensor (waterproof version)
  • ACS712 current sensor module — 30A version
  • YF-S201 water flow sensor
  • 5V 1-channel relay module (with optocoupler isolation)
  • Active buzzer
  • 16×2 LCD with I2C module (address 0x27)
  • 4.7kΩ resistor (DS18B20 pull-up)
  • 10kΩ + 20kΩ resistors (voltage divider for the flow sensor signal)
  • Breadboard + jumper wires
  • 5V power supply for the ESP32 and sensors

Pin Connections

ComponentESP32 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 / GND3.3V / GND
ACS712 OUTGPIO 34 (analog)
ACS712 VCC / GND5V / 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 / black5V / GND
Relay INGPIO 26
Buzzer +GPIO 25 (buzzer − to GND)
LCD SDAGPIO 21
LCD SCLGPIO 22
LCD VCC / GND5V / GND
ComponentPrice / link
ESP32 Dev ModuleESP32 30-Pin Wi-Fi Bluetooth Development Board — Rs 1,100
1-Channel Relay Module 5V1-Channel Relay Module for Arduino Projects 5V — Rs 155
Active BuzzerActive 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.

How the Safety Logic Works

  • Overheating: water temperature above 75°C → relay OFF, buzzer on, "OVERHEAT!" on the LCD.
  • Dry run: heater on but water flow below 0.1 L/min for 10 seconds → relay OFF, buzzer on, "DRY RUN!" on the LCD.
  • Overcurrent: current above 15A → relay OFF, buzzer on, "OVERCURRENT!" on the LCD.
  • Sensor fault: temperature reads −127°C (sensor disconnected) → relay OFF, "SENSOR FAULT" on the LCD.

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.

Arduino Code

/*
  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);
}

What the LCD Shows

  • Line 1: T: 62.5C 9.2A (temperature and current)
  • Line 2: HEATER ON F: 2.1 (heater state and flow in L/min) — or the cut-off reason, e.g. OVERHEAT!

Testing the System

  1. Test without mains first. Power the ESP32 from USB with nothing connected to the relay's mains terminals. The Serial Monitor should show temperature, current near 0 and flow 0. The heater stays off until the temperature sensor reads a valid value.
  2. Test the flow sensor. Blow or run water through the YF-S201 — the flow reading should rise above 0. If it stays at 0, check the signal wire and the voltage divider.
  3. Test with a small load. With adult supervision, connect a 60W bulb through the relay as the "heater": mains to the relay COM terminal, bulb to the relay NO terminal. The bulb should switch on, and the current should read about 0.27A.
  4. Test a cut-off. Warm the DS18B20 sensor in your hand or in warm water past 75°C — the relay must switch off, the buzzer must sound, and the LCD must show the cut-off reason. The heater must NOT switch itself back on — press the ESP32 reset button to restart.

Troubleshooting

  • Temperature reads −127°C: the DS18B20 is not connected, or the 4.7kΩ pull-up resistor is missing. Check DQ → GPIO 4 and the pull-up from DQ to 3.3V.
  • Flow always reads 0: the sensor's signal wire is not on GPIO 5, or the voltage divider is wrong. Check signal → 10kΩ → GPIO 5, and 20kΩ from GPIO 5 to GND.
  • Current reads 0 with a load on: the load wire is not passing through the ACS712's current terminals, or the wrong ACS712 version is fitted — this sketch is written for the 30A version (66 mV/A). The 5A and 20A versions have different sensitivities and will read wrong.
  • Relay clicks the wrong way: your relay module is active-high, not active-low. Swap the RELAY_ON and RELAY_OFF values at the top of the sketch.
  • LCD shows nothing: check SDA → GPIO 21, SCL → GPIO 22, and try I2C address 0x3F if 0x27 shows nothing.
  • ThingSpeak charts stay empty: check the Wi-Fi password and the API key first, and use a 2.4 GHz network — the ESP32 does not connect to 5 GHz Wi-Fi.

Applications

  • Student and final year projects — a complete sensor + safety + IoT system
  • Home safety demo — show how temperature, current and flow monitoring work together
  • Small shop load monitoring — track a heater's temperature and current
  • Final year project base — add a mobile app, daily usage logs, or SMS alerts on top

Where to Buy the Components

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.

Still Stuck?

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

FAQs

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.

Conclusion

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.