0
0
Arduinoprogramming~5 mins

SD card module wiring in Arduino

Choose your learning style9 modes available
Introduction

We wire an SD card module to an Arduino to save or read data on a small memory card. This helps the Arduino remember information even when it is turned off.

You want to log sensor data over time and save it for later.
You need to store configuration settings that stay after power off.
You want to read files like text or images from an SD card.
You are making a project that requires lots of data storage beyond Arduino memory.
Syntax
Arduino
SD card module pins to Arduino pins:

SD Module Pin  | Arduino Pin
--------------|------------
VCC           | 5V or 3.3V (check module specs)
GND           | GND
MOSI          | Pin 11 (on Uno)
MISO          | Pin 12 (on Uno)
SCK           | Pin 13 (on Uno)
CS (Chip Select) | Pin 10 (or any digital pin you choose)

Use the SPI pins on your Arduino board (usually pins 11, 12, 13 on Uno).

CS pin can be any digital pin but must match your code.

Examples
This is the common wiring for Arduino Uno and a typical SD card module.
Arduino
VCC -> 5V
GND -> GND
MOSI -> 11
MISO -> 12
SCK -> 13
CS -> 10
Example wiring for Arduino Mega using SPI pins.
Arduino
VCC -> 3.3V
GND -> GND
MOSI -> 51
MISO -> 50
SCK -> 52
CS -> 53
Sample Program

This program checks if the SD card is connected and if a file named 'test.txt' exists on it. It uses the wiring where CS is pin 10.

Arduino
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
  Serial.begin(9600);
  while (!Serial) {}

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("Initialization failed!");
    return;
  }
  Serial.println("Initialization done.");

  if (SD.exists("test.txt")) {
    Serial.println("test.txt exists.");
  } else {
    Serial.println("test.txt doesn't exist.");
  }
}

void loop() {
  // Nothing here
}
OutputSuccess
Important Notes

Make sure your SD card is formatted as FAT16 or FAT32 for compatibility.

Use a logic level converter if your SD module requires 3.3V signals and your Arduino uses 5V.

Double-check wiring before powering to avoid damage.

Summary

SD card modules connect to Arduino using SPI pins: MOSI, MISO, SCK, and a CS pin.

VCC and GND power the module; CS pin can be any digital pin but must match your code.

Correct wiring is essential for the Arduino to read and write data on the SD card.