Garden Irrigation System
Welcome to our Garden Irrigation System page, where we introduce a powerful and efficient solution for automating plant watering tasks using a Raspberry Pi. In this guide, you’ll learn how to set up a smart irrigation system that leverages the Raspberry Pi’s GPIO pins to manage water flow based on real-time soil moisture levels. Designed for garden enthusiasts and greenhouse growers alike, this system ensures optimal plant health by providing the right amount of water precisely when needed. By following this Garden Irrigation System page, you can easily automate your garden irrigation, reducing manual effort and enhancing your plant care routine.
Why Choose a Garden Irrigation System?
On this Garden Irrigation System page, we detail the benefits of using a Raspberry Pi to automate your watering process. Traditional watering methods often lead to under-watering or over-watering, both of which can harm your plants. However, our automated system solves these issues by utilizing soil moisture sensors that monitor water needs and activate a water pump or valve relay accordingly. This precision watering helps maintain the ideal moisture balance in the soil, promoting healthier and more vibrant plants.
How Does the Raspberry Pi-Based System Work?
The Raspberry Pi-based Garden Irrigation System is highly customizable and scalable. Whether you have a small garden or a large greenhouse, this system can be adapted to meet your needs. Moisture sensors are placed strategically around the garden to detect dry soil. When low moisture is detected, the system triggers a water pump or controls valves to deliver water exactly where it’s needed. As a result, this method conserves water and minimizes waste, making it an eco-friendly option for sustainable gardening.
Getting Started with Your Garden Irrigation System
This Garden Irrigation System page provides all the information you need, from setting up your Raspberry Pi and connecting it to the necessary hardware components, to writing and executing the code that automates the irrigation process. You’ll learn how to configure GPIO pins for sensor input and relay control, ensuring smooth operation. With clear instructions, diagrams, and code snippets, even beginners can successfully set up this system.
The Benefits of Automating Your Garden Irrigation
By incorporating an automated Garden Irrigation System into your gardening routine, you gain more than just convenience. You achieve peace of mind, knowing your plants are receiving consistent care—even when you’re not around. Say goodbye to the hassle of manual watering schedules and hello to a smart, efficient, and sustainable way to keep your garden thriving. Explore this Garden Irrigation System page to begin your journey toward smarter gardening today!
Kit List:
- 1x Raspberry Pi 4 running Ubuntu 22.04
- 2x Ultrasonic Water Tank Sensor (HC-SR04)
- 2x Soil Moisture Detect Sensor (LM393)
- 3x 5V 1-Way Relay Module
- 2x DC4.5V Inlet Water Solenoid Electric Valve 1/4″ High Pressure
- 1x Breadboard
Raspberry Pi Pinout:
- Plant Pot 1 valve relay: GPIO 26
- Plant Pot 2 valve relay: GPIO 27
- Water Pump 1 relay: GPIO 22
- Plant pot 1 moisture sensor DO Pin: GPIO 23
- Plant pot 2 moisture sensor DO Pin: GPIO 6
- Ultra Sonic Water Tank Sensor Trigger Pin: GPIO 16
- Ultra Sonic Water Tank Sensor Echo Pin: GPIO 25
Benefits:
- Efficient Water Usage: By automating watering based on soil moisture levels, the system optimizes water usage, preventing overwatering and conserving water resources.
- Convenience: The system provides a hands-free solution for watering plants, reducing the need for manual intervention and allowing users to focus on other tasks.
- Improved Plant Health: Consistent monitoring and timely watering help promote healthy plant growth by ensuring plants receive adequate moisture as needed.
The Garden Irrigation System is suitable for:
- Home gardeners seeking an automated solution to maintain their plants.
- Greenhouse owners looking to streamline watering processes and enhance crop cultivation.
- Agricultural enthusiasts interested in integrating technology to improve gardening practices.
The Garden Irrigation System offers a reliable and efficient method for automating plant watering tasks. With its sensor-based approach and Raspberry Pi integration, the system provides a cost-effective solution for maintaining optimal soil moisture levels, resulting in healthier and more vibrant plants.

#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
# GPIO pin definitions
PLANT_POT_1_VALVE_PIN = 26
PLANT_POT_2_VALVE_PIN = 27
WATER_PUMP_1_PIN = 22
PLANT_POT_1_MOISTURE_PIN = 23
PLANT_POT_2_MOISTURE_PIN = 6
WATER_TANK_TRIGGER_PIN = 16
WATER_TANK_ECHO_PIN = 25
# Ultrasonic water tank sensor ranges
FULL_RANGE = (1, 40)
MEDIUM_RANGE = (41, 81)
LOW_RANGE = (82, 100)
EMPTY_RANGE = (101, float('inf'))
# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(PLANT_POT_1_VALVE_PIN, GPIO.OUT)
GPIO.setup(PLANT_POT_2_VALVE_PIN, GPIO.OUT)
GPIO.setup(WATER_PUMP_1_PIN, GPIO.OUT)
GPIO.setup(WATER_TANK_TRIGGER_PIN, GPIO.OUT)
GPIO.setup(WATER_TANK_ECHO_PIN, GPIO.IN)
GPIO.setup(PLANT_POT_1_MOISTURE_PIN, GPIO.IN)
GPIO.setup(PLANT_POT_2_MOISTURE_PIN, GPIO.IN)
# Global variables
water_tank_empty = False
time_restriction_enabled = True
def check_moisture(sensor_pin):
return GPIO.input(sensor_pin)
def check_water_tank():
GPIO.output(WATER_TANK_TRIGGER_PIN, True)
time.sleep(0.00001)
GPIO.output(WATER_TANK_TRIGGER_PIN, False)
pulse_start = time.time()
pulse_end = time.time()
while GPIO.input(WATER_TANK_ECHO_PIN) == 0:
pulse_start = time.time()
while GPIO.input(WATER_TANK_ECHO_PIN) == 1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 17150
return int(distance) # Convert to integer before returning
def water_tank_status():
distance = int(check_water_tank()) # Convert to integer
if distance < EMPTY_RANGE[1]: # Check if distance is less than upper limit of EMPTY_RANGE
return "Empty"
elif distance < LOW_RANGE[1]:
return "Low"
elif distance < MEDIUM_RANGE[1]:
return "Medium"
elif distance < FULL_RANGE[1]:
return "Full"
else:
return "Out of range"
def run_irrigation_system():
global water_tank_empty
while True:
if time_restriction_enabled and 2200 <= int(time.strftime('%H%M')) <= 600:
print("Time Restriction: Script paused due to time restriction.")
time.sleep(60)
continue
plant_pot_1_moisture = check_moisture(PLANT_POT_1_MOISTURE_PIN)
plant_pot_2_moisture = check_moisture(PLANT_POT_2_MOISTURE_PIN)
print("Ultra Sonic Water Tank Sensor:", water_tank_status())
print("Plant Pot 1 Moisture Sensor:", plant_pot_1_moisture)
print("Plant Pot 1 Valve Relay:", GPIO.input(PLANT_POT_1_VALVE_PIN))
print("Plant Pot 2 Moisture Sensor:", plant_pot_2_moisture)
print("Plant Pot 2 Valve Relay:", GPIO.input(PLANT_POT_2_VALVE_PIN))
if water_tank_empty:
print("Water Tank Empty: Refill required.")
time.sleep(60)
continue
if not plant_pot_1_moisture:
GPIO.output(WATER_PUMP_1_PIN, True)
GPIO.output(PLANT_POT_1_VALVE_PIN, True)
print("Watering Plant Pot 1...")
time.sleep(30)
GPIO.output(PLANT_POT_1_VALVE_PIN, False)
GPIO.output(WATER_PUMP_1_PIN, False)
print("Plant Pot 1 watered.")
elif GPIO.input(PLANT_POT_1_VALVE_PIN):
GPIO.output(WATER_PUMP_1_PIN, False)
if not plant_pot_2_moisture:
GPIO.output(WATER_PUMP_1_PIN, True)
GPIO.output(PLANT_POT_2_VALVE_PIN, True)
print("Watering Plant Pot 2...")
time.sleep(30)
GPIO.output(PLANT_POT_2_VALVE_PIN, False)
GPIO.output(WATER_PUMP_1_PIN, False)
print("Plant Pot 2 watered.")
elif GPIO.input(PLANT_POT_2_VALVE_PIN):
GPIO.output(WATER_PUMP_1_PIN, False)
if plant_pot_1_moisture and plant_pot_2_moisture:
time.sleep(30)
if not GPIO.input(PLANT_POT_1_VALVE_PIN) and not GPIO.input(PLANT_POT_2_VALVE_PIN):
GPIO.output(WATER_PUMP_1_PIN, False)
time.sleep(1)
try:
run_irrigation_system()
except KeyboardInterrupt:
print("\nExiting...")
finally:
GPIO.cleanup()