Remote plant watering with Raspberry Pi
Andrew O
Table of Contents
Introduction
This project came up when I needed to water my plants while being away from home. I have a peace lily plant that needs to be watered every 2-3 days, and I wanted to automate this process since I would be away for over a month.
The idea was to use a small pump, a Raspberry Pi, and a relay to control the pump, and set up a remote access to the Raspberry Pi. This way, I can water the plant from anywhere, using my phone. With this, I ordered a cheap irrigation kit from Aliexpress, which included a small pump, a relay and some tubing, and started doing my research on how to set it up.
Required components
Here’s what you need for this project:
- Raspberry Pi or any other single board computer with GPIO pins
- Water pump, relay and tubing (look for items like “irrigation kit”, “watering kit” on Aliexpress, Amazon or eBay)
- A water container, size depending on the plant and the frequency of watering
I didn’t use the moisture sensor that came in the irrigation kit, as I wanted to keep it simple and just water the plant every 2-3 days. The moisture sensor could be a good addition if you want to automate the watering process based on the soil moisture level.
Setting up remote access to Raspberry Pi
I assume you already have a Raspberry Pi set up with Raspbian or other Linux distribution, and you have a basic understanding of how to use the terminal and SSH. Otherwise, please refer to the official Raspberry Pi documentation.
The key part of this project is to set up a remote access to the Raspberry Pi, so you can control the pump from anywhere. I will use the Tor network for this, as it is free and I already have it set up on my Raspberry Pi.
To set up remote access, follow the steps from my other article SSH over Tor network to set up the RPi with SSH over Tor network.
If you have something against Tor, use VPN or refer to section “An option for fully automatic watering” below for an alternative approach.
Connecting the pump
The electrical connections in this project are straightforward, displayed on the image below:
The relay is connected to GPIO 12 of the RPi, check the pinout1 for your board. The pump is connected to the relay, and the tubing is connected to the pump. The pump is placed in the water container, and the tubing is placed in the plant pot.
Pump control script
The script will be a simple Python script that will turn the pump on for a set amount of time, and then turn it off. The script will be run on the Raspberry Pi, and will be controlled from the SSH client.
This approach is better that on/off commands, because the network latency can be an issue with Tor and it is better to call the script once and let it run for a set amount of time, then call again if necessary.
Here’s the script:
#!/usr/bin/env python3
# pump.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
LED = 12
timeWatering = 3
GPIO.setup(LED,GPIO.OUT)
GPIO.output(LED, False)
time.sleep(timeWatering)
GPIO.output(LED, True)
print("Plant watered for " + str(timeWatering) + "s")
To use the script, run with no arguments to water the plant for 3 seconds:
python3 pump.py
Check the output:
Plant watered for 3s
You can adjust the timeWatering
variable to water the plant for a different amount of time.
Testing
To test the setup, run the script on the Raspberry Pi and check that the pump is working, first without the water (to avoid any accidents). After testing without the water, place the pump in the water container and run the script again several times - it may need more than one run to start pumping.
An option for fully automatic watering
Once you know how often the pump needs to run and for how long (for example, 15 seconds every 2 days), you can set up a crontab job on the Raspberry Pi to run the script at the set time. This way, you can completely skip the remote access part and have the plant watered automatically.
To set up a crontab job, run:
crontab -e
And add the following line to run the script every 2 days at 8:00:
0 8 */2 * * /usr/bin/python3 /path/to/pump.py
Check out more options for crontab scheduling here.
Conclusion
This project is a simple and fun way to automate the plant watering process, and can be expanded with more sensors and features. The key part is to set up the remote access to the Raspberry Pi, so you can control the pump from anywhere. The pump control script is a Python script that can be run from the SSH client, and can be expanded with more features like moisture sensor readings and automatic watering based on the soil moisture level.
As an alternative to remote access, you can set up a crontab job to run the script at a set time, and have the plant watered automatically. However, this requires more testing and monitoring to make sure the plant is watered correctly.
Have a good day,
Andrew
Recent Posts
Benefits, drawbacks, forearm pain
Andrew O
Leave a comment
Need help? Get 1:1 live session on a trusted platform
Contact me on Codementor to schedule a 1:1 live session to help with your project or to learn something new.