Project tutorial
Temperature and Humidity Data logger - Breadboard

Temperature and Humidity Data logger - Breadboard

A simple Arduino-based temperature data logger

  • 9,041 views
  • 2 comments
  • 10 respects

Components and supplies

10167 01
DHT22 Temperature Sensor
×1
3.3Kohm Resistors
×3
1.8Kohm Resistor
×3
Header Pins
×3
3 Core Cable
×1
SD Memory Card
×1
Power Supply
×1
Jiffy Box
×2
Real Time Clock Module
×1
SD Memory Card
×1
09590 01
LED (generic)
×6
11026 02
Jumper wires (generic)
×60
12002 04
Breadboard (generic)
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1

About this project

Prototype

Software update V1.2

thermometer_sketch.c
Software update V1.2

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

/*
  Temprature and Humidity Data Logger V1.2

 Writes temprature, humidity, time and date to SD Memory card. Only updates when 'now.minute()' is 
 00 or 30 to provide more accurate results

 The circuit:
 * LEDs on pins 2 through to 6 to ground
 * Real Time Clock on SDA and SCL
 * SD memory Card on pins 50 - 53 on mega 
 * DHT 22 on pin 22, PWR and GND

 created 9 June 2013
 by Jed Hodson

 */

//Include 
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
//Setup CS on SD Card (53 for mega, 10 for UNO)
const int chipSelect = 53;
//Setup RTC
RTC_DS1307 RTC;
//Setup DHT
#define DHTPIN 22     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

//Setup LED pins
int sdError = 2;
int dhtError = 3;
int writingLED = 4;
int rtcError = 5;
int sdStatus = 6;

void setup()
{
  //Setup LEDs
  pinMode(sdError,OUTPUT);
  pinMode(dhtError,OUTPUT);
  pinMode(writingLED,OUTPUT);
  pinMode(rtcError, OUTPUT);
  pinMode(sdStatus, OUTPUT);
  digitalWrite(sdError, LOW);
  digitalWrite(dhtError, LOW);
  digitalWrite(writingLED, LOW);
  digitalWrite(rtcError, LOW);
  digitalWrite(sdStatus, OUTPUT);

  //Initializing SD
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);

  pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    digitalWrite(sdError, HIGH);
    // don't do anything more:
    return;
  }
  digitalWrite(sdStatus, HIGH);
  //Setup DS1307
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    digitalWrite(rtcError, HIGH);
    delay(950);
    digitalWrite(rtcError, LOW);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //Setup DHT
  dht.begin();
}

void loop()
{
  DateTime now = RTC.now();
  if(now.minute() == 00 || now .minute() == 30)
  {
    String dataString = "";
    DateTime now = RTC.now();
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) {
      digitalWrite(dhtError, HIGH);
      delay(950);
      digitalWrite(dhtError, LOW);
    }
    //Create String to print to SD Card
    int humid = h;
    dataString += "Humidity";
    dataString += ", ";
    dataString += String(humid);
    dataString += "%";
    int temp = t;
    dataString += ", Temprature";
    dataString += String(temp);
    dataString += "*C";
    dataString += " at";
    dataString += " ";
    dataString += String(now.year());
    dataString += "/";
    dataString += String(now.month());
    dataString += "/";
    dataString += String(now.day());
    dataString += ", ";
    dataString += String(now.hour());
    dataString += ":";
    dataString += String(now.minute());
    dataString += ":";
    dataString += String(now.second());
    // 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(dataString);
      dataFile.close();
      // flash writing led too
      digitalWrite(writingLED, HIGH);
      delay(950);
      digitalWrite(writingLED, LOW);
    }  
    // if the file isn't open, pop up an error:
    else {
      digitalWrite(sdError, HIGH);
      delay(950);
      digitalWrite(sdError, LOW);
    }
    //delay for 59 seconds to prevent updates happening in minute
    delay(59000);
  }
}
Warning: embedding parts within the project story has been deprecated. To edit, remove or add more parts, go to the "Hardware" tab. To remove this list from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Hardware" tab).
10167 01
DHT22 Temperature Sensor
11026 02
Jumper wires (generic)
12002 04
Breadboard (generic)
09590 01
LED (generic)
3.3Kohm Resistors
1.8Kohm Resistor
Header Pins
3 Core Cable
SD Memory Card
Power Supply
Jiffy Box
Real Time Clock Module
Arduino Compatiable Board
SD Memory Card

Quick description

Today I've being working from dawn to well midday on a temperature data logger with RTC. It consists of 5 LEDs to tell the status of the data logger a Real Time Clock, SD Card, ardunio MEGA (although can be used with UNO or eleven), a resistor voltage divider, 9V plug pack, DHT 22 sensor with box and a bunch of jumpers on a breadboard.

End result

Software V1_3 - Uno Compatable

software_v1_3___uno_compatable.c
Software V1_3 - Uno Compatable

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

/*
  Temprature and Humidity Data Logger V1.3

 Writes temprature, humidity, time and date to SD Memory card. Only updates when 'now.minute()' is 
 00 or 30 to provide more accurate results

 Uno - Compatiable 

 The circuit:
 * LEDs on pins 2 through to 6 to ground
 * Real Time Clock on SDA and SCL
 * SD memory Card on pins 10 - 13 on mega 
 * DHT 22 on pin 2, PWR and GND

 --20,632 Bytes--

 created 13 July 2013
 by Jed Hodson

 */

//Include 
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
//Setup CS on SD Card (53 for mega, 10 for UNO)
const int chipSelect = 10;
//Setup RTC
RTC_DS1307 RTC;
//Setup DHT
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

//Setup LED pins
int sdError = 3;
int dhtError = 4;
int writingLED = 5;
int rtcError = 6;
int sdStatus = 7;

void setup()
{
  //Setup LEDs
  pinMode(sdError,OUTPUT);
  pinMode(dhtError,OUTPUT);
  pinMode(writingLED,OUTPUT);
  pinMode(rtcError, OUTPUT);
  pinMode(sdStatus, OUTPUT);
  digitalWrite(sdError, LOW);
  digitalWrite(dhtError, LOW);
  digitalWrite(writingLED, LOW);
  digitalWrite(rtcError, LOW);
  digitalWrite(sdStatus, OUTPUT);

  //Initializing SD
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);

  pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    digitalWrite(sdError, HIGH);
    // don't do anything more:
    return;
  }
  digitalWrite(sdStatus, HIGH);
  //Setup DS1307
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    digitalWrite(rtcError, HIGH);
    delay(950);
    digitalWrite(rtcError, LOW);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //Setup DHT
  dht.begin();
}

void loop()
{
  DateTime now = RTC.now();
  if(now.minute() == 00 || now .minute() == 30)
  {
    String dataString = "";
    DateTime now = RTC.now();
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) {
      digitalWrite(dhtError, HIGH);
      delay(950);
      digitalWrite(dhtError, LOW);
    }
    //Create String to print to SD Card
    int humid = h;
    dataString += "Humidity";
    dataString += ", ";
    dataString += String(humid);
    dataString += "%";
    int temp = t;
    dataString += ", Temprature";
    dataString += String(temp);
    dataString += "*C";
    dataString += " at";
    dataString += " ";
    dataString += String(now.year());
    dataString += "/";
    dataString += String(now.month());
    dataString += "/";
    dataString += String(now.day());
    dataString += ", ";
    dataString += String(now.hour());
    dataString += ":";
    dataString += String(now.minute());
    dataString += ":";
    dataString += String(now.second());
    // 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(dataString);
      dataFile.close();
      // flash writing led too
      digitalWrite(writingLED, HIGH);
      delay(950);
      digitalWrite(writingLED, LOW);
    }  
    // if the file isn't open, pop up an error:
    else {
      digitalWrite(sdError, HIGH);
      delay(950);
      digitalWrite(sdError, LOW);
    }
    //delay for 59 seconds to prevent updates happening in minute
    delay(59000);
  }
}

Code

thermometer_sketch.cC/C++
thermometer_sketch.c
/*
  Temprature and Humidity Data Logger V1.2

 Writes temprature, humidity, time and date to SD Memory card. Only updates when 'now.minute()' is 
 00 or 30 to provide more accurate results

 The circuit:
 * LEDs on pins 2 through to 6 to ground
 * Real Time Clock on SDA and SCL
 * SD memory Card on pins 50 - 53 on mega 
 * DHT 22 on pin 22, PWR and GND

 created 9 June 2013
 by Jed Hodson

 */

//Include 
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
//Setup CS on SD Card (53 for mega, 10 for UNO)
const int chipSelect = 53;
//Setup RTC
RTC_DS1307 RTC;
//Setup DHT
#define DHTPIN 22     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

//Setup LED pins
int sdError = 2;
int dhtError = 3;
int writingLED = 4;
int rtcError = 5;
int sdStatus = 6;

void setup()
{
  //Setup LEDs
  pinMode(sdError,OUTPUT);
  pinMode(dhtError,OUTPUT);
  pinMode(writingLED,OUTPUT);
  pinMode(rtcError, OUTPUT);
  pinMode(sdStatus, OUTPUT);
  digitalWrite(sdError, LOW);
  digitalWrite(dhtError, LOW);
  digitalWrite(writingLED, LOW);
  digitalWrite(rtcError, LOW);
  digitalWrite(sdStatus, OUTPUT);

  //Initializing SD
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);

  pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    digitalWrite(sdError, HIGH);
    // don't do anything more:
    return;
  }
  digitalWrite(sdStatus, HIGH);
  //Setup DS1307
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    digitalWrite(rtcError, HIGH);
    delay(950);
    digitalWrite(rtcError, LOW);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //Setup DHT
  dht.begin();
}

void loop()
{
  DateTime now = RTC.now();
  if(now.minute() == 00 || now .minute() == 30)
  {
    String dataString = "";
    DateTime now = RTC.now();
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) {
      digitalWrite(dhtError, HIGH);
      delay(950);
      digitalWrite(dhtError, LOW);
    }
    //Create String to print to SD Card
    int humid = h;
    dataString += "Humidity";
    dataString += ", ";
    dataString += String(humid);
    dataString += "%";
    int temp = t;
    dataString += ", Temprature";
    dataString += String(temp);
    dataString += "*C";
    dataString += " at";
    dataString += " ";
    dataString += String(now.year());
    dataString += "/";
    dataString += String(now.month());
    dataString += "/";
    dataString += String(now.day());
    dataString += ", ";
    dataString += String(now.hour());
    dataString += ":";
    dataString += String(now.minute());
    dataString += ":";
    dataString += String(now.second());
    // 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(dataString);
      dataFile.close();
      // flash writing led too
      digitalWrite(writingLED, HIGH);
      delay(950);
      digitalWrite(writingLED, LOW);
    }  
    // if the file isn't open, pop up an error:
    else {
      digitalWrite(sdError, HIGH);
      delay(950);
      digitalWrite(sdError, LOW);
    }
    //delay for 59 seconds to prevent updates happening in minute
    delay(59000);
  }
}
software_v1_3___uno_compatable.cC/C++
software_v1_3___uno_compatable.c
/*
  Temprature and Humidity Data Logger V1.3

 Writes temprature, humidity, time and date to SD Memory card. Only updates when 'now.minute()' is 
 00 or 30 to provide more accurate results

 Uno - Compatiable 

 The circuit:
 * LEDs on pins 2 through to 6 to ground
 * Real Time Clock on SDA and SCL
 * SD memory Card on pins 10 - 13 on mega 
 * DHT 22 on pin 2, PWR and GND

 --20,632 Bytes--

 created 13 July 2013
 by Jed Hodson

 */

//Include 
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
//Setup CS on SD Card (53 for mega, 10 for UNO)
const int chipSelect = 10;
//Setup RTC
RTC_DS1307 RTC;
//Setup DHT
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

//Setup LED pins
int sdError = 3;
int dhtError = 4;
int writingLED = 5;
int rtcError = 6;
int sdStatus = 7;

void setup()
{
  //Setup LEDs
  pinMode(sdError,OUTPUT);
  pinMode(dhtError,OUTPUT);
  pinMode(writingLED,OUTPUT);
  pinMode(rtcError, OUTPUT);
  pinMode(sdStatus, OUTPUT);
  digitalWrite(sdError, LOW);
  digitalWrite(dhtError, LOW);
  digitalWrite(writingLED, LOW);
  digitalWrite(rtcError, LOW);
  digitalWrite(sdStatus, OUTPUT);

  //Initializing SD
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);
  delay(950);
  digitalWrite(sdStatus, HIGH);
  delay(950);
  digitalWrite(sdStatus, LOW);

  pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    digitalWrite(sdError, HIGH);
    // don't do anything more:
    return;
  }
  digitalWrite(sdStatus, HIGH);
  //Setup DS1307
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    digitalWrite(rtcError, HIGH);
    delay(950);
    digitalWrite(rtcError, LOW);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //Setup DHT
  dht.begin();
}

void loop()
{
  DateTime now = RTC.now();
  if(now.minute() == 00 || now .minute() == 30)
  {
    String dataString = "";
    DateTime now = RTC.now();
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) {
      digitalWrite(dhtError, HIGH);
      delay(950);
      digitalWrite(dhtError, LOW);
    }
    //Create String to print to SD Card
    int humid = h;
    dataString += "Humidity";
    dataString += ", ";
    dataString += String(humid);
    dataString += "%";
    int temp = t;
    dataString += ", Temprature";
    dataString += String(temp);
    dataString += "*C";
    dataString += " at";
    dataString += " ";
    dataString += String(now.year());
    dataString += "/";
    dataString += String(now.month());
    dataString += "/";
    dataString += String(now.day());
    dataString += ", ";
    dataString += String(now.hour());
    dataString += ":";
    dataString += String(now.minute());
    dataString += ":";
    dataString += String(now.second());
    // 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(dataString);
      dataFile.close();
      // flash writing led too
      digitalWrite(writingLED, HIGH);
      delay(950);
      digitalWrite(writingLED, LOW);
    }  
    // if the file isn't open, pop up an error:
    else {
      digitalWrite(sdError, HIGH);
      delay(950);
      digitalWrite(sdError, LOW);
    }
    //delay for 59 seconds to prevent updates happening in minute
    delay(59000);
  }
}

Comments

Similar projects you might like

Temperature and Humidity Data Logger

Project tutorial by Wimpie van den Berg

  • 30,532 views
  • 2 comments
  • 28 respects

Date, Time, Temperature and Humidity Display

Project tutorial by Chamath Vithanawasam

  • 22,692 views
  • 10 comments
  • 47 respects

SD Card Temperature Data Logger

Project tutorial by 3 developers

  • 10,498 views
  • 0 comments
  • 10 respects

Temperature and Humidity Logger Per Hour

Project tutorial by lefteris1993

  • 2,633 views
  • 0 comments
  • 13 respects

Health Kit: Humidity and Temperature Control

Project tutorial by Diana Khalipina

  • 7,998 views
  • 2 comments
  • 48 respects
Add projectSign up / Login