Arduino Temperature Data-Logger with SD-Card and DS1307 RTC

Connecting the Real Time Clock

img_8222-1

In order to record a timestamp for each data point, a battery-backed real time clock (RTC)  is quite useful. The RTC is an I2C device, which means that it uses 2 wires to communicate. Both wires are used to set the time and retrieve it. On the Arduino UNO, these pins are the Analog 4 and 5 pins.

  • 5V is used to power to the RTC chip when you want to query it for the time. If there is no 5V signal, the chip goes to sleep using the coin cell for backup.
  • Connect GND to common power/data ground
  • Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
  • Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2

These modules are usually equipped with rechargeable 40 mA 3.6 V LIR2032 coin cell batteries.  In case you need longer battery life, they can be exchanged with a non-rechargeable 3 V 200 mA coin cell. However, this requires to unsolder a resistor on the board to disable battery-charging  when the module is connected to 5 V!

Connecting the Temperature Sensor (DS18S20)

The DS18B20 ‘1-wire’ sensors can be connected in parallel – unlike nearly any other sensor sold! All sensors should share the same pins, but you only need one 4.7K resistor for all of them. The 4.7k pullup resistor is placed between the data (yellow wire) and 5 V pin (red wire) of the sensor. The data pin can be wired to any digital Arduino pin, given that you configure it’s pin number in your sketch.

ds18s20

Wiring a status LED (optional)

In order to keep track of data recording, you can wire a standard 20 mA LED with 220 Ω resistor to the data logger, which briefly flashes to indicate that data are stored on the card.

Arduino Sketch

The sketch below will store each data point on a separate line in a CSV file called ‘datalog.txt’.

Tue;01-11-2016 14:52:29;20.87
Tue;01-11-2016 14:53:01;20.87
Tue;01-11-2016 14:53:32;20.94
Tue;01-11-2016 14:54:03;20.94
Tue;01-11-2016 14:54:34;20.94

If you need a different output format than day-of-week;ISO-date;temperature, you have to modify the show_temperature(), show_time_and_date() and saveData() functions.

Click on ‘show‘ to open the sketch.