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 cooking-hacks.com 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:
Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.













November 15, 2012 at 10:11 am
Sorry that may have been a little vag. I am connecting the 27937 straight to the arduino is that right? I have a FAT32 memory stick that the 27937 says it supports.
December 18, 2012 at 4:41 pm
Does that module have logic level shifting built in? SD cards are 3.3V but the arduino is 5V.
November 26, 2012 at 3:29 am
I am trying to write a timestamp to a csv file. Using the Time.h file I’ve created:
time_t myTime;
int myHour;
int myMinute;
int mySecond;
int myYear;
int myMonth;
int myDay;
then:
myDay = day()
….etc
I can print using > Serial.print(myDay);
But I cannot use:
String completeDate = String(myYear) + ‘-’ + String(myMonth) + ‘-’ + String(myDay) + ‘\t’ + String(myHour) + ‘:’ + String(myMinute) + ‘:’ + String(mySecond);
Serial.println(completeDate);
This, however, looks a lot like your code for this example (see line 112 in datalogger.pde)
Thanks in advance for any advice!
December 13, 2012 at 12:07 pm
Hi Jeremy,
Nice tutorial, thank you. I’m wondering if it is possible to access the SD card via the Serial port?… so lets say we have a closed data logger box with simply a serial port connector on the side – could we send a command to Arduino via Serial eg ‘R’ (for Retrieve) and Arduino would respond be sending the SD card contents down the Serial port? I guess it would need some sort of VB app or similar to re-assemble the data into a file?…. hmmmm would be great but I expect its complicated :-)
December 18, 2012 at 1:14 pm
Yes, you could do something like that. The arduino would wait for a command on the UART, and based on that command, it would send a command via SPI to the SD card, read data out into its RAM, then send it back over Serial.
December 28, 2012 at 7:54 pm
Hi Jeremy, thanks a lot for all tutorials. They help me a lot.
I did find lots of tutorials about how to make a Datalogger, but normally the data is managed in the computer.
I’m with a problem when I need to manage data from a CSV file in the arduino.
Basically, it has three columns and I need to compare data that came thru the GPRS module with the first field of the CSV file.
Do you have anything like this to show me or have some clues about it?
Again, thank you very much a a very good new year.
Joselio
January 3, 2013 at 8:01 pm
massive thanks for the tutorials they’ve been a really helpful.
is there anyway of increasing the a value of the .csv file each time the power is applied and remove to the arduino? for example,
log1.csv
log2.csv
log3.csv
etc
to record multiple sessions?
Thanks Sean
January 4, 2013 at 3:46 pm
You could store the previous number in EEPROM and increment it each time.
January 16, 2013 at 11:29 am
Hello, Jeremy.
hi im beginner in arduino. this is nice blog and nice tutorial….How does the program when the data logger was given RTC DS1307??
is too complicated??
February 4, 2013 at 9:33 am
i want to know if gps data logger can be done with basic arduino uno itself instead of gng for rev2 or rev3 please help me asap
February 5, 2013 at 5:43 pm
yes
February 22, 2013 at 10:04 am
Thanks for the tutorial, if you were to use a Leonardo would you just need the SD Card holder and the resistors to set this up on your own prototype board as it has a 3.3V regulated supply?
February 27, 2013 at 11:00 pm
You still need to shift the level of the SPI communication
March 11, 2013 at 5:46 am
well jeremy can you mail me the schematic of the sensor circuit with sd card and all that
March 11, 2013 at 2:43 pm
It is available for download above.
March 14, 2013 at 9:45 am
Hi Jeremy…
Is it necessary to convert the the value into ASCII format before writing it to the SD card for Datalogger,
March 15, 2013 at 7:22 pm
Hello i have a arduino mega 2560 and the same sd module. SCK–>52 , MISO–>50 , MOSI–>51 , SS–>53 , GND–>GND , 3.3–>3.3. 2gb micro sd FAT16 formated(windows 7). i cant accsess the card. I get Card Failure error. Do you have some suggestions ? Thank you in advance
March 16, 2013 at 3:36 am
Is it possible to record the data, for example light data, in SI units? And how?
March 16, 2013 at 6:58 pm
Hey Jeremy, great tutorial as usual!
Quick question, I was successively able to get the SD_write & the SD_read_write sketches to run with no problems or errors. However, with the datalogger sketch, the Arduino will only write about 4-5 iterations in the CSV file, and then stop, usually with random symbols entered in the data fields. I have troubleshooted as much as I can to my ability, and can not seem to fix the error. Any suggestions?
Thanks in advance!
Mike
March 18, 2013 at 2:15 am
Have you tried running the SPI communication at a lower speed? http://arduino.cc/en/Reference/SPISetClockDivider
March 19, 2013 at 8:14 pm
Hi, Jeremy, I tried adjusting the SPI clock speed using SPI.setClockDivider() command, and tried all values 2-128, and am still having errors. At one point I got about 16 itterations, but their it errored out and stopped recording.
Do you have any other suggestions?!
March 20, 2013 at 9:11 am
Have you tried a different SD card?
March 20, 2013 at 11:52 am
Hi Jeremy, thanks again for the reply.
Yes, I have tried multiple micro-SD cards. I originally started with the 2gb card that came with the card reader shield , and I also tried another 1gb SD card that I had laying around. I formatted them both to FAT16 format, using Windows 7. I also tried formatting them to FAT32, but made no difference and I re-formatted them back to FAT16. As I mentioned earlier, I had absolutely no problems with the SD_Read_Write sketch, and was able to successfully write and read to the .txt file with no problems at all, both saving it to the file and having it display in real time in the serial monitor.
March 20, 2013 at 3:35 pm
What kind of delay are you using between writes? You may be writing too frequently.
March 23, 2013 at 1:52 am
Hi Jeremy, sorry for the delayed response.
My initial delay between writes was what you suggested in the tutorial, once every second. I have tried different timings; every 2 seconds, every 500ms, and the most successful write was at 250ms, which gave me about 20 iterations, and then stopped. As odd at it seemed, the most successful writes were at the fastest delay timing. Like I said, I have tried everything I could to my ability to troubleshoot. I’m wondering if it has something to do with the latest version of the Arduino software..? Just for kicks, have you tried uploading your code recently with the latest software version?
March 28, 2013 at 2:14 pm
I haven’t maybe you can download an old version of the IDE and try it? I know other people have run this successfully with Arduino 1.0+, so I doubt that is the problem.
April 8, 2013 at 8:10 pm
Ok, I looked into this a bit more. I suspect you are running out of RAM. If you are using Serial in your program, remove all calls to Serial.print or Serial.println (they are for debugging anyways).
Odds are good that the literal strings within those calls are using up all your RAM and causing your problems.
March 20, 2013 at 2:36 pm
hi jeremy
very good tutorial.
i am attempting a data logging project but am very stuck with extracting data from the sd card and using it in an arduino sketch. i have a csv file with various types of data, eg 1,2,30,kitchen,0,0,
im trying to read this whole line from the file on the sd card to a buffer so i can split the data but i cannot work out how to read from the card.
any help would be much apreciated.
thanks alot sammy
March 22, 2013 at 1:03 pm
Hi, I am having the same problem, I bought the openlog and I haven’t been able to use it. First how do we connect it to arduino Uno so that I can make it to create a csv file and then every 3 or 4 minutes add the data from some sensors to the file? I have searched the web but I haven’t found a solution.
April 2, 2013 at 2:31 am
Hi jeremy
I would like to know how to use the Arduno Uno bord with Seeedstudio SD Card Shield V.3.0, Please can you help me ?
** about – some source code and the example to connecting the bord with analog sensor
thank you
Mr.Nattachai
April 5, 2013 at 11:45 am
Hi jeremy,
I tried SD_WRITE example you’ve given. It works fine in the serial monitor and prints ‘ hello ‘ every 5 secs.
Then I ‘ reset ‘ the arduino and then removed the power of arduino and then I removed the SD CARD and put that in my windows 7 pc.
In my computer the SD CARD shows a weird name with strange symbols ( SD card name I first used as SD CARD, but it has been replaced with some meaning less charactrs ).
And then I opened the sd card . Unfortunately there are number of files with more weird names ( nothing can be understood . even those charactors are not in the key board to type ) .
So I tried to open all of them but ended up with windows errors .
Any solution ?
Thanks.
Shanuka.
April 27, 2013 at 5:06 pm
Did you make sure to format the card first?
April 6, 2013 at 7:32 am
Jeremy,
I also have another problem.
In my project datalogger ( using SD card ) is a one part.
I also have a LCD display connected which shows the values ( that are to be logged into a card ).
My problem is, LiquidCrystal.h library uses PINs as follow,
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
And also the SD CARD module also uses some of those mentioned pins ( 11,12 ).
I think we cant change what’s written in the library.
So what would be the solution.
Many Thanks.
Dileesha.
April 8, 2013 at 9:36 am
dear jeremy,
im using an arduino mega board to do this sd card logging thing,, but it always says that “sd card invalid”…….
i plugged into the arduino mega 2560 digital pin 8-13 and the ground this cool hacks sd card shield for arduino…..
please help me with this thing……
loking for help asap, because this is based on my final year project..
April 11, 2013 at 3:57 am
Hi mate,
for someone so young you are a clever dude who really understands electronics and embedded programming. Thank you for these tutorials.
April 11, 2013 at 10:49 am
hi Jeremy, i have more sensors, this sensor send states to a csv file into sd card build on ethernet shield.
now i want see this states in real time and i want to save the csv file on my remote pc.
the first point was made but the second no.
how i can do it?
tnx
April 27, 2013 at 5:11 pm
Consider using a service like cosm.com
April 18, 2013 at 1:05 am
hey Jeremy, thanks for the tutorial can you please post where i can get arduino chip and which specific one you used. can you also post a link to the data sheet
thanks
Frankie
Pingback: Tutorials for Arduino Getting Acquainted with Arduino - Arduino for ProjectsArduino for Projects
May 9, 2013 at 8:40 pm
Hi Jeremy
Thank you for the tutorials.
I am trying to build a datalogger than can sample up to a 600kHz sine wave and store the data onto a csv file; similar to what you did in your tutorial but much more demanding on the microcontroller.
After several days of trials, I am beginning to think that the Arduino is not up to the task; I am trying for a 9.6kHz sampling frequency, but I think the bottle neck is really the speed at which data can be logged onto the SD chip.
Do you have any suggestions? Should I look for a different board?
May 9, 2013 at 8:44 pm
oops, I meant to say 600Hz, not 600kHz.
Pingback: Arduino RFID Card Reading -Arduino for Projects
Pingback: Arduino SD Cards and Datalogging -Arduino for Projects