Intermediateraspberry-pi

Smart Irrigation System with Raspberry Pi

Automated garden irrigation system with soil moisture sensing, weather API integration, and scheduling.

5-7 hours
$50-80
Alex Chen
Smart Irrigation System with Raspberry Pi

Parts List

  • Raspberry Pi Zero W
  • Soil Moisture Sensors (x4)
  • Solenoid Valves
  • Relay Board
  • Water Pump
  • Tubing

Step-by-Step Instructions

1

Set Up Raspberry Pi

Flash Raspbian Lite to the MicroSD card and boot the Raspberry Pi Zero W for initial configuration. Run sudo apt update && sudo apt upgrade, then install Python 3, pip, and the required GPIO libraries. Enable SSH and I2C interfaces through raspi-config to prepare for sensor communication and remote management.

2

Wire Moisture Sensors

Connect the analog output of each soil moisture sensor to the ADS1115 ADC module since the Pi Zero W does not have native analog inputs. Wire the ADS1115 to the Pi via I2C (SDA to GPIO 2, SCL to GPIO 3) and mount the sensors in each garden zone at root depth. Calibrate each sensor by recording dry and wet baseline readings to set accurate moisture thresholds.

3

Configure Valves

Wire each solenoid valve through the relay board, connecting the relay COM and NO terminals in series with the valve power supply. Assign each relay channel to a GPIO pin (GPIO 17, 27, 22, 23) and label each zone clearly on the tubing. Test each valve individually by toggling its relay from a Python script to confirm water flows only to the intended zone.

4

Write Scheduling Code

Create a Python script that reads moisture levels from all four sensors at configurable intervals and triggers watering when readings fall below the calibrated threshold. Implement a time-based scheduler using the schedule library so each zone has independent watering windows. Add logging to record moisture history and watering events for later analysis and schedule optimization.

import time
import schedule
import board
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

ads = ADS.ADS1115(board.I2C())
sensors = [AnalogIn(ads, ADS.P0), AnalogIn(ads, ADS.P1),
           AnalogIn(ads, ADS.P2), AnalogIn(ads, ADS.P3)]
VALVE_PINS = [17, 27, 22, 23]
THRESHOLD = 15000

def water_zone(zone):
    import RPi.GPIO as GPIO
    GPIO.setup(VALVE_PINS[zone], GPIO.OUT)
    GPIO.output(VALVE_PINS[zone], GPIO.HIGH)
    time.sleep(3)
    GPIO.output(VALVE_PINS[zone], GPIO.LOW)

for i in range(4):
    schedule.every().day.at("06:00").do(water_zone, i)
    schedule.every().day.at("18:00").do(water_zone, i)

while True:
    schedule.run_pending()
    time.sleep(1)
5

Add Weather Integration

Sign up for a free OpenWeatherMap API account and obtain an API key for your location. Modify the irrigation script to fetch forecast data and skip scheduled watering if rain is predicted within the next 24 hours. Add a manual override web interface so you can trigger or suspend watering from your phone when conditions change unexpectedly.