This post is part of a series
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 :-)
I used a simple python program like this to pull back the value (wet or dry / 0 or 1)
#!/usr/bin/python # Start by importing the libraries we want to use import RPi.GPIO as GPIO import os import sys # Set our GPIO numbering to BCM GPIO.setmode(GPIO.BCM) # Define the GPIO pin that we have our digital output from our sensor connected to channel = int(sys.argv) # Set the GPIO pin to an input GPIO.setup(channel, GPIO.IN) if GPIO.input(channel): print '0' else: print '1'
It can be used like so (where 5 is the GPIO pin in question)
python /home/pi/water-system/moisture-live.py 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
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
turn on the relay that powers the sensor
test for moisture
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