• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

Circuits for Beginners | Basic Circuits | LED Driver | Hobby Circuits | Transistor Circuits

New-Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright

Home » Arduino Engineering Projects » Interfacing SD Card Module for Data Logging

Interfacing SD Card Module for Data Logging

Last Updated on March 8, 2019 by Swagatam

In this post we are going to interface SD card module with arduino for data logging. We will see overview of SD card module and understand its pin configurations and on board components. Finally we will be constructing a circuit to log the temperature and humidity data to SD card.

 Secure Digital Card

SD card or Secure Digital card is boon for modern electronics as it provides high capacity storage at minimal size. We have used the SD card for media storage in one of the previous project (Mp3 player). Here we are going to use it for data logging.

Data logging is the fundamental step to record the past occurrence of an incident. For example: scientists and researchers able to interpret the rise of global temperature.

They came to this conclusion after understanding the rising temperature pattern by looking the data of past few decades. Recording the data about the current incident might also disclose about the future occurrence.

Since arduino being a great microcontroller for reading sensor data and supports various communication protocols to read the sensors and input output peripherals, the connection between SD card module arduino made piece of cake.

Since arduino don’t have any storage other than its own program storage space, we can add an external storage using the described module in this article.

Now let’s take a look at SD card module.

Image of SD card module:

Image of SD card module:

Flipside of the module and pin configuration:

Flipside of the module and pin configuration:

There are six pins and it supports SPI (serial peripheral interface) communication protocol. For Arduino UNO the SPI communication pins are 13, 12, 11, and 10. For Arduino mega the SPI pins are 50, 51, 52 and 53.

The proposed project is illustrated with Arduino UNO if you have any other model of Arduino please refer internet for the SPI pins.

The module consists of a card holder which holds the SD card in place. 3.3V regulator is provided to limit the voltage to SD cards as it is designed to function at 3.3V and not 5V.

It has LVC125A integrated circuit on board which is logic level shifter. The function of logic level shifter is to reduce 5V signals from arduino to 3.3V logic signals.

Now that concludes the SD card module.

Using SD card module we can store any king of data, here we are going to store text data. We will be storing temperature and humidity data to SD card. We are also utilizing real time clock module to log the time along with sensor data. It records the data every 30 seconds.

Schematic diagram:   

 

Interfacing SD Card Module for Data Logging

The RTC module will keep track of time and log the date and time to the SD card.

The error LED blinks rapidly, if the SD card fails or fails to initialize or SD card not present. Rest of the time the LED stay off.

HOW TO SET TIME TO RTC:

•    Download the library below.
•    With completed hardware setup, connect the arduino to PC.
•    Open arduino IDE
•    Go to File> Examples>DS1307RTC> SetTime.
•    Upload the code and RTC will get synchronised with computer’s time.
•    Now upload the code given below.

Please download following arduino library before uploading the code.

DS1307RTC: github.com/PaulStoffregen/DS1307RTC

DHT11 temp & humidity: arduino-info.wikispaces.com/file/detail/DHT-lib.zip

Program:

//-----Program developed by R.Girish-----//
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <dht.h>
#define DHTxxPIN A0
const int cs = 10;
const int LED = 7;
dht DHT;
int ack;
int f;
File myFile;
void setup()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);
if (!SD.begin(cs))
{
Serial.println("Card failed, or not present");
while(true)
{
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
delay(100);
}
}
Serial.println("Initialization done");
}
void loop()
{
myFile = SD.open("TEST.txt", FILE_WRITE);
if(myFile)
{
Serial.println("----------------------------------------------");
myFile.println("----------------------------------------------");
tmElements_t tm;
if(!RTC.read(tm))
{
goto A;
}
if (RTC.read(tm))
{
Serial.print("TIME:");
if(tm.Hour>12) //24Hrs to 12 Hrs conversion//
{
if(tm.Hour==13)
{
Serial.print("01");
myFile.print("01");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==14)
{
Serial.print("02");
myFile.print("02");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==15)
{
Serial.print("03");
myFile.print("03");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==16)
{
Serial.print("04");
myFile.print("04");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==17)
{
Serial.print("05");
myFile.print("05");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==18)
{
Serial.print("06");
myFile.print("06");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==19)
{
Serial.print("07");
myFile.print("07");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==20)
{
Serial.print("08");
myFile.print("08");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==21)
{
Serial.print("09");
myFile.print("09");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==22)
{
Serial.print("10");
myFile.print("10");
Serial.print(":");
myFile.print(":");
}
if(tm.Hour==23)
{
Serial.print("11");
myFile.print("11");
Serial.print(":");
myFile.print(":");
}
else
{
Serial.print(tm.Hour);
myFile.print(tm.Hour);
Serial.print(":");
myFile.print(":");
}
Serial.print(tm.Minute);
myFile.print(tm.Minute);
Serial.print(":");
myFile.print(":");
Serial.print(tm.Second);
myFile.print(tm.Second);
if(tm.Hour>=12)
{
Serial.print(" PM");
myFile.print( " PM");
}
if(tm.Hour<12)
{
Serial.print("AM");
myFile.print( " AM");
}
Serial.print(" DATE:");
myFile.print(" DATE:");
Serial.print(tm.Day);
myFile.print(tm.Day);
Serial.print("/");
myFile.print("/");
Serial.print(tm.Month);
myFile.print(tm.Month);
Serial.print("/");
myFile.print("/");
Serial.println(tmYearToCalendar(tm.Year));
myFile.println(tmYearToCalendar(tm.Year));
Serial.println("----------------------------------------------");
myFile.println("----------------------------------------------");
} else {
A:
if (RTC.chipPresent())
{
Serial.print("RTC stopped!!!");
myFile.print("RTC stopped!!!");
Serial.println(" Run SetTime code");
myFile.println(" Run SetTime code");
} else {
Serial.print("RTC Read error!");
myFile.print("RTC Read error!");
Serial.println(" Check circuitry!");
myFile.println(" Check circuitry!");
}
}
ack=0;
int chk = DHT.read11(DHTxxPIN);
switch (chk)
{
case DHTLIB_ERROR_CONNECT:
ack=1;
break;
}
if(ack==0)
{
f=DHT.temperature*1.8+32;
Serial.print("Temperature(C) = ");
myFile.print("Temperature(°C) = ");
Serial.println(DHT.temperature);
myFile.println(DHT.temperature);
Serial.print("Temperature(F) = ");
myFile.print("Temperature(°F) = ");
Serial.print(f);
myFile.print(f);
Serial.print("n");
myFile.println(" ");
Serial.print("Humidity(%) = ");
myFile.print("Humidity(%) = ");
Serial.println(DHT.humidity);
myFile.println(DHT.humidity);
Serial.print("n");
myFile.println(" ");
}
if(ack==1)
{
Serial.println("NO DATA");
myFile.println("NO DATA");
}
for(int i=0; i<30; i++)
{
delay(1000);
}
}
myFile.close();
}
}

//-----Program developed by R.Girish-----//

Once the circuit is allowed to log data for some time, you can remove the SD card connect to your computer, there will be TEXT.txt file which all the temperature and humidity data is recorded along with time and date, as shown below.

NOTE: The above idea is an example how to interface and record data. The utilization of this project depend on your imagination, you can record sensor data of any kind.

Author’s prototype: 

Prototype for Interfaced SD Card Module with Arduino

You'll also like:

  • 1.  How to Make a Simple Math Calculator using Arduino
  • 2.  Automatic Street Light Dimmer Circuit
  • 3.  How to Control Servo Motor Using Joystick
  • 4.  Vehicle Speed Detector Circuit for Traffic Police
  • 5.  How to Make LED Air Pollution Meter Circuit with Arduino
  • 6.  Microcontroller Basics Explored

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Subscribe2


 

Primary Sidebar

Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (53)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (98)
  • 741 IC Circuits (19)
  • Amplifiers (58)
  • Arduino Engineering Projects (82)
  • Audio Projects (94)
  • Battery Chargers (82)
  • Car and Motorcycle (94)
  • Datasheets (46)
  • Decorative Lighting (Diwali, Christmas) (33)
  • DIY LED Projects (89)
  • Electronic Components (97)
  • Electronic Devices and Circuit Theory (35)
  • Electronics Tutorial (109)
  • Fish Aquarium (5)
  • Free Energy (35)
  • Fun Projects (11)
  • GSM Projects (9)
  • Health Related (18)
  • Heater Controllers (28)
  • Home Electrical Circuits (101)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (63)
  • Mini Projects (171)
  • Motor Controller (66)
  • MPPT (7)
  • Oscillator Circuits (24)
  • PIR (Passive Infrared) (8)
  • Power Electronics (33)
  • Power Supply Circuits (74)
  • Radio Circuits (9)
  • Remote Control (47)
  • Security and Alarm (61)
  • Sensors and Detectors (116)
  • SG3525 IC (5)
  • Simple Circuits (74)
  • SMPS (29)
  • Solar Controllers (61)
  • Timer and Delay Relay (54)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (40)
  • Ultrasonic Projects (14)
  • Water Level Controller (45)

Circuit Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator

Facebook
Twitter
YouTube
Instagram
My Facebook-Page
Quora

© 2022 · Swagatam Innovations

We use cookies on our website to give you the best experience.
Cookie settingsAccept All
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Please visit the Privacy Policy Page for more info.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT