Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

MicroSD card module with Arduino Uno — SPI wiring and data logging

Wire a microSD card module to an Arduino Uno R3 on SPI (CS D10), format the card right and append CSV readings to LOG.TXT every 2 seconds.

Arduino C++Verified — core avr 1.8.8, SD 1.3.0, 3 Nov 2026Compile-only

Community draft — report a mistake

A microSD module turns the Uno into a data logger. Temperature every minute, the hours a pump ran, or a GPS track — all go to a CSV file you can open in Excel on a PC.

The usual module from Indian sellers has a 3.3 V regulator and a level-shifter chip, so it wires straight to the Uno’s 5V and its hardware SPI pins (D11, D12, D13), with CS on D10. The real constraint is RAM: the SD library needs a 512-byte buffer, which is a quarter of the Uno’s 2 KB. Plan the rest of the project with that in mind.

The sketch appends a line with the uptime and the A0 reading to LOG.TXT every 2 seconds. It closes the file after each write so nothing is lost if the power goes.

Wiring

Arduino Uno R3Only the pins used are shown · 5 V logicMicroSD card module (SPI)5VGNDD10D11D12D13GNDVCCMISOMOSISCKCS
Every connection
Arduino Uno R3MicroSD card module (SPI)WireNotes
GNDGNDblack
5VVCCredThe common module has a 3.3 V regulator and a 74LVC125 level shifter, so 5 V in and 5 V signals are right. Cards draw up to about 100 mA while writing.
D12MISOpurple
D11MOSIgreen
D13SCKblue
D10CSyellowAny pin can be CS, but D10 must stay an output for SPI anyway.

4.5–5.5 V on the common module with regulator (3.3 V-only boards also sold) part, 5 V board. The common blue module has an AMS1117 3.3 V regulator and a 74LVC125 level shifter, so it needs 5 V on VCC — 3.3 V leaves the card under-powered. Its signal pins accept 3.3 V or 5 V logic, so ESP32, Pico and Uno all connect directly.

Board quirks

  • This wiring is for the common blue module with a regulator and level-shifter chip. Bare 3.3 V-only adapters (just a socket and resistors) must be powered from 3.3V and need a level shifter on MOSI, SCK and CS.
  • The SD library keeps a 512-byte sector buffer in RAM — a quarter of the Uno’s 2 KB. Combined with an OLED’s 1 KB buffer, you will run out; use a character LCD instead.
  • Format the card as FAT32 (FAT16 for 2 GB and smaller) with the official SD Card Formatter. Cards over 32 GB come as exFAT, which the SD library can’t read.
  • File names must fit the old 8.3 format (LOG.TXT, DATA2026.CSV). Longer names fail to open.
  • Always close() or flush(). If power cuts while a file is open, the last data is lost and the card can need a check on a PC.

Code

microsd-uno.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// microSD card module on an Arduino Uno R3 (SPI), with the SD library.
// VCC → 5V (module has a regulator + level shifter), GND → GND,
// MISO → D12, MOSI → D11, SCK → D13, CS → D10.
// Card: FAT32 (or FAT16), 32 GB or smaller. File names: 8.3 format, e.g. LOG.TXT.
#include <SPI.h>
#include <SD.h>

const uint8_t CS_PIN = 10;

void setup() {
  Serial.begin(9600);
  Serial.print(F("Initialising SD card... "));
  if (!SD.begin(CS_PIN)) {
    Serial.println(F("failed - check the card is FAT32, inserted, and CS is D10"));
    for (;;) {}
  }
  Serial.println(F("OK"));
}

void loop() {
  File f = SD.open("LOG.TXT", FILE_WRITE);  // appends to the end
  if (!f) {
    Serial.println(F("Could not open LOG.TXT"));
  } else {
    f.print(millis() / 1000);
    f.print(',');
    f.println(analogRead(A0));
    unsigned long size = f.size();
    f.close();  // close (or flush) so the data is really on the card
    Serial.print(F("Logged - LOG.TXT is now "));
    Serial.print(size);
    Serial.println(F(" bytes"));
  }
  delay(2000);
}

Library: SD (Arduino, SparkFun (ESP32 and Pico cores ship their own SD library)) — compiled with SD 1.3.0.

Expected serial output

Serial Monitor · 9600Output
Initialising SD card... OK
Logged - LOG.TXT is now 8 bytes
Logged - LOG.TXT is now 16 bytes
Logged - LOG.TXT is now 24 bytes

Common errors

“Initialising SD card... failed”

Card not FAT32, not fully inserted, or MISO/MOSI swapped. Try another card — some no-name cards never work over SPI.

Works on USB power, fails on battery

Write bursts dip the supply. Use a stable 5 V source and a 100 µF capacitor across the module’s VCC and GND.

Other SPI device stops working with the SD module connected

Some cheap modules don’t release MISO when CS is HIGH. Give each device its own CS pin, and if it still clashes, power the SD module only when logging.

↑↓ to move · Enter to open