Arduino Data Logger

Page 1

Adafruit Data logging shield for Arduino - v1.0 A basic demonstration of data collection and representing it with gnuplot

The Adafruit logging shield was one of the first addons for the Arduino to catch my interest. It comes as a kit but assembly is not hard requiring only a couple hours to complete. There are a few surface mount components I had worries about even though I had assembled several 'Heathkit' projects years ago. In the end all went well although as you can see in the photo I did not solder the three smaller connections on the SD card socket as they were not used in this project. The demonstration I'm using is from the Adafruit site using only a temparature and light sensor along with the built in RTC to log the opening and closing of the door, temparature variations and defrost cycle. When this data is ploted on a graph you can see the compressor cycle to cool the fridge down after the door has been opened and also when a defrost cycle occurs. The logging shield saves the data to files on any FAT16 or FAT32 formatted SD card, to be read by any plotting, spreadsheet or analysis program. The included Real Time Clock timestamps all your data with the current time, so that you know precisely what happened and when. Libraries and example code for both SD and RTC are included making setup posible with minimal coding. An onboard 3.3v regulator is both a reliable reference voltage and also reliably runs SD cards that require a lot of power to run, the 3.3v reference signal is used in this project to power the sensors. There is also a prototyping area large enough for several sensors and components. The components I added for the demo are described in the right hand column and on the next page we'll take a quick look at the sections making up the logging shield and how they work together.

The DHT11 temperature-humidity sensor is a low cost package. Accuracy is not that good, (+/- 2 degree C), in the range I'm using but will do adequately for this demonstration. It's the blue package, lower right from center, in the photo. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and outputs a digital signal on the data pin (no analog input pins needed). The light sensor (CdS cell) can be seen just below it and is an analog device. As the squiggly face is exposed to more light, the resistance goes down. When its light, the resistance is about 510K立, when dark it goes up to 200K立.

South Mississippi Linux Users Group (SMLUG) smlug@smlug.org


Let's look at the power supply on the board first. It supplies 3.3V @ 250mA. The 'built in' 3.3v regulator on the Arduino isn't used because its only guaranteed up to 50mA and some SD card need a lot of power when writing. This supply is nice and steady, we'll also be using it as an analog reference in this project. We have two sets of bypass caps to try and keep both 5V and 3.3V supply nice and clean - the 100uF ones are for the low frequency noise and 0.1 for higher frequency

The Arduino has no real time clock so the data shield uses the DS1307 from Maxim, which has a battery backup (CR1220) and communicates with the Arduino via i2c (the SCL and SDA lines). i2c requires pullup resistors on the clock and data lines, which you see as R1 and R2. 2.2K are good values, but if you're in a bind, 1.0K to 10K will probably work fine. The RTC requires a single 12.5pF load crystal at 32.768 KHz, Q1 this is how it keeps time . There are also two LEDs for general purpose blinkin' - we like to use them to tell when the SD card is being written to.

South Mississippi Linux Users Group (SMLUG) smlug@smlug.org


The SD card holder is connected to the Arduino through a buffer IC3. The buffer is a level shifter, converting the 5V signals into 3.3V ones which are safe to use. (For some cards its OK to use 5V signals but you risk the card being permanently damaged!) There is a pull up on the CS line so that if you program the Arduino with a ISP programmer while theres a card in, you wont scramble it. There are two 'unused' lines from the SD card - Card Detect is shorted to ground when a card is inserted. Write Protect is shorted to ground when a card with the safety switch flipped is inserted.

Finally we have the arduino interface. The Datalogger shield uses 6 pins. Analog 4 and 5 are the i2c hardware pins. The SD card uses Digital pins 13, 12, 11, and 10. The first three are pretty much required. If you really need pin 10, you can edit the library header file and change it from pin 10 to any other pin. BUT you must have pin 10 as an output, if its an input, the SD interface wont work (its a really annoying thing about AVRs - not sure why this is). A standard 6 pin ISP header is available in case you want to program the Arduino with code using a stand-alone programmer There is also a RESET button, handy when you want to start the Arduino over!

South Mississippi Linux Users Group (SMLUG) smlug@smlug.org


Now lets do something with it. We'll be using the sensors to gather data and pass it to the shield to be stored on the SD card along with the date and time from the RTC. The way I have the shield configured, readings are being recorded at one second intervals and include millis, stamp, datetime, light, temp, humidity and vcc. The screenshot on the right shows the begining of this file. The first column, millis, is a built-in timekeeper in the Arduino. The stamp column is also generated by the Aurduino and is a sequintial count of events. The datetime column is from the RTC. The light and temp columns are the input from the sensors. Lets take that file and use 'Gnuplot', a portable command-line driven graphing utility for Linux, OS/2, MS Windows, OSX, VMS, and many other platforms to visualize that data. Below are the commands to setup the units used on the x and y axis along with the legend box. set xlabel "Time"

# set the lower X­axis label to 'time'

set xtics rotate by ­270

# have the time­marks on their side

set ylabel "Light level (qualitative)" set ytics nomirror

# set the left Y­axis label

# tics only on left side

set y2label "Temperature in Celsius"

# set the right Y­axis label

set y2tics border

# put tics no right side

set key box top left

# legend box

set key box linestyle 0 set xdata time

# the x­axis is time

set format x "%H:%M:%S"

# display as time

set timefmt "%s"

# but read in as 'unix timestamp'

South Mississippi Linux Users Group (SMLUG) smlug@smlug.org


Next we'll use the 'plot' and 'replot' commands to bring the data into the program and plot it on the graph. plot "fridgeTest_2.cvs" using 2:4 with lines title "Light levels" replot "fridgeTest_2.cvs" using 2:5 axes x1y2 with lines title "Temperature (C)"

`Gnuplot` is a portable command-line driven graphing utility for Linux, OS/2, MS Windows, OSX, VMS, and many other platforms. The source code is copyrighted but freely distributed (i.e., you don't have to pay for it). It was originally created to allow scientists and students to visualize mathematical functions and data interactively, but has grown to support many non-interactive uses such as web scripting. It is also used as a plotting engine by thirdparty applications like Octave. Gnuplot has been supported and under active development since 1986. Gnuplot supports many types of plots in either 2D and 3D. It can draw using lines, points, boxes, contours, vector fields, surfaces, and various associated text. It also supports various specialized plot types. Gnuplot supports many different types of output: interactive screen terminals (with mouse and hotkey input), direct output to pen plotters or modern printers, and output to many file formats (eps, fig, jpeg, LaTeX, metafont, pbm, pdf, png, postscript, svg, ...). Gnuplot is easily extensible to include new output modes. Recent additions include interactive terminals based on aquaterm (OSX) and wxWidgets (multiple platforms).

South Mississippi Linux Users Group (SMLUG) smlug@smlug.org


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.