Automated chilli watering system part 4 - Soil moisture

This post is part of a series

Soil Moisture

Technically speaking this part could also be considered optional - you could skip the detection of soil dryness and attempt to water on a certain frequency like once daily or twice daily. Past experience tells me that chillies dont like to be over watered and so I decided to go with the soil moisture detection method.

You can buy simple soil moisture detection devices on the Internet such as the ones in this amazon link or you could decide to make your own with a couple of nails and a resistor as shown in this Instructables article. I went with the first option just for speed.

In the below screen-shot you can see me experimenting to see if I could drive all 6 sensors at once - the answer is yes :-)

water probes

I used a simple python program like this to pull back the value (wet or dry / 0 or 1)


# Start by importing the libraries we want to use

import RPi.GPIO as GPIO
import os
import sys

# Set our GPIO numbering to BCM

# Define the GPIO pin that we have our digital output from our sensor connected to

channel = int(sys.argv[1])

# Set the GPIO pin to an input
GPIO.setup(channel, GPIO.IN)

if GPIO.input(channel):
    print '0'
    print '1'

It can be used like so (where 5 is the GPIO pin in question)

python /home/pi/water-system/ 5

And would return 0 or 1 to indicate if it was wet or dry. I used it exactly as shown above for just over a week and then ran into my first setback.


In less than 2 weeks my probe broke and removing it from the soil showed why

broken probe

In hindsight its obvious, its just electrolysis. A quick look on Stack Exchange and you will see its a common mistake. The simple solution is to only apply power when you want to take a reading - in my case I will only check the moisture twice a day, so I decided to only power it for a few seconds each time, this will greatly increase the lifespan of these sensors. Also, they are very cheap, so replacing them from time to time is fine

There are a few ways to achieve this, however as I had bought an 8 relay board (for controlling the power to my pumps, I decided to use that. So the script now does the following

  1. turn on the relay that powers the sensor

  2. short wait

  3. test for moisture

  4. turn off the relay

Since adopting this approach I havent worn out any moisture sensors


This part of the project was based on the following article

See also