Automated Plant Watering System with Raspberry Pi & Web Dashboard
Create a self‑watering system that monitors soil moisture and waters your indoor plant automatically, all controlled from a web interface.
Overview
This guide walks you through every step—from selecting components to wiring, coding, and launching a Flask web dashboard. The result is a reliable, low‑maintenance watering solution that runs on a Raspberry Pi.
Materials
- Raspberry Pi 3 (any Pi 2/4 works with minor pin changes)
- Soil Moisture Sensor (analog output)
- 5 V Relay Module (single channel)
- 3–6 V Mini Submersible Pump (≤ 200 mL min-1)
- Flexible water hose (1‑inch or smaller)
- Dupont jumper wires (multicolored set, 120 pcs)
- 5 V Power Supply (USB cable + wall charger or 5 V adapter)
- Optional: Small potentiometer for sensor calibration
Power Setup
Use a USB cable as a 5 V source. Strip the cable, solder thicker gauge wires to the red (+) and black (–) conductors, and connect them to a 5 V wall charger. Verify the voltage with a multimeter before connecting to the Pi.
GPIO Wiring (Pi 3)
- Soil Sensor: Positive to pin 2 (5 V), Negative to pin 6 (GND), Signal (yellow) to pin 8 (GPIO 14).
- Relay: IN pin to pin 7 (GPIO 4), VCC to pin 2, GND to pin 5.
- Pump: Connect pump power to the relay’s Normally Open (NO) contact; ground to the Common (COM) contact. When the Pi pulls pin 1 (GPIO 5) LOW, the relay closes and the pump activates.
Attach the hose to the pump’s outlet and position the other end near the plant’s soil. Fill the hose reservoir with water.
Hardware Assembly
Secure the hose to the pump using electrical tape to prevent leaks. Ensure all connections are insulated and the Pi is powered separately from the pump’s power to avoid electrical noise.
Software Overview
The project comprises four Python scripts and a Flask web interface:
- water.py – GPIO abstraction for sensor reading and pump control.
- auto_water.py – Scheduled watering logic.
- web_plants.py – Flask app exposing sensor status and manual controls.
- main.html – Simple dashboard template.
Installing Dependencies
On the Pi, run the following:
$ python3 -m pip install RPi.GPIO flask psutil
GPIO Control Script (water.py)
The script exposes two key functions: get_status() returns a wet/dry string, and pump_on() activates the pump for one second. Test it interactively:
$ python3 >>> import water >>> water.get_status() 'Dry' >>> water.pump_on() Pump activated for 1 s.
If the sensor reports incorrectly, adjust the small potentiometer on the module until the second LED lights while the soil is moist.
Running the Flask Dashboard
Place web_plants.py in the same folder as water.py and create a subdirectory called templates containing main.html. Then start the server:
$ sudo python3 web_plants.py
Navigate to the Pi’s IP address in a browser; you’ll see a dashboard with real‑time moisture status and a manual “Water Now” button. This page is powered by Flask and communicates with the GPIO layer via the helper scripts.
Automate Startup with Cron
To ensure the web server starts automatically after reboot, edit the root crontab:
$ sudo crontab -e
Add the line below, replacing /home/pi/project with your actual path:
@reboot cd /home/pi/project && sudo python3 web_plants.py
Reboot the Pi and confirm the dashboard loads automatically.
Next Steps
With the system operational, you can enhance it by adding:
- Multiple plant modules and a single dashboard.
- Logging of moisture levels to a CSV or database.
- Email or push notifications when watering occurs.
For deeper learning, consult Raspberry Pi GPIO tutorials and Flask‑GPIO integration guides.
Manufacturing process
- How to Read Temperature with a DS18B20 on Raspberry Pi 2
- Home Energy Centre: Monitoring Solar PV, Thermal Panels, and Room Temperatures with Raspberry Pi and Moteino
- Accurate Temperature Monitoring in a Server Closet with Raspberry Pi
- Build a Headless Raspberry Pi 2 Water Alarm with Adafruit T‑Cobbler Plus
- Master Raspberry Pi GPIO: Interfacing a PIR Motion Sensor on B+/Model 2
- Raspberry Pi Home Security System: PIR Motion Detection + Camera Email Alerts
- How to Connect, Calibrate, and Program the HC‑SR501 PIR Motion Sensor with a Raspberry Pi
- gatoBot: Raspberry Pi Zero W Web‑Controlled Robot with Live Video Streaming
- Arduino-Powered Automatic Plant Watering System
- Smart Automated Garden System with Arduino UNO and Raspberry Pi