Tutorial 11 for Arduino: SD Cards and Datalogging


This is my first in a series of more advanced Arduino tutorials. Now that we’ve covered the basics in tutorials 1-10 (you have watched them all right!?), it’s time to start pursuing some more complex projects! In this episode, we’ll utilize an SD card shield from to create a datalogger. First, I’ll walk you through the process of reading from, and writing to an SD card. Then, we’ll utilize some of our knowledge from tutorials 4, 6, 7, and 8 to add several sensors that we can poll periodically using our datalogger. The logger will record sensor values to its SD card in a useful format so that we can later use a computer program like Microsoft Excel to visualize the data. Download the schematics and source code first so you can reference them while you watch the video. For the first time, I’m using fritzing to draw the circuit schematics. So, take a look at them, and let me know what you think!


You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.


  1. Pingback: Tutorial 12 for Arduino: RFID Card Reading |

  2. Hi jeremy.
    Am noob in do i read data from SD card then display the data on an LCD module??

    • get a 2-in-1 USB SD Card Reader Cable. The SD will show up in your libraries with the name you gave it. Open it. every listing is a file. Open a file and you will see the log on excel. Copy it to computer. You can delete files from the SD at you option. Put the sd in trash and then remove the USB cable from your PC.

  3. Hello jeremy,
    your tutorials are very helpful. Can we use any SD Shield for this.
    Could you please give some information for selecting the shield.
    A link from e-bay would be great!

  4. OR can i use USB flash drive instead of SD card?
    If can, how can i do it?

  5. Hi jeremy, great tutorial. I am using a different sd card shield than the one used in this video but program seems to be working fine. Except the only problem I am having is the program doesn’t stop running when there isn’t a card inserted in the shield, it continues to the loop and starts looping Couldn’t access file like below.

    Initializing Card
    Card Init. Failed
    Couldn’t access file
    Couldn’t access file
    Couldn’t access file
    Couldn’t access file

    Any ideas on how to stop this … Thanks

  6. hi Jeremy.
    is it possible to display the content of a flashdrive to an LCD (touch screen)?
    what can be the materials to be used? and what are the codes for it? please help us. thank you.

  7. Jeremy Blum, hey man great tutorial, Really helped me a lot in getting the data logged in the SD card but I am having the problem that writing on the SD card only happens when I open the serial monitor, Otherwise it doesn’t happen. Any reason why?

    • Opening the serial monitor resets the Arduino, but it shouldn’t have any impact on whether it is able to write to the SD card. Are you actually taking the SD card out, putting it in a computer, and seeing that nothing is written without the serial monitor connected, and doing the same check when the serial monitor is open? Maybe it’s not writing either time, but you are mistaking the debug statements as evidence that it is actually writing to the card.

      • Hey jeremy, i have exactly the same problem, the data is not written on the sd card unless I open the serial monitor. I did check it on my computer each time so i have absolutely no idea what it could be.

  8. Hi Jeremy Blum
    I have question, How do you created new name of file? I mean , I want created more one file in SD card.

  9. Hi Jeremy Blum
    i have a small problem
    excel but all data in one column with commas between them !
    what is the problem?

    • Hi Jeremy Blum
      i have a small problem
      excel put all data in one column with commas between them !
      what is the problem?

    • Under the toolbar select text to data. try to open the file with the comma or space separator. Basically you have all data going to a single location

  10. hej Jeremy
    Sorry for bothering you, but I have a problem. I have programmed arduino for different scenarios. If is scenario 1–> erase and write 1 in data file, if is scenario 2 –> then erase and rewrite the same file and write in file 2 and so on…

    How can i compare if is written 1 or 2 or anything else on SD card?

    Thank you, Johnny

  11. Hello dude! This is so cool. But this is only storing data to the sd card, do you have any link or tutorial about accessing files from the SD card? Thanks a lot!

  12. Hi, this is almost idientical to the SD examples in the arduino IDE. However, they are also including the SPI.h
    I can’t get this to compile unless i also include that.
    As a noob, I wonder what’s going on?
    Also, how many bytes are your compiled sketch, with and without the SPI.h?

  13. Hi Jeremy,
    I wrote a program that logs pressure readings to an SD card and creates a new file after a valve closes. This generates lots of small files instead of appending to one really big one (weeks of data logging accrued).

    Is there a way to transfer the CSV files stored on the SD card to a nearby networked computer connected to the arduino’s USB port? I’d remove the SD card to transfer files for data analysis but the datalogger is in a difficult to access location. Arduino ethernet shield is an option as well.

    Thanks for your advice

  14. Hello there, quick question…I’m trying to create a snazzy touch screen menu that navigates through 5 to 10 different pages on a 7 inch LCD. In order to make the menus look nice I figured the easiest way to create the menu would be to photoshop my individual menu pages and then store the images on an SD. My arduino (Mega 2560) would then just pull the image it needed based on what it needed to draw at the time. Is this do-able or am I reaching?

  15. Hi.

    I’m working in a project about to get de ambient light with a ambient light sensor, and save all the data into a micro SD card, I using de SPARKFUN MICRO SD SHIELD. I need to save de data each period (1 Hour) and each 6 hours get the average of that 6 hours and also I need to get the time and the date for each read data.

    I hope that you help me with this project.

    See you.

  16. Hi,
    Great tutorial !! really helpful.

    I am trying to log voltage and current onto an SD card using .csv format.
    My issues is that I need current and voltage with decimal places. (float type)
    However I cannot convert from float to string in this line:

    String dataString = String(seconds) + “, ” + String(Current) + “, ” + String(Voltage);

    What should I do please?


  17. First press the panic button (reset button) on the logger. Better yet, both buttons

    Then check the SD card files by using the SD reader on your computer. If the computer reads the SD it was properly initialized. Like, other media, it needs to have stored a file allocation table so files can be written to it.

    If not then initialize it with your computer.

  18. Hi Jeremy,
    thank You for Arduino tutorials. It’s great for beginners as me. I tried to do datalogging and I have problem with temperature sensor LM35 reading. I use the code to convert “temp = (5.0 * analogRead(tempPin) * 100.0) / 1024″
    When I use analogRead only for LM35 , it’s working. But if I use one more sensor (like LDR) or potentiometer , analogRead for LM35 starts jumping. If potentiometer value is 0, LM35 values are fine. If potentiometer is like 100, LM35 values are jumping.
    How can other analogRead change readings for temperature readings? How to solve it?
    I tried to change several LM35 sensors, it’s the same.

    Thank You in advance!

  19. Sorry, I found it.
    If somebody face the same issue, here is the link

    • Glad you got it working! I was going to suggest the delay() between sequential reads, but it looks like the community beat me to it! Gotta look out for those “high” impedance analog reads!

  20. I didin´t get the commandFile.available(). In SPI the comunnication is one byte at a time. So when we make the float decade why is commandFile.available() = 4? Shoudln´t it be 1? The folowing loop runs how many time in case of 1000? 4 times? Shouldn´t the float decade be inside the loop? And isn´t that a infinite loop? Im not getting it.

    Another question for 1000 , why is there 4 bytes? the max number with 4 digits is 9999 and 9 in binary is 1001 we only need 4 bits not 8. I don´t get it

    Thank u for your time jeremy

  21. Hi Jeremy,

    That was a very helpful tutorial — I would be interested in knowing if the SD card data had to be accessed by removing the card and inserting it to your PC or if it could be accessed via the microcontroller (through usb) and how that might work?

    I am interested in creating a battery powered application where data can be logged, and then when connected via USB it can be read by the connecting device (PC or laptop). The complication comes in sharing the SD card between devices.

    Any suggestions?

    Thanks in advance,

  22. Hi jeremy

    Your tutorial is really helpful thanks. If I want to read the values of the voltage and current and store them in the SD card how do I do that?

  23. Hi Jeremy, great tutorials!

    You are a great inspiration for me, but I have one question, instead of ID number, how can we put the date and time, on the data-logger?

    Thanks a lot!

  24. hi Jeremy this tutorial are great i learned a lot, i have a question, if i want to read my file from the sd card, how i can serate my datas from the commas and get each data

  25. hi Jeremy this tutorial are great, i learned a lot, but i have a question if i want to read my file how i can get my data from the file but without commas how i can divide my datas from the commas

  26. Hi jeremy,your tutorials are useful and knowledgeable. Plz help me regarding deleting data in particular line which we want in SD card using arduino also help how to display SD card data in LCD display Using arduino

  27. Hi Jeremy
    Your tutorials are awesom. Can we use the stored data log values to be processed by the arduino. So that we use those values to process again.

  28. Hi, Jeremy, i have one question, please maybe you know why when i log the data in format .csv and when i open the file, all the datas are only in one square? i Think a i did the same like you, but i cant get the same thing like you :) . Thank you for yor answer

Leave a Reply

Required fields are marked *.