Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsA real-time clock keeps the time through power cuts. The relay output is on from 5:45 to 6:30 and from 18:30 to 19:00; press the button for an extra heat-up at any time, and press again to cancel. The LCD shows the clock and whether the output is on.
Never switch a geyser directly with a small relay module. Use a rated contactor installed by a qualified electrician.
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.
Follow the colours: red is power, dark grey is ground, blue is a signal.
The relay output is a control signal. A geyser is a 2 kW mains load: an electrician must connect it through a rated contactor.
geyser_morning_timer.inoVerify & upload in Electrolark// Geyser morning timer with boost button
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "geyser-morning-timer"
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
// ---- pins ----
const uint8_t RELAY_PIN = 2;
const uint8_t BUTTON_PIN = 3;
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, 45, 6, 30}, {18, 30, 19, 0}};
const int NSLOTS = sizeof(SLOTS) / sizeof(SLOTS[0]);
bool scheduled = false, output = false;
unsigned long lastShow = 0;
bool overrideOn = false; // a button press flips the output until the next scheduled change
bool wasDown = false;
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();
pinMode(BUTTON_PIN, INPUT_PULLUP);
setRelay(false);
}
void loop() {
DateTime now = rtc.now();
int mins = now.hour() * 60 + now.minute();
bool s = inSlot(mins);
if (s != scheduled) { scheduled = s; overrideOn = false; }
bool down = digitalRead(BUTTON_PIN) == LOW;
if (down && !wasDown) { overrideOn = !overrideOn; delay(30); }
wasDown = down;
output = scheduled != overrideOn;
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("Geyser ")); 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.
The button is rotated 90°; legs on the same side are already connected. Turn it.
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.
8 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), Tactile Push Button Switch, 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 10 steps.
No. This page has the complete, tested code (geyser_morning_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 ₹637 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; Pull-ups and debouncing; Real-time clocks and backup batteries.
Ideas that reuse this build: Geyser ready light and Porch light 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.