Recent Tweets

How To: Connect Your Old SD Card To An Arduino

How To: Connect Your Old SD Card To An Arduino

Last Updated: June 7, 2013 9:00 am 0 comments

SDCard headers

After a few weeks playing with my arduino, It started to become clear that I would need a way to start storing some data, I had already ordered a network shield which has a built in micro sd slot, but that wouldn’t be with me, for at least a week… so I had to find another way.

You can find a lot of SD Cards at low prices, no matter which one you want to use, their functionalities are the same, they only differ for storage capacity and access time. The interface is the same so you can change the card without changing your project.

In this tutorial, I’m going to use an old Micro SD Adapter, along with a 2GB micro SD card.

This image shows the basics for connecting the SD Card directly to the arduino, with this method you can  solder pins directly to the SD card adapter and slot in your micro sd card with ease.

Arduino SD layout

SD Cards work with 3.3V, they have 9 pins as shown:

Things you’ll need

To build a board to interface Arduino with a SDCard, you’ll need the following materials:

  • A pinhead six pins long
  • 3 3,3 Kohm resistors
  • 3 1,8 Kohm resistors
  • A small piece of stripboard
  • Wires
  • A SD card connector (like I said above, I’m using the Micro SD adapter)

We are going to use the resistors to build the resistive dividers, so we can use the 3.3V starting from the 5V I/O of Arduino.

Building the Board

You have to wire the circuit, shown in the following picture.

Here is simple scheme of the circuit over a stripboard.

Test the board works.

Connect the pins on the board with the corresponding pins on the Arduino board, plug the SD card into the adapter and power on your Arduino boar.

Now on the Arduino IDE compile and upload the following code.

(it is available in File->Examples->SD->ReadWrite),

and sit back & wait for the results.

The Code
SD card read/write

This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4

created   Nov 2010
by David A. Mellis
updated 2 Dec 2010
by Tom Igoe

This example code is in the public domain.


File myFile;

void setup()
   Serial.print("Initializing SD card...");
   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
   // Note that even if it's not used as the CS pin, the hardware SS pin
   // (10 on most Arduino boards, 53 on the Mega) must be left as an output
   // or the SD library functions will not work.
   pinMode(10, OUTPUT);

   if (!SD.begin(4)) {
       Serial.println("initialization failed!");
   Serial.println("initialization done.");

   // open the file. note that only one file can be open at a time,
   // so you have to close this one before opening another.
   myFile ="test.txt", FILE_WRITE);

   // if the file opened okay, write to it:
   if (myFile) {
      Serial.print("Writing to test.txt...");
      myFile.println("testing 1, 2, 3.");
      // close the file:
   } else {
      // if the file didn't open, print an error:
      Serial.println("error opening test.txt");

   // re-open the file for reading:
   myFile ="test.txt");
   if (myFile) {

      // read from the file until there's nothing else in it:
      while (myFile.available()) {
      // close the file:
   } else {
      // if the file didn't open, print an error:
      Serial.println("error opening test.txt");

void loop()
	// nothing happens after setup

upload the code, to the arduino and open your serial monitor window (ctrl + m)

The following two tabs change content below.


Web Developer
Senior Web Developer who combines passionate coding skills, strategic vision with strong hands on leadership and enormous personal drive. I create re-usable industry standard code that is used time and time again, producing outstanding results for every project I work on! I also like Classic Motorbikes, Quad bikes, Downhill Mountain biking & Learning electronics using the Arduino.

Latest posts by Marty (see all)