Drip irrigation timer with zones
Build it step by step
0 of 8 doneSet the buck output
Adjust the LM2596 to 5.0 V with a meter before connecting the Nano.
Wire the relays
Connect the four inputs and the common supply.
Add the flyback diodes
One across each valve, bar to the positive side.
Test with one valve
Run a cycle from the run-now button and listen for the click.
Set the RTC
Use a library example sketch once.
Set the start time
Use select and plus buttons for hour, minute and duration.
Run all four zones
Check each valve opens one at a time.
Install
Mount the box away from water and run the pipes.
How do you build a drip irrigation timer with zones?
An RTC-based controller opens four 12 V solenoid valves in turn at a set time, so a terrace garden or small farm gets water in the cool morning. You need Arduino Nano, DS3231 RTC module, Relay module 4-channel 5 V, 12 V solenoid water valve × 4, Rectifier Diode 1N4007 × 4, 12 V 2 A DC adapter, LM2596 Buck Module, 16x2 LCD with I2C backpack (PCF8574) and Tactile push button 6 mm × 3. It takes 8 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| 12 V adapter + | LM2596 IN+ and all four relay COM terminals | Valve supply and buck input |
| 12 V adapter - | LM2596 IN- and all four valve - wires | Common return |
| LM2596 OUT+ | Nano 5V pin and relay module VCC | Set to 5.0 V with a meter before connecting |
| LM2596 OUT- | Nano GND and relay module GND | Ground |
| Relay IN1 to IN4 | Nano D4, D5, D6, D7 | Zone 1 to 4 control |
| Relay NO terminals 1 to 4 | Valve 1 to 4 + wires | Switched positive |
| 1N4007 diode across each valve | Cathode (bar) to the + wire, anode to the - wire | Flyback protection |
| DS3231 SDA and SCL | Nano A4 and A5 | I2C clock chip |
| LCD I2C SDA and SCL | Nano A4 and A5 | I2C display |
| DS3231 and LCD VCC and GND | Nano 5V and GND | Power |
| Select button | Nano D8 and GND | Choose the setting to change |
| Plus button | Nano D9 and GND | Increase the setting |
| Run-now button | Nano D10 and GND | Start a cycle now |
Code
Each valve is switched by its own relay, and the 1N4007 diode across the valve coil absorbs the voltage spike when the coil switches off, which would otherwise damage the relay contacts and upset the Nano. Zones run one after another so water pressure stays high for each. The start time, minute step and duration are set with the buttons and saved in EEPROM, so they survive a power cut. Use 12 V DC valves rated for the pipe pressure, which is typically very low for gravity-fed drip lines, and keep all electronics in a dry box away from the valves. Mains is only used inside the adapter. Set the DS3231 clock once using an RTClib example sketch. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: RTClib (Adafruit), LiquidCrystal_I2C. Runs zones 1 to 4 one after another.
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ZONES = 4;
const byte RELAY_PIN[ZONES] = {4, 5, 6, 7};
const byte SEL = 8, PLUS = 9, RUNNOW = 10;
const bool ACTIVE_LOW = true; // most relay boards turn on with LOW
byte startHour = 6, startMin = 0, durMin = 10; // saved in EEPROM
byte field = 0; // 0 hour, 1 minute, 2 duration
bool running = false;
byte zone = 0;
unsigned long zoneStart = 0;
byte lastRunDay = 255;
void relay(byte z, bool on) { digitalWrite(RELAY_PIN[z], (on == ACTIVE_LOW) ? LOW : HIGH); }
void allOff() { for (byte z = 0; z < ZONES; z++) relay(z, false); }
bool pressed(byte pin) {
static unsigned long last[16];
if (digitalRead(pin) == LOW && millis() - last[pin] > 250) { last[pin] = millis(); return true; }
return false;
}
void startCycle() { running = true; zone = 0; zoneStart = millis(); allOff(); relay(0, true); }
void setup() {
for (byte z = 0; z < ZONES; z++) { pinMode(RELAY_PIN[z], OUTPUT); }
allOff();
pinMode(SEL, INPUT_PULLUP); pinMode(PLUS, INPUT_PULLUP); pinMode(RUNNOW, INPUT_PULLUP);
lcd.init(); lcd.backlight();
rtc.begin();
byte h = EEPROM.read(0), m = EEPROM.read(1), d = EEPROM.read(2);
if (h < 24 && m < 60 && d >= 1 && d <= 60) { startHour = h; startMin = m; durMin = d; }
}
void loop() {
DateTime now = rtc.now();
if (pressed(SEL)) field = (field + 1) % 3;
if (pressed(PLUS)) {
if (field == 0) startHour = (startHour + 1) % 24;
if (field == 1) startMin = (startMin + 5) % 60;
if (field == 2) durMin = (durMin % 60) + 1;
EEPROM.update(0, startHour); EEPROM.update(1, startMin); EEPROM.update(2, durMin);
}
if (pressed(RUNNOW) && !running) startCycle();
// Start once per day at the set time
if (!running && now.hour() == startHour && now.minute() == startMin && now.day() != lastRunDay) {
lastRunDay = now.day();
startCycle();
}
// One zone at a time so pressure stays up
if (running && millis() - zoneStart >= (unsigned long)durMin * 60000UL) {
relay(zone, false);
zone++;
if (zone >= ZONES) { running = false; }
else { relay(zone, true); zoneStart = millis(); }
}
lcd.setCursor(0, 0);
char l0[17];
sprintf(l0, "%02d:%02d Start %02d:%02d", now.hour(), now.minute(), startHour, startMin);
lcd.print(l0);
lcd.setCursor(0, 1);
char l1[17];
if (running) sprintf(l1, "Zone %d running ", zone + 1);
else sprintf(l1, "Dur %2d min %c ", durMin, "HMD"[field]);
lcd.print(l1);
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Run now | Zones run one after another |
| At the start time | Cycle starts once that day |
| Power cut and restart | Settings remembered |
| Diode removed in test | More relay noise, so keep it fitted |
If it does not work
Relay does not click
Check the logic (ACTIVE_LOW) and the 5 V supply.
Valve does not open
Check the 12 V on the COM terminal and the NO wiring.
Nano resets
Check the flyback diodes and the buck output.
Wrong time
Set the RTC again and check the battery on it.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the drip irrigation timer with zones?
Arduino Nano, DS3231 RTC module, Relay module 4-channel 5 V, 12 V solenoid water valve × 4, Rectifier Diode 1N4007 × 4, 12 V 2 A DC adapter, LM2596 Buck Module, 16x2 LCD with I2C backpack (PCF8574) and Tactile push button 6 mm × 3.
How long does the drip irrigation timer with zones take to build?
About 180 minutes for a intermediate maker, in 8 steps.
How do I know the drip irrigation timer with zones works?
Run now: Zones run one after another. At the start time: Cycle starts once that day. Power cut and restart: Settings remembered.
Relay does not click: what should I check?
Check the logic (ACTIVE_LOW) and the 5 V supply.
Valve does not open: what should I check?
Check the 12 V on the COM terminal and the NO wiring.
Nano resets: what should I check?
Check the flyback diodes and the buck output.
Wrong time: what should I check?
Set the RTC again and check the battery on it.
