0% found this document useful (0 votes)
143 views

How To Interface A SD CARD To An Arduino Board

The document provides instructions for interfacing an SD card to an Arduino board in order to store data externally. It explains that the Arduino's onboard memory is limited, so an SD card is necessary for storing larger amounts of data over long periods. The circuit uses resistors to interface the 5V Arduino signals to the 3.3V SD card. An example code reads and writes test data to show the SD card is working properly.

Uploaded by

gdgthrt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views

How To Interface A SD CARD To An Arduino Board

The document provides instructions for interfacing an SD card to an Arduino board in order to store data externally. It explains that the Arduino's onboard memory is limited, so an SD card is necessary for storing larger amounts of data over long periods. The circuit uses resistors to interface the 5V Arduino signals to the 3.3V SD card. An example code reads and writes test data to show the SD card is working properly.

Uploaded by

gdgthrt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

How to interface a SD CARD to an Arduino

board.
Published by gg1 on July 12, 2012 | 1 Response
The ATMega 328 mounted on the Arduino UNO board has 512 bytes of EEPROM to store your data, without loosing them
when you poweroff the Arduino UNO board,
This amount of data could seem to small, but for a large number of projects this is quite enough. If you have to store, for
example, temperature data once a minute for 50 days you need to add some hardware.
If the Arduino system is working close to your PC, you can interface it using the serial line and then the PC will store data.
In some cases the Arduino system has to work far from other intelligent hardwares, for example imagine you want to
monitorize the temperature in a forest, you have to put a large number of Arduino boards on the trees, then when you want,
you have to take them back to retrieve info from them. In this case you can use a SD Card.

On the market, you can find a lot of SD CARD at low prices,


no matter which one you want to use, their functionalities are the same, they only differ for starage capacity and access time.
The interface is the same so you can change the card without change your project. In this tutorial I'm going to use an old 128
MB SD card from lexar, and then a newer 4GB SD card from Verbatim. I'm going to use two different cards only to show
that you won't need different hardware to interface different cards.
Now let's start, playing with the SD card:
SD cards work with 3.3V level, they have 9 pins as shown below:

Bill Of Materials
To build a board to interface Arduino with a SDCard you 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 (i'm using one from an old and broken memory card reader)

We are going to use the resistors to build the resistive dividers, so we can use the 3,3 V starting from the 5V I/O of Arduino.
Building the Board
You have to wire the circuit has shown in the following pictures.
Here you are a simple scheme to realize the circuit over a stripboard.

Final Result

Let's Make a test to try that the board works.


Connect the pins on the board with the corresponding pins on the Arduino board, plug a SD card into the connector and
power on your Arduino board.
Now on the Arduino IDE compile and upload the following code (it is available in File->Examples->SD->ReadWrite), and
wait for the results:

/*
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.
*/
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);

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!");
return;
}
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 = SD.open("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:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}

You might also like