Interfacing a soil moisture sensor to a WiSense node

This post is about interfacing a low cost soil moisture sensor (the CHIRP plant water level alarm) to a WiSense node. This can help you automate plant watering. Wireless moisture sensors can periodically monitor the moisture level in the soil near the roots of plants and send this data (over a WiSense mesh network) to a Raspberry-Pi. The Raspberry-Pi can then use this data to remotely operate valves in pipes supplying water to your garden. If you don’t want to invest in valves, the Raspberry-Pi can send you an SMS in case a plant gets too dry. You can make it more sophisticated by combining the soil humidity informaton, local weather reports and plant specific data to decide when to water each plant.

I bought a CHIRP soil moisture sensor from Adafruit. This sensor is “open source hardware available under CERN Hardware Licence v.1.1”. The sensor utilizes capacitive humidity sensing instead of the usual resistive sensing (monitoring resistance between two galvanized nails buried in the soil near the roots).

1965-01

(Pic courtesy: adafruit.com)

The “CHIRP” behaves as an I2C slave device (with 7 bit address 0x20). It is not that straight forward to use as compared to commercial sensor ICs from TI, ST, etc. It took me some effort to get it working. The sensor can work in two modes. One is the stand alone mode (default mode of operation) in which it will periodically monitor soil moisture and give out “chirps” when the moisture level indicates that the plant needs to be monitored. The other is the slave mode where it measures humidity/light only when requested by the I2C master node (a WiSense node in our case). The CHIRP can be put in the “slave” mode by resetting it (by toggling it’s reset pin) and sending any data to it (over I2C) right after resetting it. I had to read the description at “wemakethings.net/chirp/” and read the code in the repository to get it to work. Another problem was communicating with the “CHIRP” over I2C. WiSense platform has a “soft” I2C with support for 100 KHz bus speed. This driver (which has worked without issues with more than 30 different sensors) did not work as it is. I had to introduce extra delays in the driver to get it to work. The delay is introduced only when the macro “PLTFRM_CHIRP_PWLA_ENA” is enabled.

The “CHIRP” also measures ambient light using a diode and some analog jugglery.

After some hours of struggling with the I2C code, I was able to get the moisture level from the CHIRP (interfaced to a WiSense FFD node)  to my laptop connected to a WiSense coordinator. I tested the CHIRP’s output by watering the area near the sensor. The CHIRP responded immediately by sending an elevated value (indicating higher moisture content). I configured the WiSense FFD to send moisture data every couple of seconds to the gateway app running on the laptop.

All the code is in pltfrm/inc/chirp_pwla.h and pltfrm/src/chirp_pwla.c. The code has been checked in (to bitbucket.org). The app file “ffd_app_1.c” now supports this sensor.

Here is the code in ffd_app_1.c which calls the driver API to get the moisture level from the “CHIRP”.

chirp_code

You can see (below) the jump in moisture level reported by the the CHIRP is response to watering.

moisture_level_jump

Here are some pics of the setup.

chirp_in_pot_1

chirp_in_pot_2

References:

Posted on February 5, 2015, in Uncategorized. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: