









The SD card has 9 pins in its standard form factor. Below is the pinout and description:
| Pin Number | Pin Name | Description |
|---|---|---|
| 1 | DAT2 | Data Line 2 (not used in SPI mode) |
| 2 | CD/DAT3 | Card Detect/Data Line 3 |
| 3 | CMD | Command/Response Line |
| 4 | VDD | Power Supply (2.7V to 3.6V) |
| 5 | CLK | Clock Signal |
| 6 | VSS | Ground |
| 7 | DAT0 | Data Line 0 |
| 8 | DAT1 | Data Line 1 |
| 9 | NC | Not Connected |
For microSD cards, the pinout is similar but in a smaller form factor.
Connection:
Wiring Example (SPI Mode):
CLK to SPI Clock (SCK).CMD to SPI MOSI (Master Out Slave In).DAT0 to SPI MISO (Master In Slave Out).VDD to 3.3V power supply.VSS to Ground.Software Setup:
#include <SPI.h>
#include <SD.h>
// Define the chip select pin for the SD card module
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
while (!Serial) {
// Wait for the serial port to connect (for native USB boards)
}
Serial.println("Initializing SD card...");
// Initialize the SD card
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// Stop further execution if the card is not detected
return;
}
Serial.println("Card initialized successfully!");
// Create or open a file on the SD card
File dataFile = SD.open("example.txt", FILE_WRITE);
if (dataFile) {
dataFile.println("Hello, SD card!");
dataFile.close(); // Close the file to save changes
Serial.println("Data written to file.");
} else {
Serial.println("Error opening file.");
}
}
void loop() {
// Nothing to do here
}
SD Card Not Detected:
File Write/Read Errors:
Slow Performance:
Q: Can I use a microSD card in place of a standard SD card?
A: Yes, with an appropriate adapter, microSD cards can be used in standard SD card slots.
Q: What is the maximum capacity supported by an Arduino UNO?
A: The Arduino SD library supports FAT16 and FAT32 file systems, which means it can handle SD cards up to 32 GB.
Q: How do I safely remove the SD card from my circuit?
A: Always power down the system or ensure no ongoing read/write operations before removing the SD card to prevent data corruption.
Q: Can I use the SD card for real-time data logging?
A: Yes, but ensure the SD card has a high write speed and optimize your code to minimize delays.