An Arduino-based automatic irrigation system reads soil moisture with a sensor and switches a pump or valve on when the soil gets too dry. Add a small solar panel and battery, and it can water pots or a raised bed from a rain barrel with no mains power or outdoor tap at all.
This guide covers the parts you need, how to wire them safely, how to calibrate the sensor, an example sketch with sensible safety limits, and how to size a solar setup. It’s aimed at small gardens, containers and greenhouse benches. For the bigger picture on automatic watering, see our guide to automatic garden watering systems.
What you’re building
The system has four jobs:
- Sense soil moisture in the root zone.
- Decide whether the soil is dry enough to water.
- Switch a pump or valve on and off.
- Deliver water through tubing and drippers.
Solar adds a fifth: keeping a battery charged so all of that runs off-grid.
Parts list
Controller board
- Arduino Uno or Nano: easy to learn and well documented.
- ESP32 or ESP8266: similar cost, adds Wi-Fi for remote monitoring, and the ESP32 has good low-power sleep modes for solar builds. Note that these boards run at 3.3 V logic.
Soil moisture sensor
- Capacitive sensor (recommended): the electrodes are coated, so it resists corrosion far better than bare-metal probes.
- Resistive probe (avoid for long-term use): cheap, but the exposed metal corrodes, especially if powered continuously.
Seal the electronics at the top of any sensor board; the cut edges and components aren’t waterproof. Our article on soil moisture sensor watering covers sensor types and placement in more depth.
Switching: relay or MOSFET
A board pin can’t power a pump or valve directly. It can only supply a small current, and inductive loads produce voltage spikes when switched off. Use one of these:
- Relay module: simple, isolates the pump circuit, and works with AC or DC loads. Check whether your module is “active high” or “active low”.
- Logic-level MOSFET module: silent, efficient and good for DC pumps and valves. Add a flyback diode across the pump or valve coil if the module doesn’t include one.
Water delivery: pump or valve
- Small DC pump (submersible or diaphragm) to move water from a reservoir. Check the pump’s maximum lift and flow, as small pumps lose flow quickly with height and long tubing.
- DC solenoid valve if you’re switching a pressurized supply. Pick a voltage that matches your power supply.
- Tubing, drippers, and a filter or mesh screen on the pump inlet.
Power
- Mains-powered builds: a plug-in DC adapter sized for the pump plus the board. Avoid wiring anything to mains voltage yourself unless you’re qualified.
- Solar builds: a solar panel, a charge controller suited to your battery chemistry, and a battery. Details below.
Pump from a reservoir or valve on a pressurized supply?
Pump from a reservoir suits balconies, rain barrels and spots without a tap. It’s self-contained and low-pressure, which suits drip emitters. Add a float switch or water level sensor so the pump can’t run dry, as many small pumps are damaged by running dry.
Valve on a pressurized supply suits a tap or mains line. The board opens a solenoid valve, and normal water pressure does the work. If you connect to drinking water, include a backflow preventer and a pressure regulator for drip lines.
A common pitfall with gravity feed: many standard irrigation solenoid valves are pilot-operated and need a minimum pressure difference to open properly. On a rain barrel with only a small height of water above the valve, they may not open fully or at all. For gravity setups, look for valves described as “zero pressure” or direct-acting, or use a pump.
Wiring overview
A typical pump build is wired like this:
- Sensor: VCC to the board’s 5 V or 3.3 V pin (match the sensor’s rating and your board’s analog input limit), GND to GND, signal to an analog input.
- Relay or MOSFET module: control input to a digital pin, module VCC and GND to the board.
- Pump circuit: separate supply positive to the pump, pump negative through the relay or MOSFET to supply ground.
- Common ground: with a MOSFET, the pump supply ground and the board ground must be connected. With an opto-isolated relay module, follow the module’s instructions.
- Flyback diode across the pump or valve terminals, stripe toward the positive side, if not built into the module.
Keep the pump wiring physically separate from sensor wiring where you can, to reduce electrical noise in the readings.
Calibrating the sensor
Raw readings vary between sensors and soils, so calibrate before trusting any threshold:
- Push the sensor into dry soil from your garden or pot and note the raw reading over a few minutes.
- Water the soil until it’s thoroughly wet, let it drain, and note the reading again.
- Use those two numbers as the “dry” and “wet” ends of your scale.
Capacitive sensors usually give a higher reading when dry and a lower one when wet. Set your watering threshold somewhere between the two, then adjust after watching the plants for a week or two.
Example Arduino sketch (pulse and soak with safety cutoff)
This example waters in short pulses with a soak period between them, rather than running the pump until the sensor reads wet. Water takes time to reach the sensor, so a “run until wet” approach tends to overshoot. It also uses two thresholds (start and stop) so the pump doesn’t flicker on and off, and it shuts down if several pulses fail to raise the moisture, which usually means an empty tank, a disconnected tube or a failed sensor.
const int SENSOR_PIN = A0;
const int PUMP_PIN = 7; // drives a relay or MOSFET module, never the pump directly
// Replace with your own calibration readings
const int RAW_DRY = 520;
const int RAW_WET = 260;
const int START_BELOW = 35; // start a watering session below this %
const int STOP_AT = 55; // end the session once this % is reached
const unsigned long PULSE_MS = 15000UL; // pump on-time per pulse (15 s)
const unsigned long SOAK_MS = 600000UL; // wait 10 min for water to soak in
const unsigned long IDLE_MS = 1800000UL; // check every 30 min when not watering
const int MAX_PULSES = 6; // safety limit per session
bool watering = false;
int pulses = 0;
bool fault = false;
int moisturePercent() {
long total = 0;
for (int i = 0; i < 10; i++) {
total += analogRead(SENSOR_PIN);
delay(10);
}
int raw = total / 10;
return constrain(map(raw, RAW_DRY, RAW_WET, 0, 100), 0, 100);
}
void setup() {
pinMode(PUMP_PIN, OUTPUT);
digitalWrite(PUMP_PIN, LOW); // off for an active-high module; reverse if yours is active-low
Serial.begin(9600);
}
void loop() {
if (fault) {
delay(IDLE_MS); // stay off until someone checks the system and resets the board
return;
}
int m = moisturePercent();
Serial.println(m);
if (!watering && m < START_BELOW) {
watering = true;
pulses = 0;
}
if (watering && m >= STOP_AT) {
watering = false;
}
if (watering) {
if (pulses >= MAX_PULSES) { // soil never got wet: empty tank, leak or failed sensor
watering = false;
fault = true;
return;
}
digitalWrite(PUMP_PIN, HIGH);
delay(PULSE_MS);
digitalWrite(PUMP_PIN, LOW);
pulses++;
delay(SOAK_MS);
} else {
delay(IDLE_MS);
}
}
Adjust the pulse length, soak time and thresholds to your pump, emitters and soil. If your relay module is active-low, swap HIGH and LOW for the pump pin, and be aware that the pump may briefly switch on at power-up before setup() runs.
Making it solar powered
A solar automatic irrigation system uses a panel to charge a battery, and the battery runs the board and pump. Ready-made solar drip kits exist for a modest number of pots, but a DIY build lets you size things to your garden.
Work out the daily energy use
Add up watt-hours (Wh) per day:
- Pump: watts × hours of running. For example, a 12 W pump running 10 minutes a day uses 12 × (10 ÷ 60) = 2 Wh.
- Board and sensor: standby current × voltage × 24 hours.
The second figure is often the surprise. A full-size development board left running continuously can draw tens of milliamps all day, which can add up to more energy than a small pump that runs for only a few minutes.
Size the battery and panel
- Battery: enough capacity for several days of use without sun, plus margin, because batteries shouldn’t be run completely flat. Use a charge controller matched to the battery type, whether lead-acid, LiFePO4 or a lithium-ion cell.
- Panel: enough to replace a day’s use in your worst realistic sun conditions, not your best. Panels rarely deliver their rated wattage outside ideal conditions, so size generously.
Place the panel facing the sun and clear of shade during the middle of the day, and angle it so rain washes off dust.
Cut standby power
- Use an ESP32 or a bare microcontroller with deep sleep, waking every 15 to 30 minutes to check the sensor.
- Power the moisture sensor from a digital pin or switched supply only when taking a reading. This also slows corrosion on resistive probes.
- Remove or bypass power LEDs and inefficient voltage regulators on development boards.
Weatherproofing and reliability
- House electronics in a sealed enclosure with cable glands, mounted out of direct sun and above splash height.
- Use outdoor-rated cable and waterproof connectors for anything in the soil.
- Screen the pump inlet and put a filter before drippers; small emitters clog easily.
- Add a low-water cutoff for pumps and a maximum run time in code, as in the sketch above.
- Test for a few days while you’re home before trusting it during a holiday.
Adding Wi-Fi and remote monitoring
With an ESP32 or ESP8266, you can send moisture readings and watering events to your phone, a dashboard, or a home automation platform such as Home Assistant (for example, via ESPHome or MQTT). Remote alerts for “tank empty” or “fault” are the most useful additions, because they tell you when the system needs attention. For off-the-shelf connected options, see smart and IoT plant watering systems.
When a ready-made kit or controller makes more sense
DIY builds are great for learning and for odd situations like a balcony with no tap or an off-grid allotment. For a lawn or multi-zone garden on mains water, a commercial controller is usually more reliable and easier to live with. A hose timer is simplest for tap-fed beds; see how to set up a hose-end water timer. And if you want smart features without soldering, our guide to low-cost smart irrigation controllers covers inexpensive options.