SD (Secure Digital) cards are a form of flash memory which do not require power to retain their contents. An SD card stores data in NAND logic gates which allow the data to be written and stored on the memory card. The cards are re-writable with a high memory storage capacity in comparison to a CD, an SD card comparatively transfers data faster and is a long lasting storage device. The SD card serves as an extremely suitable local data backup, which can be re-used. Many SD cards come with protection locks in the form of a switch on the side of the SD card which prevents reading and writing the of data when the switch is enabled.
About the module
An SD card module is an essential component for all microprocessor/microcontroller based projects which helps in data logging and creates a local data backup which can be accessed at any point later in time, unlike in projects or systems which lack a card reader module where the data from sensors or other input devices is immediately lost as soon as the system powers off. The module works on 3.3V DC, any voltage higher than 3.6V may damage the SD card permanently. To avoid this the module has a board regulator. The module can be interfaced with in two ways, that is, using SPI mode and SDIO mode. SDIO mode is faster and is used in mobile phones and digital cameras, however SPI is easier to use.
How does the module work?
(i) Connections:• Connect the GND pin of the Arduino to the GND pin of the module.
• Connect the VCC pin of the module to the 5V pin of the Arduino.
• Connect the MOSI (Master out slave in) pin of the module to pin 11 of the Arduino UNO.
• Connect the MISO (Master in, slave out) pin of the module to pin 12 Arduino UNO.
• Connect the SCK pin of the module to pin 13 of the Arduino UNO.
• We can connect the CS (Chip selects) pin of the module to any digital pin of the Arduino UNO apart from the already used pins. The choice is arbitrary.
This is the SPI pin configuration when using an Arduino UNO board, please make sure to connect the right SPI pins to the module if using a different board, like an Arduino NANO. Ensure that the CS pin of the Arduino always has a low output, i.e.The CS pin should not send a high digital signal otherwise it will interfere with the working of module by sending a lot of noise to the system as a result of which the module will not work. Also make sure to insert the SD card in the module before using it. Follow the above instructions and the circuit diagram given below to successfully connect your microprocessor based development kit to the SD card module.
Follow the code given below to read data from your SD card and to write and store data to the same as well. This data can later be accessed using a computer, the SD here serves as a local backup system for study and use later depending on our requirement.
• We create a file object named myFile.
• We declare the chip select pin as pin 10.
• Since we’re demonstrating how to write the code for an SD card reader, I will run the code only once in the setup section.
• We declare chip select pin as an output pin and keep it low throughout the code.
• We initialize the SD card with the SD. Begin function.
• We assign a task to the file object named myFile and use the SD.open(“test.txt”,FILE_WRITE) command to create a file named test which is text file, the argument FILE_WRITE means that we can read as well as write on this file.
• After this command a new file test.txt is created, if this file already exists then instead of creating this file it will just open this file.
• If the file is open write to the file the following text “Testing text 1,2,3,…”.
• Once we’ve written to the file we will close the file. At any given point of time we can only open one file.
• We will open the file again, if the file is open we will read the contents of the file.
• Since we can only read one byte at a time, we will use a while function which will enable us to read all the characters on the file as long as they are available.
• Once we’re done reading the file contents we will close it.
• We are leaving the loop empty in this case as we only want to read and write what is written on the file once, however if we are using some sensor we can write the code in the loop to store the sensor values on the memory card, whenever it is triggered.
We can also access the data in the SD card via a computer and use it to create plots, charts and records as per our requirements using various software’s.
Applications:• Useful for data logging
• RFID attendance systems
• Used with thermal sensors to store readings
• Used with servo motors to store positions