Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsMeasure the water level in a tank with an ultrasonic sensor and switch a filling pump on and off automatically. The sensor sends a burst of sound and measures how long the echo takes to return. Sound travels roughly 0.034 cm per microsecond, and the pulse makes the trip twice, so distance = duration × 0.034 ÷ 2. Mount the sensor facing down at the top of the tank: a large distance means the water is far away and the tank is empty, a small distance means it is nearly full.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Keep water away from the ESP32 and test the pump and tube over a tray first.
Charge 18650 cells only in a proper Li-ion charger and never short the holder's wires.
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
16x2 LCD with I2C backpack: four wires, two lines of text
HC-SR04 ultrasonic distance sensor
1k and 2k resistors: drop a 5V signal to the 3.3V an ESP32 pin can take
L298N board: its on-board regulator turns the 7.4V pack into 5V for the motor
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.
The pump runs at 5V from the L298N's on-board regulator, fed by the 2 x 18650 pack. The relay switches that 5V; the ESP32 only drives the relay.
titan_kit_023_water_tank_automation.inoVerify & upload in Electrolark#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int trigPin = 32;
int echoPin = 5;
int relayPin = 25;
int tankHeight = 30; // cm from sensor to the bottom
int fillBelow = 30; // Start pump below this percent
int stopAbove = 90; // Stop pump above this percent
bool pumpOn = false;
LiquidCrystal_I2C lcd(0x27, 16, 2);
long readDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
long distance = duration * 0.034 / 2;
return distance;
}
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Pump OFF
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Tank Monitor");
delay(2000);
lcd.clear();
}
void loop()
{
long distance = readDistance();
int level = map(distance, tankHeight, 2, 0, 100);
level = constrain(level, 0, 100);
if (level < fillBelow)
{
pumpOn = true;
}
if (level > stopAbove)
{
pumpOn = false;
}
if (pumpOn)
{
digitalWrite(relayPin, LOW);
}
else
{
digitalWrite(relayPin, HIGH);
}
lcd.setCursor(0, 0);
lcd.print("Level: ");
lcd.print(level);
lcd.print("% ");
lcd.setCursor(0, 1);
if (pumpOn)
{
lcd.print("Pump: FILLING ");
}
else
{
lcd.print("Pump: STOPPED ");
}
delay(500);
}
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.
Turn the small contrast pot on the back of the I2C board. If still blank, change 0x27 in the sketch to 0x3F.
These relay modules are active LOW: writing LOW switches them on. The sketch already does this, so check IN goes to the right GPIO.
The pump must sit under water before it starts. Check that the tube is not kinked and that the battery holder is switched on.
The sensor sends a burst of sound and measures how long the echo takes to return. Sound travels roughly 0.034 cm per microsecond, and the pulse makes the trip twice, so distance = duration × 0.034 ÷ 2. Mount the sensor facing down at the top of the tank: a large distance means the water is far away and the tank is empty, a small distance means it is nearly full.
Level: 85% / Pump: STOPPED with the tank nearly full. Move your hand away from the sensor to simulate a falling level. Below 30% the relay clicks and Pump: FILLING appears.
Yes. It is project 23 of 120 in the Geekobot Titan Kit, in level 5 (Smart automation). 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.
12 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Dupont Jumper Wires (40 pcs), LCD1602 16x2 Character LCD Display, 5V Relay Module with Optocoupler, Mini Submersible Water Pump 3–6V, HC-SR04 Ultrasonic Range Finder Sensor Module for Arduino, Carbon Film Resistor 1/4W 5% (Pack of 10), L298N Dual H-Bridge Motor Driver Module, ESP32 38-Pin Expansion Board, plus 2 more. 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 1 hour. The build on this page has 8 steps.
No. This page has the complete, tested code (titan_kit_023_water_tank_automation.ino).
About ₹1,557 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Ultrasonic distance measurement with pulseIn(); Relay logic driven by a measured level; Converting a distance into a percentage; Writing your own function that returns a value.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin. Keep water away from the ESP32 and test the pump and tube over a tray first. Charge 18650 cells only in a proper Li-ion charger and never short the holder's wires.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
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.