Arduino Projects Online

Complete Details about the Arduino

Arduino Datalogger with Memory Card

Arduino Datalogger with Memory Card How do you save data from an Arduino-based device to a memory card? Fortunately, a microSD card and SD card breakout board now make this an easy task. Below is a simple tutorial on how to capture data generated from your Arduino and write it to a text file on a microSD card for later analysis. Let’s get started!

SD Card Breackout Board

Arduino Datalogger with Memory Card

All connections (pins) in the breakout board are clearly labeled. Take note — the breakout board uses SPI protocol, so for use with Arduino Uno or a Pro Mini-compatible board, make interconnections as follows:

  • 5 V to 5 V (VCC)
  • GND to GND
  • D13 to SCK
  • D12 to MISO
  • D11 to MOSI
  • D10 to CS


Another Arduino Library

Now get ready to install the required Arduino library. Just download the zip file “SdFat-master” from here, extract the zip file, and copy the “SdFat” folder into your Arduino IDE’s “Libraries” folder. Location of the library — usually in the “Sketchbook” folder — can be found in the Arduino IDE’s “Preferences” menu. As you may have noticed, there is an SD card library included with the Arduino IDE. However, we prefer the above-introduced library.

Arduino Datalogger with Memory Card

Also remember to format your microSD card using your computer (try FAT16 or FAT32 for bigger memory cards). Next, insert the microSD card into the microSD adapter and plug it into your breakout board. Finally, open/restart the Arduino IDE.

Also Check:

The Pre-Flight Test

To conduct your first test to ensure that everything is okay up to this point, open the “SdInfo” sketch in the IDE (File > Examples > SdFat menu). Make sure that your Arduino is connected to the computer and that the serial port is correct before uploading the sketch. Author’s hardware setup is shown here:

Arduino Datalogger with Memory Card Arduino Datalogger with Memory Card

Arduino Datalogger with Memory Card

Start Data Logging

Now you can write data to the SD card. First, open the “Datalogger” example sketch (File > Examples > SD > Datalogger) and upload it to Arduino. This sketch reads the value from three analog input points and writes it to a text file. Once uploaded, open the serial monitor to “see” the logging. After this, remove the memory card and connect it to your desktop PC with the help of a USB memory card reader (most laptops have a built-in card reader slot). Once you find the contents of the memory card, you can read the “DATALOG.TXT” file saved on it. Voila!

Arduino Datalogger with Memory Card

If you want to preserve your data in a neat format for future use and/or analysis, simply call upon your favorite spreadsheet to open and process the text file (see the example shown below).

Arduino Datalogger with Memory Card

LM35 & Memory Card

This is a little DIY project with an Arduino Uno, SD card breakout board, and LM35 temperature sensor. To build a temperature logger using a microSD card, just connect the LM35 analog temperature sensor chip to your already-prepared hardware (used for your previous experiments) as indicated in the wiring diagram shown below.

Arduino Datalogger with Memory Card

After hooking everything up, upload the compiled code to Arduino and check the result on your computer after some time by reading the “LOG.TXT” file saved in the microSD card. This is a “dirty” experimental code; of course, you can polish it for your need and taste.

Arduino SD LM35 ino file
  1. #include <SPI.h>
  2. #include <SD.h>
  3. File myFile;
  4. int x = 0;
  5. int tempValue;
  6. void setup()
  7. {
  8. pinMode(10, OUTPUT);
  9. SD.begin(10);
  10. }
  11. void loop()
  12. {
  13. tempValue = analogRead(A0);
  14. myFile = SD.open(“log.txt”, FILE_WRITE);
  15. if (myFile) {
  16. myFile.print(“Temperature “);
  17. myFile.print(x);
  18. myFile.print(“:”);
  19. myFile.println((long)tempValue*0.48875);
  20. }
  21. myFile.close();
  22. x++;
  23. delay(1000);
  24. }
Updated: 14th July 2017 — 12:14 pm
Arduino Projects Online © 2017 Frontier Theme