A Raspberry Pi can control a small irrigation prototype, but the useful work starts with the valve, power supply and failure behaviour. This guide builds an attended low-voltage DC test before adding schedules or moisture-based decisions. It does not assume an unknown relay board is safe to connect directly to the Pi.

Plan the watering and hardware

Choose one small zone first. Identify the water source, required pressure, valve direction, tubing and an accessible manual shutoff. A valve designed for a pressurised supply may not work on a gravity-fed container. Check the actual manufacturer’s ratings instead of choosing solely by voltage or fitting size.

A normally closed, non-latching valve is designed to close when its coil is unpowered. That is different from choosing a relay’s normally closed contact. Debris, a stuck mechanism or faulty switching can still prevent the result you expect, so test the complete water path.

List the required components: a supported Raspberry Pi computer with GPIO, current Raspberry Pi OS, suitable storage and Pi power supply, a documented driver, a matched low-voltage DC valve/pump supply, appropriate tubing, fittings and enclosure. Optional sensors need their own compatible interface. Compare the complete cost with a commercial controller; a Pi board alone is not the total project cost.

GPIO and the driver are different power paths

The Raspberry Pi GPIO documentation describes 3.3 V signals. A GPIO pin is a control signal, not a pump or solenoid power supply. Do not connect a motor directly or apply a 5 V/12 V load signal to the Pi’s 3.3 V GPIO.

Use a driver whose input works with 3.3 V logic and whose load ratings suit the actuator, including switching and startup requirements. A relay board labelled “5 V” describes a supply requirement, not proof that its input is Pi-compatible. Check its circuit, trigger polarity and manufacturer wiring instructions.

A DC example is the Adafruit MOSFET driver, which has a documented logic input and integrated flyback protection. Its input switches the load when high. Select it only if the actual valve’s voltage/current and the connectors are within its ratings; the example is not permission to connect an arbitrary pump.

A documented DC wiring example

For that specific driver and a suitable DC load, the control and load paths are distinct. With power disconnected, follow the driver’s pin labels and confirm the Pi pinout:

ConnectionDestination
Pi GPIO17, physical pin 11Driver In control input
Pi groundDriver GND, shared logic/power reference
External DC supply positive, matched to the loadDriver V+
External DC supply negativeDriver GND
Load positiveDriver output terminal marked +
Load negativeDriver output terminal marked −, switched to ground

The Pi keeps its own suitable power supply. The external load voltage goes to the driver’s load supply, not to a Pi GPIO or 3.3 V power pin. Use rated connectors for the load current; a signal breadboard is not a finished outdoor power installation.

This is a low-voltage DC example. An AC valve needs an appropriate different driver and suppression arrangement. A flyback diode placed across a DC coil is not a generic instruction for an AC coil. If your board differs, follow its own documented wiring rather than transferring this table to it.

Prepare the software

Install current Raspberry Pi OS with Imager and configure local access. Enable SSH only if needed for administration. Use GPIO Zero with the supported backend for your Pi; older direct-register GPIO libraries should not be assumed to work on a Pi 5.

sudo apt update
sudo apt install python3-gpiozero
pinout

The GPIO Zero installation guidance describes packages and environments. Check the printed pinout before wiring: GPIO numbers are not physical header numbers. Keep GPIO17 consistent between the wiring and code.

Run one attended pulse test

Begin with the water/load disconnected and verify the driver’s signal indication. The example uses active-high logic for the documented driver above. An active-low relay would need a different verified setting; do not guess the polarity with a pump connected.

Save as irrigation-test.py. It requests one two-second pulse and then attempts to turn the output off and release it, including after a normal interruption:

from gpiozero import OutputDevice
from time import sleep

TEST_SECONDS = 2
driver = OutputDevice(17, active_high=True, initial_value=False)

try:
    driver.on()
    sleep(TEST_SECONDS)
finally:
    try:
        driver.off()
    finally:
        driver.close()
python3 irrigation-test.py

OutputDevice documents polarity and initial state. Those settings apply when the program configures the pin. They do not guarantee the physical load remains off before startup, during a power failure or after a hardware fault.

Reconnect the properly rated load only after confirming the control behaviour. Test opening, closing and the manual water shutoff under observation. Test a program interruption and restart without relying on the software to prove a valve has physically closed. A Python sleep is a software duration, not an independent hardware cutoff.

Measure actual flow before scheduling

Measure the amount delivered over a known interval using an appropriate container and normal operating conditions. Duration alone does not establish water volume. For illustration, a measured flow of 0.6 litres per minute would deliver 0.1 litres in ten seconds; your system’s pressure and tubing determine its actual flow.

Choose the watering amount for the particular zone and observe drainage. Check leaks, clogged outlets and pressure changes. Do not copy a ten-second daily interval as a universal plant requirement or claim that automation always saves water.

Add moisture sensing separately

A moisture sensor may provide an analogue voltage, a digital threshold or an I2C reading. Those are not interchangeable inputs. An analogue sensor needs a compatible external ADC and voltage range; the Pi GPIO header is not an analogue measurement input.

The GPIO Zero ADC documentation describes supported converter interfaces. The Adafruit capacitive soil-sensor guide illustrates a different I2C interface and relative moisture readings. Follow the documentation for the part you actually use.

Calibrate in the same soil and placement, comparing known dry and watered conditions. A displayed 0–100 percentage is not automatically an accurate volumetric water-content measurement. Do not assume “digital HIGH means dry” for every board or library configuration.

Resistive probes can corrode and drift; capacitive designs may avoid exposed sensing electrodes but still need suitable protection. Inspect the probe and its readings regularly, rather than relying on a fixed lifetime or replacement interval.

Before unattended automation

Add scheduling only after the attended test works. Keep the control initially off, limit individual runs and total daily watering, and prevent repeated runs merely because a sensor remains dry. Missing or implausible sensor data should stop automatic watering and request attention.

Account for restarts and overlapping jobs. A loop that waters immediately every time the Pi boots can deliver extra water after repeated power interruptions. Persist or otherwise manage scheduling state, and test recovery before relying on the system while away.

Protect electronics from water, maintain access to the manual shutoff and inspect the actual closed valve/flow behaviour. Independent hardware protection can address failures a software timer cannot. Keep remote administration private and authenticated; a web page alone is not a protected control system.

A useful irrigation prototype combines measured flow, compatible hardware and a recoverable control process. Expand to additional zones only after the first one behaves predictably and can be maintained.