Arduino SD card data logger to Excel


This tutorial shows how to make data logger by Arduino & SD card module
It will read data from real time module DS3231 (real time, temperature), then save data into text file which is latter imported into Excel file
Important thing of data logger is to know real time of recorded data, so real time DS3231 is used to read real time (link here to know how to use DS3231)
In this example, Arduino will read temperature (also from DS3231) and record in text file. Microsoft Excel will help us to import data from text file, from here we can draw a graph.

Hardware need to purchase
1. Arduino Pro Mini
2. Real time moduel DS3231
3. SD card module SPI
4. Micro SD card 8GB (with adapter)
1. Arduino Pro Mini
2. Real time module DS3231
3. SD card module SPI
4. Micro SD card 8GB




Step 1. Arduino SD card schematic




Step 2. Arduino SD card data logger code
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "DS3231.h"

RTClib RTC;
DS3231 Clock;

int Year;
int Month;
int Date;
int Hour;
int Minute;
int Second;
int tempC;
int interval;
int Minute_last;

File myFile;

void setup() {
  Serial.begin(9600);
  Wire.begin(); //for DS3231
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  delay(2000);  //afer reset Arduino, 2s to take out SD

  Serial.print("Initializing SD card...");
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
  }
  else
  {
    Serial.println("initialization done.");
  }
}

void loop() {
  interval = 1; //interval to write data
  DateTime now = RTC.now();
  Year = now.year();
  Month = now.month();
  Date = now.day();
  Hour = now.hour();
  Minute = now.minute();
  Second = now.second();
  tempC = Clock.getTemperature();
  
  if ((Minute % interval == 0)&(Minute_last!=Minute))
  {
    write_data(tempC);  //write data
    Minute_last = Minute;
  }
}

void write_data(int temperature_input)
{
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    myFile.print(Year);
    myFile.print("/");
    myFile.print(Month);
    myFile.print("/");
    myFile.print(Date);
    myFile.print(" ");
    myFile.print(Hour);
    myFile.print(":");
    myFile.print(Minute);
    myFile.print("_temperature_");
    myFile.println(temperature_input);
    myFile.close();
    Serial.println("Write file successful!"); //print out COM Port
  } else {
    Serial.println("error opening test.txt");
  }
}
What the code do is: Initialize the card, if any failure from here, it will show "initialization failed!". I got experience with it when the card 16GB can't be recognized by Arduino, but it works when replace new card 8GB.

Then the code read temperature from DS3231 and write data to file test.txt. It will inform out to COM screen the result of data writing activity.
In this code, Arduino will write data every 1 minutes (it is controlled by variable "interval", if change it into 5, then it will record data every 5 minutes)

The text file test.txt then will import to Excel by import data function

8 comments:

  1. At that point we embed a last circle completing a similar assignment toward the end. This circle is there just to watch that all rooms are truly associated.ExcelR Data Science Courses

    ReplyDelete
  2. The camera memory card is where you store the images (and videos) until you can transfer them to your computer. There are different types of digital camera memory cards such as the CompactFlash (CF), Memory Stick (MS), MultiMediaCard (MMC), Secure Digital (SD), SmartMedia (SM) and xD-Picture Card (xD). The newest type of card is the Secure Digital High Capacity (SDHC) card. bulk SD cards

    ReplyDelete
  3. Nice knowledge gaining article. This post is really the best on this valuable topic. instagram liker and followers app

    ReplyDelete
  4. Excellent post. I learned a lot from this blog and I suggest my friends to visit your blog to learn new concept about technology.Best data science courses in hyerabad

    ReplyDelete
  5. ExcelR provides Data Science course. It is a great platform for those who want to learn and become a Data Science Courses. Students are tutored by professionals who have a degree in a particular topic. It is a great opportunity to learn and grow.

    Data Science courses
    data science course in pune
    data scientist course in pune with placement
    data scientist course in pune

    ReplyDelete
  6. Joining the AI Patasala Best Python Training in Hyderabad program would be a great choice for Python career-minded people.
    Python Institutes in Hyderabad

    ReplyDelete