Project 2.1.16: Multi-zone Irrigation System
Intermediate Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
This project manages several irrigation zones independently while still limiting the system to one active watering zone at a time.
Students will build a three-zone controller, each with its own calibration and thresholds, plus a master pause button for maintenance or emergency shutdown.
The final system should read all three zones, water only the zones that are dry enough, and avoid running more than one zone simultaneously.
Required Components
![]() Soil moisture sensor |
![]() Breadboard, jumper wires, tubing, and water container |
![]() Raspberry Pi Pico 2 W |
![]() 1-channel relay module |
![]() Small DC pump or low-voltage indicator load |
![]() External power supply |
Circuit Connections
| Component terminal | Connect to | Pico physical pin | Notes |
|---|---|---|---|
| Soil sensor AOUT | GPIO 26 | GPIO 26 / physical pin 31 | ADC soil input |
| Master button one side | GPIO 18 | GPIO 18 / physical pin 24 | Uses the internal pull-up in code |
| Master button other side | GND | Any GND pin | Pressing pulls the input low |
| Relay IN | GPIO 15 | GPIO 15 / physical pin 20 | Pump or indicator control |
| Relay VCC and GND | External supply and Pico GND | Power pins | Share ground where required |
| Pump/load positive path | Relay COM to NO contacts | Not a Pico GPIO | External power only |
Wiring Diagram

Raspberry Pi Pico 2 W
┌─────────────────────┐
│ │
│ GPIO 26 ───────────┤──── Zone A Soil AOUT
│ GPIO 27 ───────────┤──── Zone B Soil AOUT
│ GPIO 28 ───────────┤──── Zone C Soil AOUT
│ │
│ GPIO 15 ───────────┤──── Zone A Relay IN
│ GPIO 16 ───────────┤──── Zone B Relay IN
│ GPIO 17 ───────────┤──── Zone C Relay IN
│ │
│ GPIO 18 ───────────┤──── Master Pause Button ──── GND
│ │
│ 3.3V ───────────┤──── Soil Sensors VCC
│ │
│ GND ───────────┤──── Soil Sensors GND
│ GND ───────────┤──── Relay GND
│ │
└─────────────────────┘
Zone A Relay Zone B Relay Zone C Relay
┌──────────┐ ┌──────────┐ ┌──────────┐
│ COM ─────┼────(+) │ COM ─────┼────(+) │ COM ─────┼────(+)
│ NO ─────┼──┐ │ NO ─────┼──┐ │ NO ─────┼──┐
└──────────┘ │ └──────────┘ │ └──────────┘ │
│ │ │
Pump A (+) Pump B (+) Pump C (+)
│ │ │
All pumps (-) ───── External Supply (-)
Step-by-Step Assembly
Step 1: Place the Raspberry Pi Pico 2W
Place the Raspberry Pi Pico 2W on the breadboard so it sits across the center gap. Keep the USB port facing outward so you can easily connect it to your computer.
Step 2: Label the Three Irrigation Zones
Label the soil sensors and relay channels as Zone A, Zone B, and Zone C before wiring. Identify VCC, GND, and AOUT / AO / Signal on each soil sensor.
Step 3: Connect the Soil Sensor Power Rails
Connect each soil sensor VCC pin to 3.3V. Connect each soil sensor GND pin to GND.
Step 4: Connect Zone A Soil Sensor
Connect Zone A AOUT, AO, or Signal to GPIO 26.
Step 5: Connect Zone B Soil Sensor
Connect Zone B AOUT, AO, or Signal to GPIO 27.
Step 6: Connect Zone C Soil Sensor
Connect Zone C AOUT, AO, or Signal to GPIO 28.
Step 7: Place the Relay Hardware
Place the relay hardware where all three control inputs and load terminals are easy to reach. Identify VCC, GND, IN, COM, NO, and NC for each relay channel used.
Step 8: Connect the Three Relay Inputs
Connect Zone A relay IN to GPIO 15. Connect Zone B relay IN to GPIO 16. Connect Zone C relay IN to GPIO 17.
Step 9: Power the Relay Hardware
Power the relay module from the supply required by its label. Connect relay GND to Pico GND and to the external pump or load supply GND where shared grounding is required.
Step 10: Place the Master Pause Button
Place the master pause push button across the breadboard center gap. Connect one side of the master pause button to GPIO 18. Connect the opposite side of the button to GND.
Step 11: Wire Each Zone Load
For each zone, connect the external supply positive wire to that zone relay COM. Connect that zone relay NO to the pump or safe test load positive lead. Connect the pump or load negative lead to the external supply negative wire.
Wiring Check
- [x] Pico 2W is placed correctly across the breadboard center gap
- [x] Zone A soil signal connects to GPIO 26
- [x] Zone B soil signal connects to GPIO 27
- [x] Zone C soil signal connects to GPIO 28
- [x] Zone A relay IN connects to GPIO 15
- [x] Zone B relay IN connects to GPIO 16
- [x] Zone C relay IN connects to GPIO 17
- [x] Master pause button connects between GPIO 18 and GND
- [x] Relay hardware uses external power and shared ground where required
- [x] Each pump or safe test load is switched through its own relay COM and NO path
- [x] No load current is routed through the Pico
- [x] No loose jumper wires
Intermediate Note Label every sensor and relay wire before testing. Calibrate each zone separately, and use the master pause button to confirm all relays turn off before connecting real pumps.
Safety Note Use safe test loads before connecting three real pumps. Use external power for pumps, keep electronics away from water, and run only one zone at a time during this classroom build.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring, library, or code problems.
Hardware Setup
- Build one sensor and relay zone first, then replicate the pattern for the other two zones
- Label every sensor and output channel clearly so the zones do not get mixed up
Test the Input Sensors
- Calibrate the three soil sensors independently
- Confirm that each ADC channel changes only when its own zone sensor changes
Test the Output Devices
- Test each relay channel one at a time before using real pumps
- Confirm that the master pause button forces all outputs off when pressed
Run the Full System
- Dry one zone and confirm that only that zone waters
- Then create multiple dry zones and verify that the controller still waters only one at a time
Save the Project
- Save the final code and record the threshold values used for each zone
- Write down whether the one-zone-at-a-time sequencing matched your pump or water-source limits
Additional Testing and Calibration Checks
Calibration and tuning notes
- Calibrate each zone separately because different probes often behave differently
- Use safe loads before switching three real pumps
- If several zones are dry, expect the controller to service them one by one rather than all together
- Remember that the Pico supports three external ADC zones directly; adding more needs extra hardware
Quick testing checklist
- [ ] All three ADC zones respond independently
- [ ] Each relay channel switches the correct zone
- [ ] Only one zone waters at a time
- [ ] Master pause stops all zones
- [ ] Per-zone thresholds and recovery values work independently
Full Project Code
After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below into a new file, or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.
from machine import ADC, Pin
import time
RELAY_ON = 0
RELAY_OFF = 1
PUMP_RUN_S = 4
MIN_REST_S = 30
master_button = Pin(18, Pin.IN, Pin.PULL_UP)
soil = ADC(26)
relay = Pin(15, Pin.OUT)
master_enabled = True
last_button = time.time()
last_cycle = time.time() - MIN_REST_S
ready = True
SOIL_DRY = 52000
SOIL_WET = 22000
DRY_THRESHOLD = 35
RECOVERY_THRESHOLD = 45
relay.value(RELAY_OFF)
def clamp(value, low, high):
return max(low, min(high, value))
def moisture_percent():
raw = soil.read_u16()
span = SOIL_DRY - SOIL_WET
if span == 0:
return 0
return clamp(int(((SOIL_DRY - raw) * 100) / span), 0, 100)
def water_zone():
global last_cycle, ready
relay.value(RELAY_ON)
print("Zone output ON")
time.sleep(PUMP_RUN_S)
relay.value(RELAY_OFF)
last_cycle = time.time()
ready = False
print("Zone output OFF")
print("Single-zone irrigation system ready")
while True:
now = time.time()
if master_button.value() == 0 and (now - last_button) > 0.3:
master_enabled = not master_enabled
last_button = now
print("Master enabled:", master_enabled)
while master_button.value() == 0:
time.sleep(0.05)
if not master_enabled:
relay.value(RELAY_OFF)
print("System paused by master button")
time.sleep(2)
continue
moisture = moisture_percent()
if moisture >= RECOVERY_THRESHOLD:
ready = True
if ready and moisture <= DRY_THRESHOLD and (time.time() - last_cycle) >= MIN_REST_S:
water_zone()
else:
print("Moisture:{}% Ready:{}".format(moisture, ready))
time.sleep(5)
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
zones list |
Stores sensor, relay, thresholds, and state for each zone | Structured data keeps the multi-zone design manageable |
master_enabled |
Pauses or resumes all irrigation zones | A multi-zone system needs a safe global control |
watered_this_loop |
Allows only one active watering cycle per pass | Sequencing prevents overload on power and plumbing |
| Per-zone ready and last values | Track re-arming and rest timing independently | Each zone should behave according to its own conditions |
Expected Result
Each zone should report its own moisture percentage. When a zone is dry enough, the controller should water that zone and then stop before moving on. If several zones are dry, only one should run at a time. Pressing the master pause button should stop all zones from running until resumed.
Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| The wrong zone waters | The sensor or relay labels are mixed up | Label the hardware and compare each zone one at a time with the code |
| Two outputs run together | The sequencing flag was bypassed or another relay is wired incorrectly | Check watered_this_loop logic and the relay channels carefully |
| One zone never waters | That zone's threshold is too low or its ADC input is wrong | Print the live moisture for that zone and recalibrate it |
| Master pause does nothing | The button wiring or debounce timing is wrong | Test GPIO 18 separately and confirm the Shell message changes when pressed |





