Watermark Soil Moisture Sensor Probe Calibration

OWFS and the 1-Wire bus are able to handle several 1-Wire units at a time and I want to display air and soil temperature together in the same graph, and also add a Watermark soil moisture sensor to the system. The soil moisture sensor is controlled by a PCB from Hobby-Boards.com, but the temperature sensors are connected directly to the 1-Wire bus in a daisy chain.

When the units are connected they show up in the owfs directory. 10.x... are temperature sensors, 30.6... is the ground moisture sensor circuit board, and 81.5... is the USB-to-1-Wire adapter:

$ ssh 192.168.1.xx
$ cd owfs
$ ls -la

total 4
drwxr-xr-x 1 root   root      8 Oct 19 13:58 .
drwxr-xr-x 7 thomas thomas 4096 Sep 28 13:36 ..
drwxrwxrwx 1 root   root      8 Oct 19 15:39 10.06A394010800
drwxrwxrwx 1 root   root      8 Oct 19 15:39 10.4F7494010800
drwxrwxrwx 1 root   root      8 Oct 19 15:39 30.6A1E62120000
drwxrwxrwx 1 root   root      8 Oct 19 15:39 81.592527000000
drwxr-xr-x 1 root   root      8 Oct 19 13:58 alarm
drwxr-xr-x 1 root   root      8 Oct 19 13:58 bus.0
drwxr-xr-x 1 root   root      8 Oct 19 13:58 settings
drwxrwxrwx 1 root   root      8 Oct 19 15:39 simultaneous
drwxr-xr-x 1 root   root      8 Oct 19 13:58 statistics
drwxr-xr-x 1 root   root     32 Oct 19 13:58 structure
drwxr-xr-x 1 root   root      8 Oct 19 13:58 system
drwxr-xr-x 1 root   root      8 Oct 19 13:58 uncached

My previous system only had a single temperature sensor connected to it, so I delete the old RRDtool database:

$ cd /home/thomas/rrdtool/
$ rm database.rrd
$ nano create_database.sh

and add the new temperature sensor and the soil moisture sensor (soiltemp and soilmoist) to a new database using the create_database.sh script:

#!/bin/bash
rrdtool create database.rrd --start N --step 300 \
DS:airtemp:GAUGE:600:U:U \
DS:soiltemp:GAUGE:600:U:U \
DS:soilmoist:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:12 \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:12:168 \
RRA:AVERAGE:0.5:12:720 \
RRA:AVERAGE:0.5:288:365

(Check out my other post about RRDtool for more details on how to get the logging system up and running: How to Use RRDtool on Debian NSLU2 to Capture Temperature Data).

The update_database.sh script also needs an update to include the soil temperature data and the soil moisture data:

#!/bin/bash
cd /home/thomas/rrdtool

# Read data from sensors
airtempread=`cat /home/thomas/owfs/10.4F7494010800/temperature`
soiltempread=`cat /home/thomas/owfs/10.06A394010800/temperature`
soilmoistread=`cat /home/thomas/owfs/30.6A1E62120000/current`

# Format reading
airtemp=`echo $airtempread | cut -c -4`
soiltemp=`echo $soiltempread | cut -c -4`
soilmoist1=`echo $soilmoistread | cut -c -7`

# Calculate soil moisture
a=`echo "(-1)*$soilmoist1" | bc`
soilmoist=`echo $a | cut -c -5`

# Update database
rrdtool update database.rrd N:$airtemp:$soiltemp:$soilmoist

# Create graphs
#0000FF = blue trace color
#CC6600 = brown trace color

rrdtool graph temp_h.png -y 2:1 --vertical-label "[deg C]" \
--start -1h DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_d.png -y 2:1 --vertical-label "[deg C]" \
--start -1d DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_w.png -y 2:1 --vertical-label "[dec C]" \
--start -1w DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_m.png -y 2:1 --vertical-label "[dec C]" \
--start -1m DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_y.png -y 2:1 --vertical-label "[dec C]" \
--start -1y DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph soil_moisture_h.png --vertical-label "[]" \
--start -1h DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_d.png --vertical-label "[]" \
--start -1d DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_w.png --vertical-label "[]" \
--start -1w DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_m.png --vertical-label "[]" \
--start -1m DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_y.png --vertical-label "[]" \
--start -1y DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

Watermark soil moisture sensor circuits need to be calibrated before the system will produce any meaningful results. Therefore the calculation in the above script is limited to converting from a negative to a positive readout, by multiplying with -1. In order to make the calibration you need the minimum and maximum value and afterwards convert to a percentage, i.e. minimum corresponds to a totally dry sensor, and maximum corresponds to a totally wet sensor.

With the raw soil moisture data now available the upload_graphs.sh script needs to be updated to upload the new graphs too:

#!/bin/bash
sleep 30
lftp -u USER,PASSWORD SERVER <<EOF
cd /temp/
lcd /home/thomas/rrdtool/
put temp_h.png
put temp_d.png
put temp_w.png
put temp_m.png
put temp_y.png
put soil_moisture_h.png
put soil_moisture_d.png
put soil_moisture_w.png
put soil_moisture_m.png
put soil_moisture_y.png
quit 0
EOF

Using the above scripts will produce graphs that contain both the air temperature and the soil temperature in the same graph.

Data from the soil moisture circuit are displayed in another graph:

Note that there’s no unit on the Y-axis because it’s still the raw data coming from the soil moisture sensor circuit. The reason for the fast drop shown in the graph is that during calibration I’m controlling the actual moisture. This is not your usual kitchen table project – it turned into a kitchen floor project ;-) :

When I had the Watermark soil moisture probe installed in my previous garden I noticed a strong dependence on soil temperature, which I wanted to compensate for in this new installation. This is a graph produced by my old set up:

You do get a general idea about the soil moisture content, but the temperature influence is clear, as each number on the X-axis represents day of month and the temperature drops each night.

I used an oven and a freezer during calibration to find the real minimum and maximum values, that the system is able to produce.

I had hoped that I could do some math in my scripts and remove this temperature dependence but after seeing the graph for the raw minimum and maximum data produced during calibration I realized that it’s not possible to that after all.

To the left on the X-axis I have a completely dry sensor (using the hot air fan in my oven), and to the right the sensor is completely soaked in a bowl of water:

The graph do show the temperature dependence, but the problem is that the error due to temperature is dependent on the actual soil moisture content, which is also the parameter I want to measure. So to make the correct adjustment, in order to calculate the actual moisture, I would need to know the actual moisture, which is impossible, since the actual moisture is what I wanted to measure in the first place. I guess I had hoped that the two lines would have been parallel, so that the temperature error would have been the same no matter what the actual moisture was. We’re moving into the field of physics, but the question still is: What is the maximum value to be used for calibration?

If the average value of 1.0 is used you’ll get measurements showing more than 100 % when the temperature exceeds 20 deg. C and the sensor is soaked. Choosing 0.7 will only make it worse. If 1.3 is chosen as maximum value the measurements will always be too low, but I’ll use this value in a new script to get the readout converted to a percentage. I’ll show the math and new graphs in my next blog post.

(Update 2011-11-08: Check out my new script: Watermark soil moisture sensors calibration calculator)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>