In this illustration we will going to wire the Arduino SD Card Module along with Arduino UNO and MEGA 2560 microcontroller board. We will going to transfer a data from standard SD card to our PC vise-versa. As you can see the illustration below the pin-out is directly connected to the Arduino board by using Peripheral BUS interface that is why this module can be used to other microcontrollers like PIC, AVR, STM Etc. as long has SPI capability. This module allows you to add mass storage data logging to your project like for example storing a configuration, date & time log, data execution, Etc.
Required Component:
Arduino UNO/MEGA
SD Card Module
Jumper Wires / DuPont Wires
Wiring Diagram for Arduino UNO Board
Wiring Diagram for Arduino MEGA 2560
Arduino Sketch Test Code
The SD.h code library is already built-in Arduino IDE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 14CORE TEST Code SD CARD MODULE Data Reading & Acquisition 8888888888888888888888888888888888888888888888888888888888 */ #include <SD.h> //Include the SD.h Code Library const int chipSelect = 4; //Select at pin 4 if your using Arduino MEGA change this to 53 see the illustration above void setup() { Serial.begin(9600); //Start Serial Communication Info at boud rate 9600 Serial.print("14CORE SD Initializing..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); //Define as ouput // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("14CORE Card failed, or not present"); //Stop dont do anything return; } Serial.println("card initialized."); } void loop() { // make a string for assembling the data to log: String dataString = ""; // read three sensors and append to the string: for (int analogPin = 0; analogPin < 3; analogPin++) { int sensor = analogRead(analogPin); dataString += String(sensor); if (analogPin < 2) { dataString += ","; } } File dataFile = SD.open("14COREData.txt", FILE_WRITE); // Write if (dataFile) { dataFile.println(dataString); dataFile.close(); Serial.println(dataString); } else { Serial.println("Error opening 14COREData.txt Data"); // Faild to read the file } } |
Download Other Code Library using SD Card Reader Module | Zip