Automated Plant Watering System with Raspberry Pi
Automated Plant Watering System with Raspberry Pi Read soil moisture and trigger a pump when plants need water. A practical GPIO project combining sensors and automation. Hardware Raspberry Pi (any model) Capacitive soil moisture sensor (not resistive — they corrode) Small 5V submersible pump Relay module (controls pump from GPIO) MCP3008 ADC chip (Pi has no analog inputs) Tubing and water reservoir Enable SPI for MCP3008 bash sudo raspi-config Interface Options > SPI > Enable Reading Moisture python import spidev spi = spidev.SpiDev() spi.open(0, 0) spi.maxspeedhz = 1350000 def readchannel(channel): adc = spi.xfer2([1, (8 + channel) << 4, 0]) return ((adc[1] & 3) << 8) + adc[2] Returns 0 (wet) to 1023 (bone dry) moisture = readchannel(0) Full Automation Script python from gpiozero import OutputDevice import spidev, time PUMPPIN = 18 DRYTHRESHOLD = 700 # above this = needs water WATERSECONDS = 3 # how long to run the pump pump = OutputDevice(PUMPPIN, activehigh=False) spi = spidev.SpiDev() spi.open(0, 0) def readmoisture(): adc = spi.xfer2([1, (8 + 0) << 4, 0]) return ((adc[1] & 3) << 8) + adc[2] while True: moisture = readmoisture() if moisture > DRYTHRESHOLD: print("Watering...") pump.on() time.sleep(WATERSECONDS) pump.off() time.sleep(30) # wait before re-checking time.sleep(300) # check every 5 minutes Calibration Measure sensor output in dry soil and fully watered soil for your specific potting mix. Adjust DRYTHRESHOLD accordingly — values vary by sensor and soil type.
Related Guides
- Getting Started with ROS2 on Raspberry Pi for Robotics
- How to Control GPIO Pins on Raspberry Pi with Python
- Controlling GPIO Outputs with Python — LED, Relay, and Buzzer
- Raspberry Pi GPIO: Complete Beginner Guide with Python Examples
- How to Set Up OpenCV Machine Vision on a Raspberry Pi
- How to Run a Timelapse Camera with Raspberry Pi
- Reading Sensors over I2C with Raspberry Pi
- Running Home Assistant on a Raspberry Pi 4