This is a tutorial on building a Compost Temperature monitoring system. It details how to build a web connected wireless sensor network and shows one possible way it could be constructed.
A Medium level of knowledge and skills are required. Basic knowledge of soldering and breadboarding will be very useful. I will assume that you know enough Arduino code to understand what a Function is, how a Library is useful, and why Serial Communication is important. And you will need to know enough electronics to understand what I mean with terms like Voltage, Current, Resistance, etc. A (very) basic knowledge of how radio works would also be useful for understanding the concepts, but not essential for following along. This is not advanced by any means and I will attempt to always reference materials that will cover these concepts in greater detail.
This tutorial is not about building a polished final product. I am going to assume that you are accompanied by some basic fabrication skills and are capable of doing some problem solving in this area. I will show an example of my project at the end, but I will not be talking extensively on housing design or fabrication. This will be purely about the code and electronics to get up and running with the various communication types, sensors, and data storage. That being said, by the end of this tutorial you will have a web connected sensor network working on your breadboard. Putting it into a housing will be easy after that.
"Composting is the biological decomposition of organic matter under aerobic conditions." Micro-organisms consume organic material and oxygen and create heat as a waste product. By measuring this heat you can predict decomposition rate, oxygen content (loosely), and the overall health and efficiency of your composting operation. It helps to predict when the pile needs to be turned to introduce more oxygen, when the pile is finished with its hot cook cycle, and if you have effectively killed any pathogens or weed seeds that might be present in the feed stocks. Monitoring is an important aspect to streamlining and creating a stable process and workflow to get a predictable and consistent result through each cook, improving the overall efficiency in the operation.
This project uses short range Radio and Cellular communication to get sensor data from individual probes in the compost to an online database. The hardware will be built on the Arduino platform using the Moteino wireless boards. We will be using thermistors for our temperature sensing, an Adafruit FONA cellular module for our cellular communication and the Sparkfun Data Service for our online database.
Note: You will need an ftdi board to upload code to the Moteino's.
Take a look at these before starting off.
We're going to start this project off by building our Sensor Node. We'll put together the Temperature Sensor first, and then once we've tested that and it's working we'll incorporate the wireless communication. The First step is to make sure you have the all the Libraries installed.
The two you need are here:
Install those and make sure you have an FTDI adapter and the drivers are correctly installed.
Once that is done you should read this quick start guide to the Moteino, there is some helpful information there.
Once that is done, solder the header pins onto the Moteino board because we will be plugging it directly into a breadboard, and cut a piece of wire 6.83 in (743mm) long to use as our antenna. Solder it to the antenna hole on the Moteino. See the images on this page and the Moteino website for reference. Once those are soldered and you've successfully interfaced with the Moteino (try uploading the Blink sketch with the LED pin set to 9), plug it into the breadboard, connect the power and ground to the breadboard buses and we can get started sensing.
For the temperature sensor, we are using a Thermistor. It is a simple, inexpensive and fairly accurate piece of solid state hardware. We are going to be sticking this sensor into a hot, humid, and fairly caustic environment so it is important that it is able to withstand these environmental factors.
The sensor we are using is a 10kOhm Epoxy sealed Thermistor from Adafruit, which they have excellent documentation for. The code I am using is a slightly modified version of theirs. There is no point in re-inventing the wheel, so please read through their documentation in addition to this tutorial for more information about this sensor.
The Hookup is super simple, see the schematic and images attached to this page. We'll be using Analog Input 0.
The code itself consists mostly of math that you don't need to worry about. The math part is cordoned off in its own function because it's better not to look at it. The code takes 5 readings from the Analog Input over a short amount of time and averages them to get a more stable reading (these sensors can be noisy). It then does some magic to convert that resistance into temperature which we print out the Serial Monitor.
Once your temperatures are reading correctly, we will need a way of sending them to the Receiver. To do that, we are using the RFM69 Radio module, that green thing soldered to the back of your Moteino. First thing, make sure you have an antenna soldered to the antenna port of the Moteino board. Without the antenna, the range of this radio is a few inches instead of a few hundred meters. Information about the Antenna's and range can be found on the Moteino Site. All of the connections are already made for us, so we can just initialize the Library and start using it. To get started, I would suggest looking at Andy Sigler's excellent code for some super simple send/receive examples.
In the code so far, we sensing the temperature. What we need to do is to take the sensor value and send it across to another Moteino which will be listening for radio messages. We do that by bundling up this piece of data in a little packet and passing it over the air. This packet is called 'payload'. Once the 'payload' reaches the Receiver, the Receiver will send a quick message back saying "Got your packet, everything looks OK". This is called an acknowledgment (shorthanded to ACK in the code). If an acknowledgment isn't received by the Sender, it will wait a little while and try sending it again. If it tries 5 times and fails, it will give up. This is a really important way of creating stability and accountability in our wireless communication because we need to know if our messages are being received.
To power the Moteino without the computer we will be using a 9 volt battery attached to the VIN pin of the Moteino. This pin sends power to the voltage regulator, which steps it down to 3.3v for use on the board.
Because these sensor nodes are battery powered, power consumption is a really important factor to take into consideration. This is a a bit beyond the scope of this tutorial, but I am going to discuss broadly here. The existing circuit, as you will see should work fine as is, but there is room for optimizations. Each different component consumes some amount of power. I did some current measurements really quickly with a 9V battery powering the Moteino.
You can see here that the biggest hogs of power are the microcontroller and the radio (obviously). Both of those we can put to sleep and reduce the power consumption dramatically. We are unfortunately stuck with the Thermistor consumption without some more advanced circuitry. We use the library made by jeelabs which has a great function called Sleepy. I use it so much I extracted it and made my own library so that I can use just that one function without any of the other stuff. It is here in my github. Sleepy basically just replaces the delay() function.
In the end we are left with a circuit which consumes a nominal ~ 1.5 mW at 9v. A typical 9 volt battery alkaline battery has a capacity of 565mAh, which is 5 watt hours. Our sensor consumes at a rate of 0.0015 watt hours. A good rule of thumb with batteries is that only 50% of their rated capacity is actually usable. That leaves us with 2.5 watt hours of available capacity. From these estimates, we should expect a lifespan of about 1600 hours, or about 2 months, which is completely reasonable for the scope of this project. This, of course, is not taking into consideration the self-discharge rate of the battery.
Now that we have a sensor that can live on its own for a length of time, it's time to build something that receives its messages.