Dear friends welcome to this Arduino SD Card Tutorial! In this video, we will see how to use the SD card module with Arduino in order to add storage space to our projects. So, let’s start.

Intro to the Arduino SD Card Tutorial

The module is very easy to use and the cost of it is very low. It costs around 2.5 euros. In order to use it, you will also need a Micro SD card.
The SD card module is 3.3 Volt device so it won’t tolerate the 5V logic levels that Arduino uses. Luckily most of the modules for Arduino use a 3.3V regulator and a logic level shifter so they can work with Arduino.

——————–
WHERE TO BUY
——————–

 

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

The connection of the module is very easy.The module uses the SPI protocol in order to communicate with Arduino.So, we need to use the hardware SPI pins on our Arduino board. On an Arduino Uno, those pins are pins from 13 to 10. Different Arduino boards have different SPI pins. So be careful. I will post them in the description of the video. Let’s start connecting the module to an Arduino Uno. There are 7 pins on this module, we only have to connect 6 of them. Four of them are used for the SPI communication one is Ground and the other is Vcc. Ground goes to Arduino Ground. Vcc goes to Arduino 5Volts. The next pin MISO goes to digital pin 12. Pin MOSI goes to digital pin 11. Pin SCK goes to digital pin 13. and lastly pin CS goes to digital pin 10 on Arduino. This is the only pin that you can change to any digital pin you like. The other pins are fixed. You cannot change them.

I have prepared a small program in order to test the read and write functionality of the SD card module. It uses the standard SD.h library. I just developed some easy to use functions in order to make writing to the SD and reading from the SD card easier.

Let’s see the code. First we initialize the SD card. Then we create a file named test.txt. If the file exists it will be opened if it doesn’t
exist it will be created. Then we write a small text in the file and then we close it. Only one file can be open at any time so we have to close files that we don’t use. Then we will try to open a filename prefs.txt that already exists in the SD card and read some lines from it. Then, of course, we have to close the file. Each function prints something to the Serial Monitor in order to be able to check if everything is working as expected. Let’s now upload the program to Arduino and see the output at the Serial Monitor.
The program is now loaded to Arduino ok let’s open the Serial Monitor and see the output.

As you can see the SD card is initialized, is ready to use we have created a file successfully, and we are writing to the file the sample text. The file is closed. And then we open the preferences file. The file is opened and we read two lines line 1 and line 2, and then we close the file.
Let’s now connect the SD card to the computer and see what it contains. As you can see the SD card contains two files. One file is named test.txt as the file we have created in code. And inside it there isthis sample text that we have printed that’s it next is the prefs.txt file which was created manually in the beginning. Inside it I have placed 5 lines of data, line 1, 2, 3, 4 and 5 and in the code all we do is we read the first two lines of this file. As you can see everything is working fine.

——————–
CODE
——————–

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv