Introduction: Micro SD Card Tutorial
Description
This Micro SD Card is used for transfering data to and from a standard sd card. The pin out is directly compatible with Arduino and also can be used with other microcontrollers. It allow us to add mass storage and data logging to our project.
Features
- Input Voltage: 3.3V/5V
- With all SD SPI Pins out :MOSI, SCK, MISO and CS ,for further connection
- Through programming, you can read and write to the SD card using your arduino
- Make your SD application more easier and simple
- Communicate with Arduino using SPI interface
- Push-pop socket with card slightly over the edge of the PCB so its easy to insert and remove
- 4 mounting holes with 2.2mm diameter
- Only use 4 I/O pins on the Arduino
- Size: 42mm x 25mm x 5mm
Step 1: Step 1 : Material Planning
For this tutorial, the items needed to run this project are:
- Arduino Uno
- USB Cable type A to B
- Micro Sd Card Module
- Female to male jumper wire
- SD Card
Step 2: Step 2 : Hardware Installation
Micro SD Card Module
This module uses the standard SPI interface for communication, which involve SPI buses, MISO, MOSI, SCK, and a CS signal pin. through programming, the data can easily be read and wrote into SD Card by using the Arduino or other microcontrollers.
- CS (chip select)
- SCK (serial clock)
- MOSI (master out slave in)
- VCC (3.3V or 5V)
- GND (ground)
Diagram above shows the simple connection between Micro SD Card Module and Arduino UNO:
- Connect VCC with 5V in the Arduino.
- Then, connect the GND of SD card to the ground of Arduino.
- Connect CS to pin 14
- Connect SCK to pin 13
- MOSI connect to the pin 11
- Lastly, connect MISO to pin 12
After completing the connection, connect the Arduino to power supply with USB cable.
Step 3: Step 3: Insert Coding
Lets try an example in the Arduino.
- Open the Arduino software
- Click 'file'
- Find the 'example'
- Click 'SD'
- Choose 'ReadWrite'
Step 4: Step 4 : Choose COM Port
Just click at 'Tools', then choose your port available on your PC.
Step 5: Step 5 : Upload Souce Code
Upload the source code into the Arduino and open the Serial Monitor to se the result.
Step 6: Ster 6 : Result
The following result will be displayed in the monitor. In this example, the .txt file named "test.txt" was created and the sentence "testing 1,2,3." were wrote into the .txt file. After this, the sentence "testing 1,2,3." were read back from .txt file and display on serial monitor.
5 People Made This Project!
- taichichuanwijchen made it!
- marlonss4 made it!
- r570sv made it!
- PaulF265 made it!
See 1 More
26 Comments
Question 1 year ago
Hi, thank you very much for this posts, it is very interesting for me. But I have a question about how to read from SD card. For example, I have number 3 and I write to SD card once every minute. How can I get data at any point in time?
Answer 1 year ago
Hey,
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
} else {
Serial.println("error opening test.txt");
return;
}
that should work. what the code is doing is that it will first open the file, then it will chack if that file existes. Then it will go through every char in the file and print it on the serial monitor.
Bust of luck,
Electronics_boy
2 years ago
Hi, thanks a lot for the information. Do you know how to detect when the SD was removed o extracted and when it was put on again? for example, it is working normally and it is on, but someone wants to extract SD and does not turn off the device and then put again, so dont work well, but if i detect that was extracted i can do somethink. do you know somethink like that?
2 years ago
Alright, but if you put the card in an mp3/mp4 and then connect it with the PC, the PC will read the microSD card as well or not?
Reply 2 years ago
For anyone who may have the same question, it really works! I eventually tried it myself.
2 years ago
Worked straight. Thanks
Question 2 years ago
How to write binary data into the sd card using Arduino?
Tip 2 years ago
I'd like to take moment to clarify some things and maybe dig a little bit deeper in whats what.
In this example the Arduino Uno board is used. If you have another board please take a look at what pin setup your specific board is using.
From the text above, the SD card CS (Chip Select) is pointed out to be wired to pin 14 at the Arduino. In the figure however the yellow wire goes to pin 4. Also in the code the SD.begin() is using the pin 4 as argument. So this is a typo (well, actually it is the pin 14 on the ATMEGA328 MCU chip which is connected to pin 10 on Uno) - connect to pin 4 to get it to work with the example code.
It often directs the CS to pin 4 in different demos, i don't know why.
If you take a read in the reference of the SD [https://www.arduino.cc/en/reference/SD] it tells you that the Arduino pin 10 as a standard pin for CS [ SD.begin(CSPIN) ] and in the case that you decide to use standard pin (10) you will not need to specify the pin as an argument, and makes this setup to use the Arduino pins 10 through 13. This is useful as to keeping the wires together. Quite often if you would like to use LCD, or what ever, the pin 4 is then used by that or other setups.
This specific SD Card breakout is using a 5v to 3.3V voltage regulator (U) so you don't need to worry about burning/destroying the card from a standard 5V Arduino system. Also the other U1 marked chip on the PCB (Printed Circuit Board) is a level converter that keeps the 5V on one side and 3.3V on the other side. All the interface memory logic's is taken care of by the memory card. So if you would have a pure 3.3V Arduino system those chip would not be really needed, and you could look for a less complex SD card reader. But this break out card works in both 5V and 3.3V setups, so you wouldn't need more than one break out if you are trying both type of Arduino boards.
For further details see also: https://www.arduino.cc/en/Reference/SDCardNotes
I hope that you will have much joy of the SD card storing and reading.
And one final thing - allways(!) format all your SD cards with "SD Card Formatter" from SD Assosiation. [https://www.sdcard.org/downloads/formatter/]
Question 3 years ago
Hi! Can I use different pin connections from the tutorial as long as they are similar? i.e. can I plug in MOSI into the analog PWM pin #6 instead of the #11 that this tutorial indicates? I am already using #11 for another sensor.
Question 3 years ago
MY CODE IS SHOWING INITIALIZATION FAILED , WHEN I TRIED THE CODE IN THE EXAMPLES. I AM USING THE ARDUINO MEGA2560. PLEASE HELP ME WITH IT ON URGENT BASIS. THANKS
3 years ago
What's the maximum supported capacity of the micro sd card? also how fast should the card be?
http://bigbelectronics.in/product.php?product=micro-sd-tf-card-memory-shield-module-spi-micro-sd-storage-expansion-board-arduino
3 years ago
I keep seeing the error "SD card initialization failed!". I checked the connections multiple times, I am facing the same error though.
Can you please help me!
Thanks in advance...
3 years ago
may i ask u some problem of my program, it says "error opening text.txt", can anyone else know what happened?
Question 3 years ago
hi , where i can buy this parts.
5 years ago
I'm getting the "initialization failed!" error and wondering what's not correct. Can anyone explain this code?
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Reply 5 years ago
Got it! For an Arduino Mega, we want to use pins 50, 51, 52, and 53 for MISO, MOSI, SCK, and CS, respectively.
Reply 5 years ago
i'm using arduino UNO still facing same error
Reply 4 years ago
Were you able to figure out what's wrong?
I'm having the same error.
Reply 4 years ago
double check all your connections to the SD reader. basically the error message means that your arduino couldnt communicate with the SD reader properly. maybe the SD reader isnt getting enough power. maybe its not connected to the correct pins on the arduino
Question 4 years ago
for example :(Nano V3.0 ATmega328P CH340G 5V 16M micro-controller Arduino
Micro SD TF Memory Card Reader Module with SPI interface For Arduino PI Portable)