* Automatic plant watering with Raspberry Pi

3. December 2018, Jakub Horák. Categorized as IoT.


Who hasn’t had hers/his plants die at home while traveling for a few days? Unfortunately my plants suffered from this fate too. Since I already have my plants connected to the internet via Raspberry Pi, notifying me whenever the soil gets dry, one solution is to have that same event trigger actual plant watering. That’s what I set out to accomplish. By researching online, I stumbled upon an interesting tutorial Raspberry Pi Automated Plant Watering with Website which describes the hardware build very well, but adds a web server on top, which I find useless. I decided to run my own software stack.

Hardware parts necessary (assuming Raspberry Pi plant sensor is built already):

After getting all the necessary parts, first step is to cut the USB charger phone part off and expose red and black wires. Next, solder the red wire sticking from the pump to the red wire exposed from the USB charger cable.

When the soldering is done, it’s time to connect everything together. See the complete wiring diagram with two moisture sensors in the figure below.

Complete wiring

I have two sensors for two plants, but only one water pump for now.

Ports (as per pinout.xyz) used for the pump are (first relay, then Raspberry Pi 3):

The next step is to fill the water container with water, tape the pump as close as possible to the container’s floor and use something (e.g. a wine bottle) to hold the outlet from the hose. I measured, that the motor can pump 23ml of water each second, thus it should be enough to pump for 1 or 2 seconds each time when the soil is dry.

Watering system

As for software, get my updated scripts from the associated GitHub repo. The configuration from moisture.py can be seen below. First the moisture sensors are set-up:

# Define the GPIO pin that we have our digital output from our sensor
# connected to and URL which to call on sensor state change
sensors = {
        "peace_lily": (17, "** URL 1 **"),
        "parsley": (23, "** URL 2 **")
        }

then the water pumps:

# Define the GPIO pin that we have our digital input to the
# respective relay connected to and number of seconds to pump
# each time
pumps = {
        "parsley": (27, 1)
        }

When I get my second water pump, after wiring, I will just add a new entry under “pumps” with the corresponding pin.

 

In action

Watering system in action

That’s all folks, happy farming!

Tags: , , ,



2 Responses to “Automatic plant watering with Raspberry Pi”

  1. Robert PL Says:

    I like what you’re doing here. Only problem I’ve had so far is Ansible installation. Does it matter which directory all the python scripts and yml files are located?

    Best regards

    Rob

  2. Jakub Horák Says:

    Hi Rob,

    no, it shouldn’t matter, which directory you have the scripts. You just need to run the ansible command from that location. E.g. if you have checked out the GitHub project into rpi-moisture directory, you need to run the command inside rpi-moisture.

Backlink

Leave comment