Collects rainwater automatically and stops before the tank overflows.
Built and tested by Drisya K S · Industrial Robotics Institute

A smart rainwater harvesting controller. A rain sensor detects rainfall and the ESP32 switches on a pump to collect water into the storage tank. An ultrasonic sensor monitors the tank level; when it is full, the pump stops and a buzzer warns of overflow. Rain status, water level and system status are shown in the Blynk app.
| Component | Qty |
|---|---|
| ESP32 Dev Board | 1 |
| Rain Sensor Module | 1 |
| Ultrasonic Sensor (HC-SR04) | 1 |
| Water Pump | 1 |
| Relay Module | 1 |
| Float Sensor (optional backup) | 1 |
| Buzzer | 1 |
| LED | 1 |
| Jumper Wires / Breadboard | As needed |
| Power Supply | 1 |
| From | Connect to |
|---|---|
| Rain sensor VCC | 3.3V |
| Rain sensor GND | GND |
| Rain sensor DO | GPIO 27 |
| Ultrasonic VCC | 5V |
| Ultrasonic GND | GND |
| Ultrasonic TRIG | GPIO 25 |
| Ultrasonic ECHO | GPIO 26 (via divider to 3.3V) |
| Relay IN | GPIO 14 |
| Relay VCC / GND | 5V / GND |
| Pump | Through relay COM / NO |
| Buzzer + | GPIO 33 |
| LED + (via resistor) | GPIO 32 |
Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the ESP32.
#define BLYNK_TEMPLATE_ID "YourTemplateID"
#define BLYNK_TEMPLATE_NAME "Rainwater Harvesting"
#define BLYNK_AUTH_TOKEN "YourAuthToken"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "YourWiFiName";
char pass[] = "YourWiFiPassword";
#define rainPin 27
#define trigPin 25
#define echoPin 26
#define relayPin 14
#define buzzer 33
long duration;
int distance;
void setup() {
Serial.begin(115200);
pinMode(rainPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(buzzer, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
int rain = digitalRead(rainPin); // LOW = rain
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Blynk.virtualWrite(V1, rain);
Blynk.virtualWrite(V2, distance);
if (distance < 10) { // tank full
digitalWrite(relayPin, LOW); // pump OFF
digitalWrite(buzzer, HIGH);
Blynk.virtualWrite(V3, "Tank Full - Pump OFF");
} else {
digitalWrite(buzzer, LOW);
if (rain == LOW) {
digitalWrite(relayPin, HIGH); // pump ON
Blynk.virtualWrite(V3, "Rain Detected - Collecting Water");
} else {
digitalWrite(relayPin, LOW);
Blynk.virtualWrite(V3, "No Rain - Standby");
}
}
Blynk.run();
delay(1000);
}A smart rainwater harvesting controller. A rain sensor detects rainfall and the ESP32 switches on a pump to collect water into the storage tank.
You need: ESP32 Dev Board (1), Rain Sensor Module (1), Ultrasonic Sensor (HC-SR04) (1), Water Pump (1), Relay Module (1), Float Sensor (optional backup) (1), Buzzer (1), LED (1), Jumper Wires / Breadboard, Power Supply (1). Software: Arduino IDE, Blynk IoT app.
It is rated intermediate and takes about 3–4 hours to build, using the ESP32. The guide on this page explains every connection and step.
The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.
Yes. IRI sells a kit with the parts for this project (PRJ-156). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.