Temperature Data Logger

This is our third project with Michael Margolis, this time using an I2C digital temperature & relative humidity sensor.  A typical application might be monitoring an internal space to check comfort levels achieved.  We are using the Sensirion SHT11 sensor in this example as it measures both values on one small site.  We have had a neat little PCB made which completes the kit nicely and gets you up and running pretty quickly, albeit after soldering up some tiny SMD components. 

The Seeeduino Stalker sketch is nicely written by Micahel Margolis and takes care of some of the pitfalls experienced with the Stalker demo code.  The sketch will either create a new file on the card if it doesn't exist and start writing to it or it will append an existing file - gone are the frustrations of non-zero byte files and formatting sensitivities - it just works much better.

Michael has also included a write error LED which lets you know if you have a problem writing to the microSD card without having to pop the card out and have a look.  The sketch relies on the SENSIRION library by Markus Schatzl & Carl Jackson with a little tweak by Arduino Forum member tasasaki to polish it off nicely - thank you all for your work on this.  The sketch & library are available below - enjoy, and please let us know how you get on via the comments section at the bottom of the page.

The Parts List:

  • 1 no. Seeeduino Stalker 168  (Battery for the on-board Real Time Clock not included)
  • 1 no. Breakout board for the SHT1x or SHT2x sensor
  • 1 no. SHT11 - I2C Temperature & Relative Humidity sensor
  • 2 no. SMD 10K resistors
  • 1 no. SMD 0.1uF capacitor
  • 1 no. LED to show card write errors
  • 1 no. 100Ω resistors for the LED
  • 1 no. 256Mb microSD card

The wiring is simple enough:

Once you have soldered up the breakout board you have 4 connections to make to the Stalker board - the breakout board looks like this before & after soldering.



Once you are all soldered up connect the breakout up as shown:


The LED:

Solder a 100Ω resistor to the positive (longer) leg of the LED.

This Write Error LED is on Stalker digital pin 6 so the LED positive (with the resistor attached) goes to Stalker digital pin 6 and the negative leg (adjacent to the flat on the plastic LED housing) goes to Stalker GND.

Mounting the sensors:

I need to work out a nice mounting for this sensor but just just remember that the relative humidity is sensed via capacitance and should be 'IN' the air you are measuring.


The Arduino Sketch:

You need to download the FAT16 Arduino library from http://code.google.com/p/fat16lib/ and place the files in your ...\arduino-0019\libraries  (or similar if using a different Arduino IDE version) folder before you attempt to upload your sketch (downloaded from the bottom of the page).

You can adjust the logging interval using this line in the code:

const long logInterval = 300;

The 300is the interval, in seconds, at which the data gets written to the SD card.  In this case every 5 minutes.  A microSD card of 256Mb is enough space to store about 8 million time stamped data records which at a 5 minute logging interval equates to about 76 years worth of data - should be enough !

You should now be set - I have assumed you have successfully uploaded the sketch below to your Stalker data logger and inserted your SD card ready to power up for your data logging session.

So, all being well, the Stalker onboard LED will be blinking every time a sample is taken and gets written to the microSD card.  Once you have collected your desired data period you can download your CSV file from the microSD card which will be in the following format:


Pretty good - but even better if you graph it out in your spreadsheet:


This graph shows temperature in centigrade, relative humidity and dew point recorded over a 2 day period in our bathroom.  You can clearly see the heating cycle and the two shower spikes, less obvious is the bath taken the evening before the two showers.  Have fun & do share your experiences via the comments section at the bottom of the page.


The Sketch:

You can also download the PDE directly from the link at the bottom of the page along with the Sensirion library.

 * SimpleSHT11Logger -
 * This version logs the temperature every 5 minutes
 * change logInterval variable to change interval
 * Copyright Michael Margolis 2010
 * In association with www.airsensor.co.uk

#include <Fat16.h>  // the SD Card library - http://code.google.com/p/fat16lib/
#include <Wire.h> 
#include <Time.h> 
#include <DS1307RTC.h> // a basic DS1307 library - http://www.arduino.cc/playground/Code/Time
#include "Sensirion.h" // a nice library from - http://www.arduino.cc/playground/Code/Sensirion

const uint8_t dataPin  =  2;
const uint8_t clockPin =  3;

float temperature;
float humidity;
float dewpoint;

Sensirion tempSensor = Sensirion(dataPin, clockPin);
const int  fileLedPin  =  6;  // LED to indicate a file error
const long logInterval = 60; // the interval in seconds between each log
const char *fileName = "logdata.csv";  // the name of the log file
SdCard card;
Fat16 LogFile;
void setup(void)
  pinMode(fileLedPin, OUTPUT);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  // initialize the SD card
  if (!card.init())
  // initialize a FAT16 volume
  if (!Fat16::init(&card))
  // open file for append, create if it doesn't exist 
  if (!LogFile.open(fileName, O_CREAT | O_APPEND | O_WRITE))
  // clear write error
  LogFile.writeError = false;
void loop(void)

   tempSensor.measure(&temperature, &humidity, &dewpoint);
   time_t timeStamp = now(); 
   // write the data to the card at the end of every line
    if (!LogFile.sync())
    delay(logInterval * 1000L);   
// routine handle file errors
void error(int err)
  // blink forever
   digitalWrite(fileLedPin, HIGH);
   delay(err * 200);
   digitalWrite(fileLedPin, LOW);
void printDateTime(time_t t)
  printDigits(hour(t),':' );
  printDigits(minute(t),':' );
  printDigits(second(t),',' );  // uncomment this to print seconds (and replace the comma above with colon)
  // print a space here if you need it
  printDigits(day(t),'//' ); 
  printDigits(month(t),'//' );  
//  LogFile.print(year(t));  // prints year using 4 digits
  LogFile.print(year(t)-2000);  // prints year using 2 digits
void printDigits(int digits, char seperator)
  // utility function time with leading 0
  if(digits < 10)

4.5/5 rating (2 votes)

Comments (4)

  • Luis
    10 February 2012 at 19:33 |

    Hello there!

    Great project you have here!
    I wold like to make one, but with two "little" modificatins, which are:

    Another sensor to measure the air pressure;
    Being able to create a "stand-alone" outside station communicating via XBee (or other wireless modules).

    Would it be doable starting from this project?


    • Administrator
      10 February 2012 at 21:47 |

      Hi Luis, Your project is completely doable, I would recommened the BMP085 air pressure sensor to complete the hardware list: Stalker, SHT11 & Xbee - all well supported by the Arduino community. Have you had a look at our new CO2 shield? This has the SHT11 & BMP085 onboard - I am hoping to publish the demo code soon so you can see how it works - sending via Xbee is very similar to the Serial.print code so you should be fine there too. Hope that helps and that you get your project up and running.

      • Luis
        10 February 2012 at 22:06 |

        Hello Admin,

        Thanks for your reply.
        I think I'll give it a try, and definitely do a version with ethernet support.

        Unfortunately the link above to AirSensor -Kit (which have a typo) does not work.
        Can you fix that?


        • Administrator
          11 February 2012 at 10:07 |

          Hi Luis, The kit is discontinued as it was based on the old Stalker 1, I need to update the article so it doesn't link to this old kit. If you would like to place an order for the various parts I can include the SHT11 sensor on a small PCB for £15 each - please use the custom payment unit in the shop to purchase this (ie buy 15 custom units).

Leave a comment

Please login to leave a comment.