Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsWatering at noon loses much of the water to evaporation, and watering on a timer alone wastes it on days the soil is still wet. This controller does both checks: inside the 6–8 am and 5–7 pm slots it starts the pump when the soil probe reads dry, stops when the soil is moist again, and never runs longer than 20 minutes per slot, so a burst pipe cannot empty the tank.
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.
Capacitive probe that measures soil moisture without exposed metal, so it does not corrode like resistive probes.
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.
farm_drip_irrigation_controller.inoVerify & upload in Electrolark// Drip irrigation controller with time slots
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "farm-drip-irrigation-controller"
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
// ---- pins ----
const uint8_t SOIL_PIN = A0;
const uint8_t RELAY_PIN = 2;
RTC_DS3231 rtc;
const int SOIL_DRY = 520; // reading in dry air: calibrate
const int SOIL_WET = 260; // reading in a glass of water: calibrate
const bool RELAY_ACTIVE_LOW = true; // most relay modules switch on when IN is LOW
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ---- latest readings ----
int soilPct = 0;
struct Slot { uint8_t h1, m1, h2, m2; };
const Slot SLOTS[] = {{6, 0, 8, 0}, {17, 0, 19, 0}}; // watering is allowed only inside these times
const int NSLOTS = sizeof(SLOTS) / sizeof(SLOTS[0]);
const int DRY_PCT = 35, WET_PCT = 60; // start below DRY_PCT, stop above WET_PCT
const unsigned long MAX_RUN_MS = 20 * 60000UL; // safety limit per slot (a broken pipe cannot drain the tank)
bool pumping = false, slotUsed = false;
int lastSlot = -1;
unsigned long pumpStart = 0, lastRead = 0;
void setRelay(bool on) { digitalWrite(RELAY_PIN, (on != RELAY_ACTIVE_LOW) ? HIGH : LOW); }
int slotNow(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 (mins >= a && mins < z) return i;
}
return -1;
}
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() {
if (millis() - lastRead < 1000) return;
lastRead = millis();
DateTime now = rtc.now();
int s = slotNow(now.hour() * 60 + now.minute());
if (s != lastSlot) { lastSlot = s; slotUsed = false; } // a new slot starts with a fresh time limit
soilPct = constrain(map(analogRead(SOIL_PIN), SOIL_DRY, SOIL_WET, 0, 100), 0, 100);
if (!pumping && s >= 0 && !slotUsed && soilPct < DRY_PCT) { pumping = true; pumpStart = millis(); }
if (pumping && (s < 0 || soilPct > WET_PCT || millis() - pumpStart > MAX_RUN_MS)) { pumping = false; slotUsed = true; }
setRelay(pumping);
char buf[17];
snprintf(buf, sizeof(buf), "%02d:%02d Soil %3d%% ", now.hour(), now.minute(), soilPct);
lcd.setCursor(0, 0); lcd.print(buf);
lcd.setCursor(0, 1); lcd.print(pumping ? F("Watering ") : s >= 0 ? F("Slot: waiting ") : F("Outside slot "));
Serial.print(buf); Serial.println(pumping ? F("pump ON") : F("pump off"));
}
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.
Calibrate: note the raw reading in dry air and in water, and put them in SOIL_DRY and SOIL_WET.
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 probe is not reaching wet soil. Move it closer to a dripper or lower WET_PCT.
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. Analog readings run 0–4095 instead of 0–1023, which the ADC_MAX constant handles.
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.
10 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, Capacitive Soil Moisture Sensor – 3.3V/5V Analog Output, 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–3 hours. The build on this page has 11 steps.
No. This page has the complete, tested code (farm_drip_irrigation_controller.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 ₹897 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.
Calibrating an analog sensor with map(); Character displays and I²C backpacks; Isolation, relays and switching higher-power loads; Real-time clocks and backup batteries.
Ideas that reuse this build: Phone dashboard version and Automatic 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.
09:30 Soil 82% pump off 09:30 Soil 82% pump off
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.