Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsRunning all sprinklers at once drops the water pressure so none of them work well. This timer opens one solenoid valve at a time: zone 1 for ten minutes, then zone 2, 3 and 4, starting at 6 am. The button starts or stops a cycle by hand. The clock keeps time through power cuts.
Keep the board, relays and adapter in a weatherproof box above the ground. Only the 12 V valve wires go outside.
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.
Four isolated relays on one board for four separate low-voltage loads.
Follow the colours: red is power, dark grey is ground, blue is a signal.
The 12 V adapter feeds each valve through its own relay (COM and NO). Only one valve runs at a time, so a 2 A adapter is enough. Power the Uno from USB or its DC jack.
four_zone_garden_irrigation_timer.inoVerify & upload in Electrolark// Four-zone garden irrigation timer
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "four-zone-garden-irrigation-timer"
#include <Wire.h>
#include <RTClib.h>
// ---- pins ----
const uint8_t RELAY_1 = 2;
const uint8_t RELAY_2 = 3;
const uint8_t RELAY_3 = 4;
const uint8_t RELAY_4 = 5;
const uint8_t BUTTON_PIN = 6;
RTC_DS3231 rtc;
const int START_H = 6, START_M = 0; // daily start time
const int ZONE_MIN = 10; // minutes per zone
const uint8_t ZONES[4] = {RELAY_1, RELAY_2, RELAY_3, RELAY_4};
int running = -1; // zone now watering, -1 = none
unsigned long zoneStart = 0;
int lastStartDay = -1;
void setZone(int z) {
for (int i = 0; i < 4; i++) digitalWrite(ZONES[i], i == z ? LOW : HIGH); // active-LOW relay board, only one valve at a time
running = z; zoneStart = millis();
if (z >= 0) { Serial.print(F("Watering zone ")); Serial.println(z + 1); } else Serial.println(F("All zones off"));
}
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(BUTTON_PIN, INPUT_PULLUP);
for (int i = 0; i < 4; i++) pinMode(ZONES[i], OUTPUT);
setZone(-1);
}
void loop() {
DateTime now = rtc.now();
if (running < 0 && now.hour() == START_H && now.minute() == START_M && now.day() != lastStartDay) { lastStartDay = now.day(); setZone(0); }
if (digitalRead(BUTTON_PIN) == LOW) { setZone(running < 0 ? 0 : -1); while (digitalRead(BUTTON_PIN) == LOW) delay(10); } // start or stop by hand
if (running >= 0 && millis() - zoneStart > ZONE_MIN * 60000UL) setZone(running < 3 ? running + 1 : -1);
delay(200);
}
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.
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. 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 (4 channel), Tactile Push Button Switch, 4 × 12V Solenoid Water Valve 1/2" (Normally Closed), DC Power Adapter 12V 2A (5.5x2.1mm), 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 3 hours. The build on this page has 9 steps.
No. This page has the complete, tested code (four_zone_garden_irrigation_timer.ino). Install this library first: RTClib.
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 ₹1,803 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.
Isolation, relays and switching higher-power loads; Pull-ups and debouncing; Real-time clocks and backup batteries.
Ideas that reuse this build: Farm drip irrigation controller and Auto plant watering. 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.
All zones off
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.