Skip to content Skip to sidebar Skip to footer

Arduino Data Logger to SD Card Tutorial DS3231 Data Logger

Arduino Data Logger

This article provides how to make an Arduino Data Logger to SD Card DS3231 Data Logger Tutorial, along with the program code and circuit. Please come in. - Thank you for coming to the website At this time we will learn how to make a data logger with the addition of the RTC and Micro SD Reader modules.


A. What is a Data Logger?

Data Logger is a tool that can record certain values ​​into storage media. In this article, we will learn how to save sensor data to micro SD within 1 second along with the date and time. For that, we must provide the materials needed in making this data logger.


B. Components for Build a Data Logger

To be able to make a Data Logger, several materials are needed so that the data logger is what you want. The materials used are:

  • Arduino Uno (can also use Nano, Promini and others)
  • Micro SD memory (in this tutorial I use 8GB)
  • DS3231 RTC Module (supports DS1307)
  • Micro SD reader module (in this tutorial I use Catalex)
  • Sensor (whatever type, the output is an analog voltage).
  • Breadboard or Project Board
  • Sufficient cable


In this tutorial we need two libraries, the RTC DS3231 and Micro SD. Well, you can download the library at:

RTC Module Library


Micro SD Arduino Libary (include in Arduino IDE)

C. Arduino Data Logger Wiring

To be able to communicate with Aruduino, the MicroSD adapter module that we will use here, uses the SPI (Serial Peripheral Interface) protocol. The SPI protocol requires 4 pins, namely SCK, MOSI, MISO and CS (Chip Select).

While the DS3231 RTC module that we use here uses the I2C (Inter-Integrated Circuit) protocol which only requires 2 pins, namely SDA and SCL.


 Arduino Uno  MicroSD Module
 5V  VCC
 13  SCK
 12  MISO
 11  MOSI
 10  CS
 Arduino Uno  DS3231
 5V  VCC
 A4  SDA
 A5  SCL

D. Data Logger Arduino Program

After the wiring has been connected as in the image above, there are two points that we must do:

1. Create a file to save data

Before we go into the main program, we must first create a file and save the file on the micro SD. This file is useful for storing sensor data.


  • For file names up to 8 characters and using file extension ".txt". For example "Data_Log.txt"
  • The file name is not Case Sensitive or does not recognize capital or lowercase letters. For example in microSD the file name is "DATA_LOG.TXT" while the file name in the program "data_log.txt", it can running well.


2. Program Code

In this program, the sensor will be read using the analog pin Read 0 (A0), then connect the sensor to A0.

For the file name, I gave the name "data_log.txt" which is on the micro SD. The programs are as follows:

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

File myFile;
RTC_DS3231 rtc;

int chipselect  = 10;
int sensorPin   = A0;
int sensorData  = 0;
String fileName = "data_log.txt";
String timeData;
String dateData;

void setup() {

  if (!SD.begin(chipselect)) {
    Serial.println("Micro SD reading failed!");
    Serial.println("* Is the connection correct?");
    Serial.println("* Or the memory card is not inserted?");
    while (1) {
  } else {
    Serial.println("The MicroSD card has been read.");

  if (! rtc.begin()) {
    Serial.print("RTC not detected! ");
    Serial.println("is the circuit correct?");
  } else {
    Serial.println("The RTC has been read.");


void loop() {
  DateTime now =;

  dateData = now.timestamp(DateTime::TIMESTAMP_DATE);
  timeData     = now.timestamp(DateTime::TIMESTAMP_TIME);

  sensorData = analogRead(sensorPin);

  if (SD.exists(fileName)) {
    Serial.println("Writing data...");
    myFile =, FILE_WRITE);
    myFile.print(dateData + " " + timeData);
    myFile.print(" ");
  else {
    Serial.println("File " + fileName + " not in memory yet.");



After the program above has been uploaded to Arduino, wait a moment for the data to be saved. 

To find out that the logger has successfully stored data, please remove the Micro SD from the Micro SD Module, then insert SD Card into your computer / laptop.

If there is data generated, it means you have successfully created a data logger. If not, then something might be wrong in the circuit, program code and so on.

As in the following picture is a .txt file that contains the saved data from the above program.


You can use this program and series to your project. If this article is useful, then share it with other  who might need it.

That's all. I hope this article is useful.


Similar searches: 


Post a Comment for "Arduino Data Logger to SD Card Tutorial DS3231 Data Logger"