Monday, June 10, 2013

Garden Monitoring Gadgets

A Previous Year's Tomatoes from our Garden

Note:  This is just a teaser.  A full how-to will follow some time in the future.

As regular readers know, we here at Digital Diner have grown tomatoes and veggies every summer for years.  Recently, we've been experimenting with hydroponics.  It has been pretty amazing seeing how our hydroponics plants perform compared to our more traditional, geoponic garden.  We are still learning, but the results are quite impressive with plants growing much faster, with no herbicides or pesticides and using only a fraction of the water of standard gardening.  There are some complexities, like understanding how to manipulate the nutrients etc, but overall, we have been mightily impressed.

The trusty old SunSPOT
watching over the tomatoes
One of the downsides of this type of gardening is that the plants have trouble quickly if there are any problems with the system.  If a pump or a fogger fails, in a matter of a couple hours the plants wilt and suffer dramatically.  For this reason, Widdakay and I decided to work on a system for monitoring our plants and providing live feedback on the web.  We could have used a prepackged system like Pachube COSM Xively which is designed for collecting sensor data, but what fun would that be?  No, we have to design our own system.  We have some experience with this since for years we have been montoring the tomato plants with some SunSPOTs and soil moisture sensors.  Now we have conceptualized a rather complex system and started to implement it.  It is still a work in progress, but we got far enough yesterday that I thought I'd report on it now.

To start with, we like graphs.  The graph below shows live feed from the sensors in our hydroponic garden.  Right now we have only two sensors connected, but we can easily support several more.  The blue line shows the water level in our ebb and flow hydroponic system.  When it goes high it means that the pump has turned on and water is pumped into the system.  When it drops down, it means water is draining out of the system.  In this type of hydroponic system that cycle occurs regularly when things are working correctly.  When the water level gets too low (due to evaporation) the pump wont turn on and we will see it here in the graph.  Later we will implement some sort of alerts to tell us of this condition, but for now it's just a graph.
The black line shows moisture level in one of our aeroponic systems.  It is using a soil moisture sensor, so it isn't exactly designed for measuring humidity, but it sort of works.  Generally speaking, if that line goes to zero for too long, it means that the fogger is not doing its job and we need to take action. If all is going well, the graph is being updated every few seconds while you watch right now and you should see the blue line periodically bouncing up and down while the black line squiggles around somewhere above 0.  If not, either we are working on the system right now, or we have a problem.

Note that you can scroll around, looking back over historical data, by moving the bar at the bottom.  You can change the time scale by dragging the sides of the region at bottom or clicking one of the buttons along the top left to look at the last 5 minutes, 30 minutes, 6 hours, 1 day or week.

The technology involved in making this system is quite complex, but amazingly quite available to us common folks.  The basic system architecture is shown in the diagram below:

Moisture sensor inside an aeroponic system
We use some inexpensive soil moisture sensors that we found at Jameco.  The systems we are measuring are hydroponic, which means there is no soil, still these sensors fit our needs pretty well.  We connected these to a ChipKit Uno 32.  The ChipKit is a new gadget here at the Diner.  It is a device that is code compatible with an Arduino Uno, but with a much faster PIC32 CPU and with a bit more I/O.  (Stay tuned for full review after we get more experience, but so far we like it).  We chose it for this task because it gives us up to 12 analog inputs compared to only 6 on an Arduino Uno.  A simple C program on this board collects the sensor data every 10 seconds through the analog inputs and sends it over the USB port to a Raspberry Pi.  (We may try replacing the Raspberry Pi with a BeagleBone Black in the future)  The Raspberry Pi runs a Python program that massages the data into appropriate formats and then connects over WiFi to stuff the data into a MySQL database on a server.  We then use a little Javascript and a very cool package called highcharts (free for personal and non-profit use) to plot the data from the database and handle the live updates.

ChipKit being installed on the ebb and flow system

All the code is in a GitHub repository that we will publish here when we get a little further along on the project.  For now, just let us gloat a little about the cool live graphs we got working this weekend.