Part

microSD card module

A real FAT16 card behind SD.h. Watch the files a sketch writes appear, and download them.

See every part
  • 6 pins
  • 2 settings
  • In 2 projects
  • In 1 lesson
Drawn live by the editor's own code, at the size you see it.
At a glance

The microSD card module in brief

What it is, and every setting the properties panel gives it.

A microSD card module is the small SPI breakout with a card socket, a 3.3 volt regulator and a level shifter, which is why it takes 5 volts on VCC from an Uno: CS to pin 4 or 10, SCK to 13, MOSI to 11 and MISO to 12, or on a Mega 52, 51, 50 and 53. Mokxi puts a 4 MB card in it, formatted as a real FAT16 volume with a partition table, and the card speaks the SPI mode of the SD specification: CMD0, CMD8, ACMD41, CMD58, single and multiple block reads and writes, with R1 status, data tokens, CRCs and busy after a write. The files property sets what the card holds when the run starts, as 8.3 names mapped to text; while it runs, whatever a sketch writes appears beside the board and can be downloaded singly or as a disk image. Clicking the board ejects the card, and a sketch then has to call SD.begin() again. Real cards are slower to initialize and stall now and then while erasing, and SDHC cards, FAT32 and long file names are not modeled.

Family
Clocks and links
Pins
6
files
{"HELLO.TXT": "Hello from the SD card.\r\n"}
inserted
true
Pins

6 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
Role
What it does
GND
Input or output
Ground.
VCC
Input or output
Supply, 3.3 to 5 V.
MISO
Output
Data from the card, at 3.3 V.
MOSI
Input
Data to the card.
SCK
Input
SPI clock.
CS
Input
Chip select.
How to use it

How to use a microSD card module with an Arduino

The module goes on the Uno’s SPI pins: MOSI to 11, MISO to 12, SCK to 13, and CS to pin 10, with VCC on 5 V. Call SD.begin() with the CS pin and check what it returns, then SD.open() a file with FILE_WRITE, print to it and close() it.

Bytes wait in a 512-byte buffer until a sector fills or the sketch calls flush() or close(), so a logger that keeps its file open should flush every second or so, as the rocket flight computer does. Pull the card out mid-run and SD.begin() has to be called again.

Part pin
Board pin
CS
Pin 10
MOSI
Pin 11
MISO
Pin 12
SCK
Pin 13
VCC
5 V
GND
GND
Arduino Uno: rocket flight computerlive0.000 s 0.00x
Hold the button
This is the simulator itself, running here. Click anything to open it in the editor.
Writing a line to the card
#include <SPI.h>
#include <SD.h>
void setup() {
  Serial.begin(9600);
  if (!SD.begin(10)) {
    Serial.println("No card");
    while (true) {}
  }
  File file = SD.open("LOG.TXT", FILE_WRITE);
  file.println("Hello from the Uno");
  file.close();
}
void loop() {}
How it is modeled

What is true about the microSD card module, here

In its help article’s own words: what the simulation gets right, and where it stops.

Not modeled

Real cards are slower in ways this one is not: long initialization, and a write that now and then takes a hundred milliseconds while the card erases. High capacity (SDHC) cards, FAT32 and long file names are not here.

Everything goes over SPI a bit at a time, driven by the sketch, so reading a 512-byte sector takes tens of milliseconds on an Uno, where a real SPI port takes well under one. On a faster board each bit waits a little before it is read, so the answer the card has just put on MISO has arrived; that makes a card read on an ESP32-C3 or a Pico slower still. It is the one thing about this card that is slower here than on the bench, and it matters when a sketch also has to keep up with something else, like a GPS: the GPS logger in the gallery writes its lines five at a time for that reason.

From microSD card module, in full.

Projects

See the microSD card module in a project

2 built-in projects use it. Each opens in the editor, already wired.

Lessons

Where it turns up in a lesson

One lesson places it in its own circuit.

Boards

The boards it is shown on

Each of these 2 boards has a built-in project with the microSD card module in it.

Libraries

Arduino libraries for the microSD card module

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the microSD card module

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.