Garden and Agriculture

OWFS and humidity/temperatures



Marc MERLIN has a blog post on using owfs with different 1-wire devices, including the hobby-board moisture sensor (including the caveat about using a transformer for ground isolation, as well as hints on how to convert the current read into humidity values):



Thomas has a post below about his own setup:



Happy Farming

Thomas from Denmark blogs about gardening using OWFS to monitor and plan. (NSLU2 and sensors from HobbyBoards).

Garden temperature and soil moisture logging system

http://happyfarming.com
by Thomas Wagner Nielsen

Background

When you do gardening it's important to know the last frost date, since most plants don't like frost. Another thing like how much moisture is in your soil is also important because you'll want to give your plants the best conditions for growth. You can also save your energy by doing better planning, if you have access to weather data for your local area.


System overview

This is an overview of the OWFS logging system I've built for my garden:


Measurements

The system is able to do two kinds of measurements; temperature and moisture.

Temperature

Temperature measurements are done using the DS18S20 sensor IC from Maxim. For air temperature measurements the sensor is just mounted at the end of a 2 meter long stick. This simple way of doing it does cause some spikes to appear in the measurements, probably due to direct sunlight hitting the IC case. This could be solved by building some kind of shield over the sensor. The same type of sensor is used for soil temperature measurements. The DS18S20 is glued onto a 20 x 20 cm (8 x 8 inch) aluminium plate to get good thermal contact with the soil:



The black tube on the left cable is just a collection of unused wires.

Moisture



In the middle of the picture you can see a moisture meter board from http://hobby-boards.com and on the right a Watermark soil moisture sensor ($32). When the moisture sensor gets wet its electrical resistance goes down, and when it dries up the resistance goes up. The sensor is connected as a part of the moisture meter circuit, which has a 1-wire interface to the rest of the system.

The board needs a separate 9 to 24 volt DC power supply. I have placed the power supply indoors and the power supply current is running in the Ethernet cable as well as the 1-wire data signal, but only to the moisture meter board and not further into the 1-wire network.

As the other sensors in my 1-wire network this board is also accessed through OWFS and I'm using the Current Register of the onboard DS2760 1-wire monitor IC to read out data. The moisture sensor is connected to an onboard timer IC and when the resistance changes so does the oscillating frequency of the IC and its power consumption. This is measured by the DS2760 and the value is stored in the Current Register.

When the moisture sensor is completely wet the value in the Current Register is -1.400 and when completely dry the value is -0.2386. This goes for this particular system.

I've dug a hole about 30 cm (12 inch) deep and put the sensor at the bottom. The soil that I dug up has been mixed with water and poured into the hole to fill it up again. It's important with a close fit between sensor and soil.

NSLU2



I'm using a NSLU2 computer from the company Linksys as the core of the system. The price is about $100 and I think it's available all over the world. This is a small computer with USB and network connection but no keyboard or mouse connected. This a is a bit challenging because you have to do all communication through the network, but when it's up and running it's very convenient. It consumes only 5 watts so it can be left on 24/7. This means that you'll be able to produce a constant flow of information.

Debian

The NSLU2 is running Debian on a 4 GB USB flash memory. The OWFS software and RRDTool is used for generating graphs. I have placed the NSLU2 computer in the windowsill and laid an Ethernet cable out to the raised beds in the garden.

There are a couple of good reason to install Debian on your small NSLU2 computer. Although it's not exactly the Debian version you would use on your desktop PC it smells a lot like it. The file system structure is there, and if you're used to Linux you'll know your way around right after installation is complete. Also, `apt-get' is available to you making it easy to install new programs on the small computer.

I've used a 4 GB USB flash memory stick as disk for the installation. This is not as reliable in the long run compared to a harddrive. Flash memory allows only a limited number of write operations to the disk.

You'll need a hacked version of the Debian installer from the Internet to put on the NSLU2. Search Google for `Debian NSLU2 install'. What you need is a file called di-nslu2.bin around 8 MB in size. It came in a .zip-file called `debian-armel-5.0.zip' last time I did an install. Using the web server interface of the NSLU2 you need to upgrade it with this 8 MB .bin-file.

Scripts

I have Linux scripts running on the NSLU2 that take care of reading sensors in the 1-wire network, and making historical graphs of the readings.
A database for RRDTool is created first:

make_database.sh:
#!/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

The next script updates the RRDTool database.

update.sh:
#!/bin/bash
cd /home/thomas/happyfarming

# Read data from sensors
airtempread=`cat /home/thomas/owfs2/10.4F7494010800/temperature`
soiltempread=`cat /home/thomas/owfs2/10.06A394010800/temperature`
soilmoistread=`cat /home/thomas/owfs2/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
drylimit=0.2368
wetlimit=1.400
range=`echo "$wetlimit-$drylimit" | bc`
a=`echo "(-1)*$soilmoist1" | bc`
b=`echo "$a-$drylimit" | bc`
c=`echo "scale=3; $b/$range" | bc`
d=`echo "100*$c" | bc`
soilmoist=`echo $d | 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 log_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 log_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 log_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 log_m.png -y 2:1 --vertical-label "[deg 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 log_y.png -y 2:1 --vertical-label "[deg 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 log_soil_moisture_h.png --vertical-label "[%]" --start -1h \
DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture [%]"

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

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

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

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

Graphs are uploaded to http://happyfarming.com using this script:

upload.sh:

#!/bin/bash
sleep 30
lftp -u USERNAME,PASSWORD SERVER <<EOF
cd /images/
lcd /home/thomas/happyfarming/
put log_h.png
put log_d.png
put log_w.png
put log_m.png
put log_y.png
put log_soil_moisture_h.png
put log_soil_moisture_d.png
put log_soil_moisture_w.png
put log_soil_moisture_m.png
put log_soil_moisture_y.png
quit 0
EOF

Linux crontab

The system automatically stores the value of its sensors every five minutes using the crontab function in Linux. crontab is a schedule of recurring things to be done in the form of commands to be run on the system. There's different crontab's for different users. In this particular system I'm running crontab commands as root user. As far as I remember it was necessary to do that to have sufficient rights on the system.

To see what is in your crontab at the moment, run this command:

crontab -l

where -l is for list only. Use -e for editing your crontab:

crontab -e

This will start a default editor, in my case `nano', so that you can make changes to your list.

crontab -l on this system gives this output:

# m h dom mon dow command
*/5 * * * * /home/thomas/happyfarming/update_temp_2.sh &> /dev/null
*/5 * * * * /home/thomas/happyfarming/upload_temps.sh

m: Minute. "/5'' means every five minutes.
h: Hour
command: Command to be executed. I run the update_temp_2.sh script every five minutes. "&> /dev/null" takes the output from this command and discards it, so that I don't get a mail every five minutes.

* means at every value, i.e. minute is 1 through 60 or hour is 1 through 24 etc.

Graphs

Here are some examples of the type of graphs the system generates:


(Air and soil temperature for one week.)

As expected the soil temperature is changing much slower than the air temperature because the soil is massive compared to air.


(Soil moisture for one week.)

Future improvements

Rain collector sensor Valve or pump for automatic watering More air temperature sensors

Links

OWFS for managing 1-wire electronics:
https://owfs.org

Supplier of 1-wire electronics


Forum for Hobby-Boards customers


My garden blog

Previous page: Hydroelectric plant
Next page: Setup