Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsMany hostels and flats depend on a caretaker to start the pump. The clock runs it from 5:30 to 6:30 am and 5:30 to 6:30 pm, which covers the morning rush and the evening use, and the LCD shows the pump state. Add the level sensors later to stop it when the tank is full.
Field pumps run on mains or three-phase power. Have a licensed electrician fit a contactor and starter: never connect them to the relay module directly.
Keep to low-voltage loads unless a qualified electrician wires the mains side in an earthed, closed enclosure.
Tick anything you already have and the total updates.
Connects the Uno to your computer to upload code and power it
Temperature-compensated real-time clock (±2 minutes a year) with a coin-cell backup, so the time survives power cuts.
An electrically isolated switch that lets a 3.3/5 V pin turn a 12 V (or mains) load on and off.
Classic 16-character, 2-line LCD with an I²C backpack, so it needs only two signal wires.
Mini pump for the bench model (a field pump goes through a contactor)
Follow the colours: red is power, dark grey is ground, blue is a signal.
The bench model runs the 3–6 V mini pump from a 4×AA holder through the relay (COM and NO). A mains or three-phase field pump must be switched by a contactor that an electrician wires; the relay only drives the contactor coil circuit he provides.
hostel_water_pump_timer.inoVerify & upload in Electrolark// Hostel water pump morning and evening timer
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "hostel-water-pump-timer"
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
// ---- pins ----
const uint8_t RELAY_PIN = 2;
RTC_DS3231 rtc;
const bool RELAY_ACTIVE_LOW = true; // most relay modules switch on when IN is LOW
LiquidCrystal_I2C lcd(0x27, 16, 2);
struct Slot { uint8_t h1, m1, h2, m2; }; // on from h1:m1 until h2:m2 (24-hour clock)
const Slot SLOTS[] = {{5, 30, 6, 30}, {17, 30, 18, 30}};
const int NSLOTS = sizeof(SLOTS) / sizeof(SLOTS[0]);
bool scheduled = false, output = false;
unsigned long lastShow = 0;
void setRelay(bool on) { digitalWrite(RELAY_PIN, (on != RELAY_ACTIVE_LOW) ? HIGH : LOW); }
bool inSlot(int mins) {
for (int i = 0; i < NSLOTS; i++) {
int a = SLOTS[i].h1 * 60 + SLOTS[i].m1, z = SLOTS[i].h2 * 60 + SLOTS[i].m2;
if (a <= z ? (mins >= a && mins < z) : (mins >= a || mins < z)) return true; // slots may run past midnight
}
return false;
}
void setup() {
Serial.begin(115200);
if (!rtc.begin()) Serial.println(F("RTC not found"));
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set from the upload time
pinMode(RELAY_PIN, OUTPUT);
setRelay(false);
lcd.init();
lcd.backlight();
setRelay(false);
}
void loop() {
DateTime now = rtc.now();
int mins = now.hour() * 60 + now.minute();
bool s = inSlot(mins);
if (s != scheduled) { scheduled = s; }
output = scheduled;
setRelay(output);
if (millis() - lastShow > 1000) {
lastShow = millis();
char buf[17];
snprintf(buf, sizeof(buf), "%02d:%02d:%02d ", now.hour(), now.minute(), now.second());
lcd.setCursor(0, 0); lcd.print(buf);
lcd.setCursor(0, 1); lcd.print(F("Pump ")); lcd.print(output ? F(" ON ") : F(" off "));
Serial.print(buf); Serial.println(output ? F("ON") : F("off"));
}
delay(50);
}
The sketch above runs here on a simulated Arduino Uno. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
The coin cell is flat or missing. Some modules need the charging resistor removed when using a CR2032.
Load must be on COM and NO, with its own supply in series.
Your module may be active-HIGH. Set RELAY_ACTIVE_LOW to false.
Some 5 V relay boards do not fully switch off with 3.3 V logic. Remove the JD-VCC jumper, feed JD-VCC from 5 V and VCC from 3.3 V, or use a relay board made for 3.3 V input.
Adjust the contrast pot on the backpack. If still blank, change 0x27 to 0x3F.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider.
The relay is rated for mains, but mains wiring is dangerous. Keep this build on low-voltage loads (12 V pumps, fans, LED strips), or have a qualified electrician fit the relay inside an earthed, closed enclosure.
Use a 5 V USB phone charger or a power bank into the board's USB port. Loads such as pumps, fans and solenoids need their own supply.
9 parts: Uno R3 CH340G ATmega328p Compatible Development Board, Arduino USB-A to USB-B Data Cable for UNO/MEGA, DS3231 Precision RTC Module with EEPROM, 5V Relay Module with Optocoupler (1 channel), LCD1602 16x2 Character LCD (blue, with I2C adapter), Mini Submersible Water Pump 3–6V with 1m tube, Battery Holder (AA), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. 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 2 hours. The build on this page has 9 steps.
No. This page has the complete, tested code (hostel_water_pump_timer.ino). Install these libraries first: RTClib and LiquidCrystal I2C.
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹843 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Character displays and I²C backpacks; Isolation, relays and switching higher-power loads; Real-time clocks and backup batteries.
Ideas that reuse this build: Automatic water tank pump controller and Municipal water supply timer. They are listed under Take it further on this page.
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.
Learning project. Check every circuit and the datasheet of each part before you power it up.
09:30:01 off 09:30:02 off
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.