CNAP

MicroSD Card Module Reference

An SPI breakout for microSD cards, used for reading/writing files — commonly for data logging.

Pin names

NameDescription
CDCard Detect — indicates whether a card is inserted
DOMISO — SPI data in
GNDGround
SCKSPI clock
VCCPower (5V, regulated to 3.3V onboard)
DIMOSI — SPI data out
CSChip Select

Attributes

This component has no configurable attributes.

Usage

Connect VCC to 5V, GND to GND, SCK/DI (MOSI)/DO (MISO) to the board's hardware SPI pins (13/11/12 on an Uno), and CS to any free digital pin. Read/write files with the built-in SD library.

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

const int CS_PIN = 4;

void setup() {
  Serial.begin(9600);

  if (!SD.begin(CS_PIN)) {
    Serial.println("SD card init failed!");
    return;
  }

  File logFile = SD.open("log.txt", FILE_WRITE);
  if (logFile) {
    logFile.println("Sensor reading: 42");
    logFile.close();
  }
}

void loop() {}

Examples

DescriptionAttrs
Default microSD module{}

See also