Arduino temperature logger project

One of the most popular projects made with Arduino is a data logger. You can find a lot of these on the internet, but most of them are huge, sophisticated projects with a whole bunch of sensors and unnecessary additions.

I like when things and simple and clean making it easy for you to learn and replicate. If you understand the simple it is easy to combine many simple to now build something advanced.

In this Arduino project, we will show you how to use an SD card and a DHT11 temperature and humidity sensor to read the ambien temperature and humidity, save their values and play with them using Microsrof Excel. So, let’s start by downloading the necessary libraries. If you do not know how to do this, you might need to check this.

We need the following libraries:

  • Simple DHT11 library
  • SD card library

The SD card library is installed in every Arduino IDE by default.

Humidity and temperature logger

Here are the hardware parts we need:

Here is schematic.

When everything is connected, you can plug your SD card into the SD card reader and upload the following program to the Arduino.

It just reads the ambient temperature and humidity from DHT11 and saves it on the SD card into a text file named temp.txt.

//including libraries
#include <SimpleDHT.h>
#include <SPI.h>
#include <SD.h>

//we will need myfile value to save values to the file on SD card
File myfile;
//thats the number of pin where DHT11 is connected
int pinDHT11 = 2;
SimpleDHT11 dht11;

void setup() {
  Serial.begin(9600);
//initialization of SD card
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }  
}

void loop() {
  //openning file on sd card
  myfile = SD.open("temp.txt", FILE_WRITE);
  byte temperature = 0;
  byte humidity = 0;
  if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) {
    Serial.print("Read DHT11 failed.");
    return;
  }
  //saving to file if it is opened correctly
  if(myfile){
  myfile.print((int)temperature);
  myfile.print(";");
  myfile.println((int)humidity);
  myfile.close();
  //we will save the value every second you can change the delay
  delay(1000);
  }
}

After uploading the code you can hold the temperature sensor in your hand to increase the temperature reads. After few seconds or more, you can take off the SD card and see the data on your computer. It should look something like this:

21;60
21;59
21;62
21;64
21;70
23;87
23;87
23;89
23;89
24;90
24;90
24;91
24;91
24;91
24;91
24;91
24;91
24;91
24;91
24;92
24;92
25;91
25;91
25;91
25;91
25;91
24;92
24;91
23;89
23;87
23;84
23;87
23;87
23;87
and so on.

To see this it more clearly, we can import it into Excel. That’s why we included the sign “;” in between the temperature and humidity, to let Excel split them with no additional hassle.

Click on the import icon and select the text file. As separator select “;” and that’s all. Your data will be imported into Excel.

I had fun creating a graph using the data fetched and it looks just cool.

Hope I helped you have an idea for your next Arduino project. Enjoy!

tchouken2

Related Posts