solderlab logo


Arduino controlled environmental Sensors

Temperature Sensors

or Arduino Duemilanove + Ethernet Shield and four DS18B20

For work I needed to monitor some temperatures. The guy who did that before was gone and all I got were four DS18B20 (Programmable Resolution 1-Wire Digital Thermometer) devices. So I took my arduino duemilanove + Ethernet shield and started to write a sketch which does the following:

  • starting web client on given ip address
  • reading temperatures of all four devices
  • display temperatures on small webpage and automatically refresh page on given interval
  • update temperatures to pachube to have a kind of data logging and a tool to graph your data
  • (or create your own archive and graph with RRDtool)


You also have the possibility to store the data yourself on the on-board sd card but to be honest I was too lacy and I always wanted to try out this pachube thing. The test setup works well since over one week.

The whole thing is not very impressive nor that complicated. I could set it up within only a few days. Well, the most time I struggled with features that were hard to resolve. They are commented within the sketch that you can find here. Maybe someone finds it useful.

For the code itself I used two external libraries to talk to the OneWire devices and to pachube. You can find good documentation and examples in the web. So it was fun (and useful) to do something with my arduino without LEDs.


snapshot of the graph from the Pachube website


Humidity Sensors

By the time this little project grew up and was extended by humidity sensors (dht22). Also for such devices the implementation into the Arduino IDE framework was quite easy since there are external libraries on the market (easy to find). For data logging I switched from pachube to a file based system where the data is stored on an external server. The server regularly pulls data via tcp/ip from the arduino, e.g. via netcat. For the graphical representation I switched to the OpenSource RDDtool solution. This tool aims to handle all kind of time-series based data and stores it into a so called round-robin database, a circular-buffer archive. For this tool a lot of documentation can be found around the web. Hence, I'll just give a short outline in the following section of what I have done - creating the database, feed it with data and make a nice plot.



As written on the RRDtool website: RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data.

To get it working you first need to create a database which fits your needs.

rrdtool create temperature.rrd --start N --step 3600 DS:dev1temp:GAUGE:7200:0:100 RRA:LAST:0.5:1:8784 RRA:AVERAGE:0.5:24:366

This will create a database file, called temperature.rrd, with one dataset (DS) and two archives (LAST and AVERAGE). I intend to update the temperatures once per hour (3600 s) and I want to save values up to one year (8784 data points).

Now you only need to feed data, the measured temperature, into the database and to create a nice plot of the stored values. I just post a code snipped (not really tested) from a bash script to give you an impression of how it works:


date=`date +"%R %d.%m.%Y"`

data=`echo "Dev1:Temp?" | nc -q 1 <device ip> 23 | sed 's/ /:/g' | sed 's/\(.*\)../\1/'`

if [ ! -z "$data" ]; then
    rrdtool update $path/humtemp.rrd "$date"$updatestring

newdate=`echo $date | sed 's/:/\\\:/g'`

# device 1
rrdtool graph $path/temperatures.png \
-s "- 4 weeks" \
-v "T / C" \
-t "temperature, device 1" \
DEF:mycap=$path/temperature.rrd:dev1temp:LAST LINE2:mycap#0000FF:"temperature" VDEF:mycapcurr=mycap,LAST COMMENT:"last update\: $newdate" GPRINT:mycapcurr:"%4.2lf C"

As you can see, it first fetches the temperature from the arduino and stores it into the data variable. Then it updates the database file with the rrdtool update command. And finally it creates a images file (temperatures.png) with rrdtool graph. It displays the data from four weeks (see image below). For details about the command structure check the RRDtool documentation. This script is called once per hour as a cron job.


rrd graph of one of the temperature devices




+1 # Bill Cherry 2012-07-18 00:17
I'm interested in details/code on the separate server & RRDtool solution for your sensors.

Reply | Reply with quote | Quote
+1 # Bill Cherry 2012-07-18 12:21
Reply | Reply with quote | Quote