Connect your Arduino to your computer with the SD card reader attached. If you have a micro SD card reader on your computer you could skip this step but it's worth knowing how to do it this way. The sketch looks for a file of a particular name on the SD card and reads it out and prints it to the Serial Monitor if it's there.
Step 1:
Grab the code and give it a try.
/* Read microSD Card This is specifically for reading a .txt file off a microSD card using the SD board and the Arduino The libraries in question aredocumented here... https://www.arduino.cc/en/Reference/SD documented here... https://www.arduino.cc/en/Reference/SPI SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 10 It is an important skill for an STEM worker to be able to understand and use a tool that they don't fully understand. This is personallly difficult for me because I want to know how it happens but sometimes you just gotta go with the flow and this is one of those times. I got the very lightly commented code below from https://electronicshobbyists.com/arduino-sd-card-shield-tutorial-arduino-data-logger/ and I am thankful to be able to do so. There are many almost identical versions of this code so it is clearly in the public domain. I will add my own thoughts or perhaps insights to the comments with my initals so that you know to be cautious about them. */ // these #include statements make the functions defined in these libraries // accessible to the writer of this sketch. See the documentation links // above for detailed descriptions of all functions. Notice that any function // used from these libraries starts with SD.'function' or SPI.'function'. You // can tell the IDE recognizes them because of the color change. #include <SD.h> #include <SPI.h> // Creates an object that is of a type File and gives it a name much // like defining an int or float (needs more clarity) -- BE File sdcard_file; bool removeFile = false; // if you wish to erase file after reading set to true // NOTE: data file name must be manually edited on lines 77, 86, 103, 106 // the CS pin manages the back and forth flow of information to the card as // part of the Serial Protocol Interface (SPI) method of communication. - BE int CS_pin = 10; // this test sketch has been set up to complete a short set of writes and // reads to the connected SD card. This is not actually looping as you would // need in a data logger. This is once and done which is a useful feature of // the void setup() call. void setup() { // Opens the serial monitor so we can watch the write/read process Serial.begin(9600); //Setting baudrate at 9600 while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } pinMode(CS_pin, OUTPUT);//declaring CS pin as output pin // SD.begin initiallizes the library and the card and returns TRUE if // successful. Argument articulates the control pin. Default pin depends // on board. if (SD.begin(10)) { Serial.println("SD card is initialized and it is ready to use"); } else { Serial.println("SD card is not initialized"); } // Check to see if the file exists: This is a potentially useful tool when reading an // SD card. if (!SD.exists("datalog.txt")) { Serial.println("data file doesn't exist."); Serial.println("You need to edit the read sketch"); } else { Serial.println("data file exists."); // This opens a file called mydata.txt on the card in the READ mode.See microSDTest.ino // for additional comments. sdcard_file = SD.open("datalog.txt", FILE_READ); if (sdcard_file) { Serial.println("Reading from the file"); Serial.println(); while (sdcard_file.available()) { Serial.write(sdcard_file.read()); } sdcard_file.close(); Serial.println("Done with Read"); } else { Serial.println("Failed to open the file"); } // delete the file if removeFile = true if (removeFile) { Serial.println("Removing data file..."); SD.remove("datalog.txt"); } // verify that file is gone if (SD.exists("datalog.txt")) { Serial.println("data file still exists."); } else { Serial.println("data file is gone."); } } } void loop() { //Nothing in the loop }
Step 2: Things to try!
You can select the output of the data reader from the serial monitor and copy/paste it into a .txt file on your computer. If you have a microSD card reader on your computer you can just copy the file from the SD card onto your computer.
Below is a sample of the data file that I read using this sketch. The temperature sensor had been outside in the sun on a hot day and was truly up to 40C. This is a 10 min slice of the cooling down process inside. Easy to drop into a file or Excel to plot.
Temperature (C)
0, 40.33
1, 38.87
2, 36.43
3, 34.47
4, 33.50
5, 32.52
6, 31.54
7, 31.05
8, 31.05
9, 30.57