Logging temperature using an Arduino and AD7410 sensor

This article is a quick and dirty demonstration to hack yourself a temperature data logger which saves its results to an SD card. The sensor of use is a HTU21D, a I²C temperature and humidity sensor.




I hooked up a HTU21D sensor to an Arduino Uno + SD-card shield and let it monitor temperature (and humidity) over an entire day:


Here is a close-up of what happens at night:


Source code:

 SD card datalogger

This example shows how to log data from three analog sensors
 to an SD card using the SD library.

The circuit:
 * analog sensors on analog ins 0, 1, and 2
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

created 24 Nov 2010
 modified 9 Apr 2012
 by Tom Igoe

This example code is in the public domain.

 HTU21D Humidity Sensor Example Code
 By: Nathan Seidle
 SparkFun Electronics
 Date: September 15th, 2013
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 Uses the HTU21D library to display the current humidity and temperature

 Open serial monitor at 9600 baud to see readings. Errors 998 if not sensor is detected. Error 999 if CRC is bad.

 Hardware Connections (Breakoutboard to Arduino):
 -VCC = 3.3V
 -SDA = A4 (use inline 330 ohm resistor if your board is 5V)
 -SCL = A5 (use inline 330 ohm resistor if your board is 5V)


#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "SparkFunHTU21D.h"

//Create an instance of the object
HTU21D myHumidity;

const int chipSelect = 4;

// make a string for assembling the data to log:
String dataString = "";

void setup() {
 // Open serial communications and wait for port to open:
 while (!Serial) {
 ; // wait for serial port to connect. Needed for native USB port only

 Serial.println("HTU21D ready!");

Serial.print("Initializing SD card...");

// see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
 Serial.println("Card failed, or not present");
 // don't do anything more:
 Serial.println("card initialized.");

void loop() {

Serial.println("Writing data...");
 // open the file. note that only one file can be open at a time,
 // so you have to close this one before opening another.
 File dataFile = SD.open("datalog.txt", FILE_WRITE);

// if the file is available, write to it:
 if (dataFile) {
 // print to the serial port too:
 // if the file isn't open, pop up an error:
 else {
 Serial.println("error opening datalog.txt");

void readTemp() {
 float humd = myHumidity.readHumidity();
 float temp = myHumidity.readTemperature();

 // make a string for assembling the data to log:
 dataString = "Time: ";
 dataString += String(millis());
 dataString += String("; Temperature: ");
 dataString += String(temp);
 dataString += String("; Humidity: ");
 dataString += String(humd);
 dataString += String("%");

This was just a quick and dirty hack to get some instant results. I’m planing to do some more logging in the future to get a better understanding of how to approach my self build climate control. Stay tuned for more.

Make a Raspbian SD card for Raspberry Pi under Ubuntu, the easy way

Fast & easy way to setup the Raspbian OS for Raspberry PI.

  1.  Get a 4Gb or higher SD card
  2. Download Raspbian: here
  3. Insert your SD card in your Ubuntu 14.04 system and open the Disks tools (“schijven” in Dutch)

    Schermafdruk van 2014-07-19 20:17:54

  4. Select your SD Card, next go to the upper right corner and click the ‘More Actions’ button. Next select the ‘Restore Disk Image…” menu option.

    Schermafdruk van 2014-07-19 20:20:10

  5. The menu underneath appears, now select your downloaded image file (unzip it first if it’s zipped):

    Schermafdruk van 2014-07-19 20:20:39

  6. You can ignore the message that tells you that your disk image is smaller than the target device, upon first usage you’ll get the menu option to adjust the disk to the total size of the SD card. Press ‘Start restoring…’ and wait for the process to finish.

That’s it, enjoy your Raspbian Pi  setup!