A simple, clear guide to logging and reading data using an SD card with Arduino
Working with external storage opens up a whole new level of possibilities for Arduino projects—data logging, configuration storage, and even simple file systems. In this guide, you’ll learn how to interface a micro SD card module with an Arduino in a practical, beginner-friendly way.
Why Use a Micro SD Card with Arduino?
Arduino boards have very limited onboard memory. If your project involves storing sensor readings, logs, or large datasets, a micro SD card is a perfect solution. It allows you to:
- Store large amounts of data
- Read and write files easily
- Transfer data to a computer for analysis
- Build real-world applications like data loggers
Components Required
To get started, you’ll need:
- Arduino board (Uno, Nano, or similar)
- Micro SD card module
- Micro SD card (formatted as FAT32)
- Jumper wires
- Breadboard (optional)
How the SD Card Module Works
The micro SD card module communicates with the Arduino using the SPI (Serial Peripheral Interface) protocol. This allows high-speed data transfer using a few dedicated pins.
The key SPI pins are:
- MOSI (Master Out Slave In)
- MISO (Master In Slave Out)
- SCK (Clock)
- CS (Chip Select)
Each Arduino board has fixed SPI pins, so wiring must match accordingly.
Wiring the Module to Arduino
Here’s how to connect the SD card module to an Arduino Uno:
- VCC → 5V
- GND → GND
- CS → Pin 4
- MOSI → Pin 11
- MISO → Pin 12
- SCK → Pin 13
Make sure your connections are secure, as loose wiring can cause initialization failures.
Preparing the SD Card
Before using the SD card:
- Format it as FAT32 using your computer
- Avoid using very large cards if you're a beginner (2GB–16GB works best)
- Ensure the card is properly inserted into the module
Arduino Code Explanation
To work with the SD card, Arduino provides a built-in SD library. This simplifies file operations like reading and writing.
Here’s a clean example that initializes the SD card and writes data to a file:
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
File myFile = SD.open("data.txt", FILE_WRITE);
if (myFile) {
myFile.println("Hello, this is a test log.");
myFile.close();
Serial.println("Data written to file.");
} else {
Serial.println("Error opening file.");
}
}
void loop() {
}
Reading Data from the SD Card
You can also read stored data easily:
File myFile = SD.open("data.txt");
if (myFile) {
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
} else {
Serial.println("Error opening file.");
}
This is useful for debugging or displaying stored logs.
Common Issues and Fixes
If your SD card doesn’t work as expected, here are a few things to check:
- Double-check wiring connections
- Ensure correct chip select (CS) pin in code
- Confirm SD card is FAT32 formatted
- Use a reliable SD card (cheap cards often fail)
- Make sure the module supports 5V or use a level shifter
Practical Applications
Once everything is working, you can extend this setup into real projects:
- Temperature or humidity data logger
- GPS tracking system
- Event logging for IoT devices
- Offline storage for sensor data
Final Thoughts
Interfacing an Arduino micro SD card module is one of the most useful skills for building real-world embedded systems. With just a few components and simple code, you can dramatically expand your project’s capabilities.
Start small, experiment with writing and reading files, and gradually build more complex systems. Once you get comfortable, you’ll find yourself using SD cards in many of your projects. Explore 500+ hands-on tutorials and ideas at Arduino projects with code and circuit diagrams
to kickstart your next electronics build.
If you found this helpful, consider sharing your own projects or improvements—you might inspire someone else to build something amazing.




Top comments (0)