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.
Keep water away from the Nano 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 Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 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.
The brain of every Explorer Kit project
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
L298N board: here only its 5V regulator is used, to feed the pump
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
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, which is fed by the 2 x 18650 pack. The relay switches that 5V; the Nano only drives the relay.
explorer_kit_23_water_tank_automation.inoVerify & upload in Electrolark#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int trigPin = 9;
int echoPin = 10;
int relayPin = 7;
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 the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
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 pin.
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 61 in the Geekobot Explorer 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 Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
11 parts: Generic Nano CH340 Development Board (Soldered), 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, L298N Dual H-Bridge Motor Driver Module, Arduino Nano IO Expansion Shield (328P Compatible), 18650 Battery Holder, plus 1 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 (explorer_kit_23_water_tank_automation.ino).
About ₹1,299 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.
Keep water away from the Nano 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.