Wimpie van den Berg
Published © GPL3+

Temperature and Humidity Data Logger

This project shows you how to measure Temperature and Humidity and record data on an SD-Card with an Arduino Uno and an Ethernet Shield.

BeginnerFull instructions provided30 minutes50,940
Temperature and Humidity Data Logger

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Arduino UNO
Arduino UNO
×1
Arduino Ethernet W5100 Shield for Uno
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
9V Battery Clip
9V Battery Clip
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

The SD-Card must be inserted in the slot.

The final product

Code

Temp_and_Humid.ino

Arduino
Use the SD card data logger in the Arduino IDE examples and add the code for the DHT11 sensor as shown in the code below. The SD-card example allows you to log data from up to 3 sensors. Make sure you change line 57 middle segment from analogPin < 3 to analogPin < 1.
/*
  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.

 */

#include <SPI.h>
#include <SD.h>
#include <dht.h>

dht DHT;

#define DHT11_PIN A0

const int chipSelect = 4;

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


  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:
    return;
  }
  Serial.println("card initialized.");
}

void loop() {
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 1; analogPin++) {
    int chk = DHT.read11(DHT11_PIN);
    dataString += String(chk);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

  // 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) {
    dataFile.println(DHT.temperature);
    dataFile.println(DHT.humidity);
    dataFile.close();
    // print to the serial port too:
    Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(600000);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

Credits

Wimpie van den Berg

Wimpie van den Berg

2 projects • 27 followers
I am an Industrial Engineer and Entrepreneur, now exploring the opportunities with Arduino, Raspberry Pi and 3D printing.

Comments