Temperature / Humidity data-logger

In order to log the temperature and humidity inside payload we have designed a handmade datalogger which will log these magnitudes based on Arduino.

1 / 5
Arduino UNO
Arduino UNO
2 / 5
DATA Logging SD Shield
DATA Logging SD Shield
3 / 5
4 / 5
Electronic diagram
Electronic diagram
5 / 5

There are several ways to save data from a sensor attached to an Arduino. If you are connected to a personal computer, you can simply send the data from the Arduino to the personal computer serially, and save it to a file. If you have got an SD card attached to the microcontroller, you can save the data to the card.

Or, if you have access to the Internet and a device that can connect to a server, you can save the data to a server. In this tutorial we will show you how to integrate an SD Card and a real time clock module into a project to allow data logging.

The sketch below reads a temperature and humidity sensor (DHT22) using the Adafuit DHT library, and if there is an SD card present and initialized, it saves the results to a file called “LOGGERXX.CSV”. Transfer this file to your computer and use it as you wish. You can open it in a spreadsheet and graph it or anything else you wish.

/*This Arduino sketch shows us how to use SD card library to log data, from a temperature and humidity sensor (DHT22), on a SD card. Together with temperature and humidity readings, this code allows us to save date and time readings from a Real Time Clock (RTC) For this we use an Arduino UNO + a shield Data logging with an RTC (Real Time Clock) integrated.
Our Data logging shield lets you store data to a CSV file and save it on an SD card to read them later. It is compatible with Arduino UNO and also includes a prototyping area for mounting sensors, etc. The shield includes a RTC (Real Time Clock) so that in addition to temperature/humidity the file data may include date/time at which the reading is done. The CSV file will have this format: dd/mm/yy hh:mm:ss, temperature, humidity.
The DHT22 is a basic, low-cost digital humidity/temperature. The sensor generates a digital signal (data) to the yellow wire -no input pin Analog is necessary- In our case we used the Arduino digital pin 2. The only drawback of this sensor, according to manufacturer, is that the time between readings must not be inferior to 2 seconds.

The DHT22 sensor is connected to the Arduino as follows:
1) DHT22 red wire connected to Arduino 5V.
2) DHT22 yellow wire connected to Arduino Digital Pin 2.
3) DHT22 black wire connected to Arduino GND.
4) We must also connect a 10K Resistor from yellow wire to red wire.*/

/*-----( Declare objects )-----*/
File logFile;           // Create file to log to
RTC_DS1307 rtc;         // Create a RealTimeClock object
/*-----( Declare Constants and Pin Numbers )-----*/
//#define DHTTYPE DHT11   // modelo DHT 11 
#define DHTTYPE DHT22   // modelo DHT 22 
//#define DHTTYPE DHT21   // modelo DHT 21
#define DHTPIN 2
const int tiempo_entre_lecturas = 5000;
const int chipSelect = 10;
/*-----( Declare Variables )-----*/
long temperature;
void setup()   /****** SETUP: RUNS ONCE ******/
Serial.print("Initializing SD card...");
  if (!SD.begin(chipSelect)) {
   Serial.println("Card failed, or not present"); // don't do anything more:
  Serial.println("card initialized.");
    dht.begin ();
  SD.begin (chipSelect);
  rtc.begin();                    // Start the RTC library code
  pinMode(10, OUTPUT);
/*----( These lines allow code to work also on Arduino DUE )----- */
  #ifdef AVR
    Wire1.begin();    // Shield I2C pins connect to alt I2C bus on Arduino Due
/*----( SET the date and time )----*/
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));       
  // rtc.adjust(DateTime(2015, 8, 10, 18, 0, 0));
  char filename[] = "LOGGER00.CSV";                       
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logFile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
  if (!logFile) {
    Serial.println("could not create file");
  Serial.print("Logging to: ");
  logFile.print ("Formato datos:dd/mm/aa,hh:mm:ss,temperatura,humedad");
//--(end setup )---
void loop ()   /****** LOOP: RUNS CONSTANTLY ******/
  delay (tiempo_entre_lecturas);
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();
  DateTime now = rtc.now();
  logFile.print(now.day(), DEC);
  logFile.print(now.month(), DEC);
  logFile.print(now.year(), DEC);
  logFile.print(' ');
  logFile.print(now.hour(), DEC);
  logFile.print(now.minute(), DEC);
  logFile.print(now.second(), DEC);
  logFile.print (",");
  logFile.print (" ");
  logFile.print (temperature);
  logFile.print (",");
  logFile.print (" ");
  logFile.print (humidity);
  Serial.print(now.day(), DEC);
  Serial.print(now.month(), DEC);
  Serial.print(now.year(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(now.minute(), DEC);
  Serial.print(now.second(), DEC);
  Serial.print (",");
  Serial.print (" ");
  Serial.print (temperature);
  Serial.print (" grados C");
  Serial.print (",");
  Serial.print (" ");
  Serial.print (humidity);
  Serial.print (" %");
//--(end main loop )---
//*********( THE END )***********

Last mission