ESP32 with SD card modules — The master guide

Diego Eguez
6 min readDec 12, 2020
ESP32 (DEVKIT V1) and 16Gb SanDisk SD card

Using SD cards with an ESP32 is simple, right? In reality you might find some shortcomings; this article explores common drawbacks and provides an in-depth view of the SD library.

Connecting to the SD card module

SD card module with SPI interface
SD card module with SPI interface

Most SD card modules are like the one in the picture above. They connect through a protocol known as Serial Peripheral Interface (SPI) and accept either 5V or 3.3V (note most modules won’t work with 3.3V).

ESP32 connection with SD card module
ESP32 connection with SD card module (note the regulator has been removed)

For testing, you can connect the module to the ESP32 as indicated in the diagram above. For reference, the SPI pins of the ESP32 are: MOSI GPIO23, MISO GPIO 19, SCK GPIO 18 and CS GPIO 5. Note the Clock Select (CS) pin is not fixed as the other SPI pins. You can practically use any pin as the CS pin.

Now, plug in a microSD card and try the code below. You can ignore #include <Arduino.h>, if you’re running this code in the Arduino IDE; though it should not cause any problems.

--

--

Diego Eguez
Diego Eguez

Written by Diego Eguez

I am software engineer passionate about programming and electronics. Through the years I’ve had the oportunity to learn and apply many technologies.

Responses (2)