SD Card Module With Arduino: How to Read/Write Data

by Electropeak in Circuits > Electronics

21588 Views, 10 Favorites, 0 Comments

SD Card Module With Arduino: How to Read/Write Data

micro-sd-module-arduino-teaser.jpg

Overview

Storing data is one of the most important parts of every project. There are several ways to store data according to the data type and size. SD and micro SD cards are one of the most practical ones among the storage devices, which are used in devices such as mobile phones, minicomputers and etc.
In this tutorial, you’ll learn how to use SD and micro SD cards with Arduino. In the end, as a simple project, you will measure the environment temperature every hour and store it on the SD card.

What You Will Learn

How to use SD and micro SD card

Writing data on SD card

Reading data from SD card

What Is SD and Micro SD Card Module?

uSD-Arduino-SD.jpg

The SD and micro SD card modules allow you to communicate with the memory card and write or read the information on them. The module interfaces in the SPI protocol.

To use these modules with Arduino you need the SD library. This library is installed on the Arduino application by default.

Note

These modules can not handle high-capacity memory cards. Usually, the maximum identifiable capacity of these modules is 2 GB for SD cards, and 16 GB for micro SD cards.

Required Components

uSD-Arduino-required-materials.jpg

Important SD Module Library Commands

Untitled.png

A brief explanation of practical SD library’s commands is provided in the attached table.

*file is an instance from File class.
You can find more information about the SD library Here.

How to Use SD and Micro SD Card With Arduino?

Tip

The module used in this tutorial is the micro SD module, however, you can use the code and tutorial for SD modules as well.

Circuit

ds3231-sd-module-pinout.jpg
ds3231-sd-card-module-circuit.jpg

Using this module is very simple and its configuration is as picture.

Code

Writing data on SD card with Arduino

Result

write-1500x549.png

The result of the above code execution

Reading Data

Reading data from SD card with Arduino

Result

read.png

The result of the above code execution

Project: Save Temperature Data on a MicroSD Using DS3231 Module

You can find DS3231 here. In addition to the IC clock and calendar, this module also has a temperature sensor.

Circuit

SD_ds3231.png

Code

ds3231-lib.png

To work with the DS3231 module, you must first add the library (Sodaq_DS3231.h) to the Arduino application.

After storing the temperature at different times of the day, you can draw this information into Excel using the chart.

Downloads

Draw a Chart in Excel:

excel_from-text-1500x798.png
excel_tempPNG.png
excel_1.png
excel_2.png
excel_chart1-1500x772.png
excel_chart2-1500x798.png

To do this, follow these steps:

Connect the SD card to your PC.

Enter the Excel software and select the From Text option from the data window and select the file from your memory card.

What’s Next?

  • Create an entry/exit control device. Using the RFID module and Arduino, save entrance and exit time for several persons on the memory card. (Consider an RFID card for each person)
  • Like our FaceBook page to notice the latest projects and also support our team.