Interfacing a Micro SD Card Module With Arduino

by Rachana Jain in Circuits > Arduino

38 Views, 0 Favorites, 0 Comments

Interfacing a Micro SD Card Module With Arduino

1.jpg

If you’ve ever built a weather station that logs temperature and humidity every 10 seconds, or a smart irrigation system that records soil moisture throughout the day, you’ve probably noticed one limitation—Arduino’s onboard memory isn’t enough to store all that data.

The simplest way to solve this? A Micro SD card—the same tiny storage device you use in your smartphone, camera, or music player. These cards can hold anything from a few megabytes to several gigabytes, making them perfect for logging large amounts of sensor data. With a Micro SD card module, you can connect the card to your Arduino and instantly give your project powerful data-logging capabilities.

In this guide, we’ll walk through how to interface a Micro SD card module with Arduino.

Supplies

  1. Arduino UNO R3
  2. LCD 16x2
  3. Jumper Wires
  4. USB Cable Type A to B
  5. 12V Supply Adapter
  6. Micro SD card Module
  7. Micro SD card

Micro SD Card Module: Inside the Hardware

Slide3.PNG

A standard Micro SD card module typically consists of three main components:

1. Micro SD Card Socket

This is the slot where you insert your card. Most modules have small printed symbols or arrows that indicate the correct orientation for insertion.

2. 3.3V LDO Voltage Regulator

Since microSD cards operate at 3.3V, applying 5V directly would damage them. The module includes an LDO voltage regulator that safely steps down the Arduino’s 5V supply to 3.3V. This ensures stable voltage delivery even when the input supply fluctuates.

3. Logic Level Shifter

Microcontrollers like Arduino Uno send signals at 5V logic, but microSD cards require 3.3V logic. The module uses a chip such as 74LVC125A to translate the voltage levels, protecting the card from potential damage while ensuring smooth communication.

Micro SD Card Module Pinout

Slide2.PNG

Here’s the standard pin configuration:

  1. GND – Connects to Arduino GND.
  2. VCC – Power input; typically connected to Arduino’s 5V pin.
  3. MISO (Master In Slave Out) – Data output from the card to the Arduino.
  4. MOSI (Master Out Slave In) – Data input from the Arduino to the card.
  5. SCK (Serial Clock) – Carries the clock pulses from Arduino for data timing.
  6. CS (Chip Select) – Selects the SD card on the SPI bus. Pulling this low activates communication with the card.

Interfacing a Micro SD Card Module With Arduino

The SD card module communicates with Arduino via the SPI (Serial Peripheral Interface) protocol, which uses dedicated pins such as MOSI, MISO, SCK, and CS for data exchange. In addition to the data lines, the module requires two power connections—VCC (5V) and GND—to operate. For Arduino Uno, the wiring is as follows: CS connects to pin 10, SCK to pin 13, MOSI to pin 11, MISO to pin 12, VCC to the Arduino’s 5V pin, and GND to the Arduino GND.

Similarly, connecting an I2C LCD to Arduino is straightforward: link the LCD’s VCC and GND pins to the Arduino’s VCC and GND, then connect the SCL (clock) and SDA (data) lines to the Arduino’s SCL and SDA pins. On the Arduino Uno, SCL corresponds to analog pin A5 and SDA corresponds to analog pin A4. It’s also important to ensure that the A0, A1, and A2 address jumpers on the I2C LCD are not shorted; this ensures the display operates at address 0x27, which will be used in the code.

Arduino Code for Checking Micro SD Card Information

In this code the information about SD card is displayed on I2C LCD as well as sent on serial terminal at baud 9600,n,8,1.

/*
Code to get info about SD card and for testing if its working or not
by platwithcircuit.com
*/
#include <SPI.h>
// include SPI library header
#include <SD.h>
// include the SD library header
#include <LiquidCrystal_I2C.h>
// include I2C LCD library header
// set up variables using the SD utility library functions
Sd2Card card;
SdVolume volume;
SdFile root;
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int chipSelect = 10;
void setup() {
// initialize the LCD
lcd.init();
// Turn ON the Backlight
lcd.backlight();
// Clear the display buffer
lcd.clear();
// Print a message to the LCD
lcd.setCursor(0, 0);
lcd.print("Initializing");
lcd.setCursor(0, 1);
lcd.print("SD Card...");
// Open serial communications and wait for port to open
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect
}
Serial.print("\nInitializing SD card...");
delay(1000);
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Initialization");
lcd.setCursor(0, 1);
lcd.print("Failed");
while (1)
;
} else {
Serial.println("Wiring is correct and a card is present.");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Initialization");
lcd.setCursor(0, 1);
lcd.print("Successfull");
delay(2000);
}
// print the type of card
Serial.println();
Serial.print("Card type: ");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Card Type:");
lcd.setCursor(0, 1);
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
lcd.print("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
lcd.print("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
lcd.print("SDHC");
break;
default:
Serial.println("Unknown");
lcd.print("Unknown");
}
delay(2000);
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1)
;
}
Serial.print("Clusters: ");
Serial.println(volume.clusterCount());
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Clusters:");
lcd.setCursor(0, 1);
lcd.print(volume.clusterCount());
delay(2000);
Serial.print("Blocks per Cluster: ");
Serial.println(volume.blocksPerCluster());
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Block per Clster");
lcd.setCursor(0, 1);
lcd.print(volume.blocksPerCluster());
delay(2000);
Serial.print("Total Blocks: ");
Serial.println(volume.blocksPerCluster() * volume.clusterCount());
Serial.println();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Total Blocks:");
lcd.setCursor(0, 1);
lcd.print(volume.blocksPerCluster() * volume.clusterCount());
delay(2000);
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("Volume type is: FAT");
Serial.println(volume.fatType(), DEC);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume type is:");
lcd.setCursor(0, 1);
lcd.print("FAT");
lcd.print(volume.fatType(), DEC);
delay(2000);
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
Serial.print("Volume size (KB): ");
Serial.println(volumesize);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume size (KB):");
lcd.setCursor(0, 1);
lcd.print(volumesize);
delay(2000);
Serial.print("Volume size (MB): ");
volumesize /= 1024;
Serial.println(volumesize);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume size (MB):");
lcd.setCursor(0, 1);
lcd.print(volumesize);
delay(2000);
Serial.print("Volume size (GB): ");
Serial.println((float)volumesize / 1024.0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Volume size (GB):");
lcd.setCursor(0, 1);
lcd.print((float)volumesize / 1024.0);
delay(2000);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}


To learn more checkout: Interfacing Micro SD Card Module with Arduino