Introduction: Arduino GPS Datalogger

Picture of Arduino GPS Datalogger

Do you want to log some GPS data onto an SD card using your Arduino? Do you already own a Sparkfun microSD shield and GPS module? Did you try the Adafruit Sheild (although it is awesome and cheap) but it stole all of your pins? Want it to output into a nice, Google Earth friendly format? Well read on...

Step 1: The Hardware

Picture of The Hardware

You will need:
1. An Arduino (which ever you prefer. I stick to the uno, duemilanove, mega, and this bad boy )
2. A GPS module (I'm using the EM-406 from Sparkfun )
3. A matching way to hook the GPS module to the Arduino (I went with Sparkfun's GPS Shield )
4. And a microSD Sheild (Again from Sparkfun )

Some optional stuff:
5. Indicator LED (ok ok I won't force Sparkfun on you for this guy)
6. A nice hard weatherproof case (I used the Pelican 1010 which fit perfectly)
7. Battery (No point logging GPS data tethered to your computer)

Step 2: Hook It All Up

Picture of Hook It All Up

It's a simple as, stacking the sheilds.
I put the GPS Shield on top to maximize reception.
The led is on pin 13 (see close up pic). This will flash every time it logs a GPS point.

To work with my code, make sure the little switch is set to "DLINE" on the GPS Shield. (Included a close up if you have no idea what I'm talking about) This is so we can use pins 2 and 3 to communicate with the GPS instead of the "UART" setting, which uses pins 0 and 1. This is a personal preference, modify the code as you wish. If you are using the UART, then make to switch it over to DLINE while uploading code to the Arduino if the shield is attached.

Lastly remember to have your microSD card formatted to FAT (FAT16).

Sparkfun (and many others!) has some awesome tutorials on the product pages that I referenced in this Instructable's Hardware page for both of the shields. I'd highly recommend a glance through them if this is a little too confusing. (Especially the microSD tutorial!!!!!)

Step 3: The Software

Picture of The Software

I'm assuming if you've read this far you know a bit about the Arduino and how to upload programs using the Arduino IDE, so I will not be covering the basics. Lets walk through some sudo-code

initialize serial, libraries and variables.
create a text file on SD card with header
pull GPS data
write GPS data in the end of the text file.
flash led
keep looping

I'm not going to go into my code in to much detail but it's commented enough to understand whats happening.
You will notice I'm using two really awesome libraries written by Mikal Hart, so make sure you have downloaded them! (TinyGPS and NewSoftSerial )
TinyGPS basically makes it easier for us to extract data like longitude and latitude from the slightly complex NMEA sentences that the GPS module spits out.
NewSoftSerial allows us to transform any pins into "serial pins". In this case pins 2 and 3 as previously mentioned.

The Arduino file is attached.
Just upload and it should work! (Leave a comment with the issue if it's not)

Step 4: Great We Are Logging... Now What?

Picture of Great We Are Logging... Now What?

So as of now, you are logging all of the gps data onto a text file named trip.txt in the root of your sd card. If you disconnect power, then reconnect, it will just append the new data to the end of that file.
You are more than welcome to write some code that reads the SD card and says: "if the file exist, make a new one with a different name." You could even get creative and use the date and time from the GPS in the filename.
The possibilities are endless. I'm just doing some basics as a proof of concept.

So it outputs a text file with a heading and the data that looks something like this:

Now you can use an awesome tool over at to create a Google Earth File with the points and their data at each.
Change the settings to your liking and use upload or copy paste.
Its as simple as that.
The picture is an output from the data above.

Step 5: The Side Note

Picture of The Side Note

This is my first Instructable so please play nice.
This is simply a start in the right direction for a full on data logger.
In no way did I optimize my code or hardware to be as efficient as possible.
It doesn't take things like file size or bad gps data into account.
Unplugging the power could even corrupt the SD card. Easily fixed with a button and some start-stop code.

It simply says, "if there is a gps module attached, I will log whatever it gives me"

And that's it! Feel free to ask questions and I'll do my best to answer them and have fun!!!!
Post your projects in the comments if you use this, I'd love to see what you guys are doing!

-----------------------------UPDATE 10/10/12-----------------------------
Hey guys, I'm sorry to say, this project has been discontinued for now. It has been almost a year since I published this. I haven't had much time to update and fix the bugs in the code, however it should still be compatible with older versions of the Arduino IDE and libraries. Next project that I use the sd shield for I will come back and give this another update, but for now work and school are cutting into my project time.
Thanks for your support!


David_Dragino (author)2016-07-04

Hi,guys ,
There is a cheap and powerful GPS expansion board here:

spetyo (author)2016-06-17

help a video

ThreephanK made it! (author)2016-04-12

Hi, friends! Here is my article about creating the same device - (in russian).

echovoice (author)2011-10-18

nice tutorial, thanks for the code... works perfectly!

CarmenS1 (author)echovoice2014-09-02

Where did you find the code???
Could you send it to me please? I can't find it anywhere here!

PraveenkumarS (author)2015-05-04

Hello I am using Jupiter 610F GPS module and there are 10 pin setup in that and the use of Vcc ground and the Output for the GPS module pin is known and what about the remaining pins and there is pin called antenna power pin should i need to give any voltage to that if so whats the value and if possible let me know with the configuration of the pin connections

electron2709 (author)2013-10-25

Can you help me with this error?

#error NewSoftSerial has been moved into the Arduino core as of version 1.0. Use SoftwareSerial instead.
In file included from GpsDataLoggerInstructable.pde:11:

hheidmann (author)electron27092015-04-01

There was a period of time where you needed to manually install NewSoftSerial yourself, but if you keep your Arduino IDE up to date then you already have NewSoftSerial installed as SoftwareSerial. Basically they caught on that it was a better version and replaced the old one to make it the new standard Software Serial library.

Paulo Coutinho (author)2014-12-31

Nice tutorial, I would like to talk to you if possible.

handsup9987 (author)2014-08-27


I'm trying to compile the code, but it does not work. I downloaded the sdfat and TinyGPS to the library.

In file included from sketch_aug27a.ino:15:

C:\Users\Y510P\Documents\Arduino\libraries\SdFat2/SdFat.h:294: error: conflicting return type specified for 'virtual void SdFile::write(uint8_t)'

D:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

Valber Senna (author)2014-01-25

where is the code?

electron2709 (author)2013-09-14

sir...wat arduino software are you using? thnk u

jonnyboy323 (author)electron27092013-09-14

Check out step 1!

electron2709 (author)jonnyboy3232013-09-16

are you selling this?

adham rabea (author)2012-10-07

can u upload the full software plz

jonnyboy323 (author)adham rabea2012-10-10

Not sure what you mean by "full software" but I just zipped the file to fix that download issue that people have been having. I added an update to the end of the Instructable too.

dsp9753 (author)2012-07-22

Hi Jonny,

I am using your code but it is not printing any values to sd card. Do you know what might be the issue? it creates the text file and adds in "year,month,day,hour,minute,seconds,latitude,longitude,altitude(ft),speed(mph),course" but it does not actually print any values from the gps. The text file is blank besides that one line.

jonnyboy323 (author)dsp97532012-07-26

Hmmm I am not to sure. The bulk of the problems usually come from actually writing to the card. Try printing some of the gps values to the serial port and see if you can see them. If you can then I would say the issue lies in the code where it is compiling that string of all the values. I will admit that this code is very old and probably not compatible with Arduino 1.0. I already owe Rustie0125 some new code from almost 4 months ago now... I can see what I can do and try to release version 2.0

keihisazumi (author)jonnyboy3232012-08-20

I also find same issue.
but, by changing as described below, I was successful.
NewSoftSerial nss(3, 2);
NewSoftSerial nss(0, 1);

mrdakota (author)2011-12-10

Great job on the Instructable!
For a first time, it was well constructed.
Now for my problem,
I'm not getting the log file header unless I have the Arduino connected to my computer USB and it is not logging any gps data.
The only thing I have different is the SD card shield, I'm using the Arduino wireless SD shield.
At first I tried editing the SdFatConfig.h file to change the CS pin from 10 to 4 for my SD shield and that didn't work.
So I changed it back to pin 10 and modified the shield, ( cut the copper trace from pin 4 and connected it to the unused pin 10) still no luck.....
I really looking forward to getting this to work.

mrdakota (author)mrdakota2011-12-10

Well by mistake , I installed a different micro SD card and it works PNY instead of SanDisk.
But still it doesn't work off the power plug only off the USB. I'm puzzled!

mrdakota (author)mrdakota2011-12-10

My-BAD- again! It turns out my battery(5v) wasn't enough.
Everything is fine now with a 7.4v Li-Po
Hope this helps someone else in the future!

jonnyboy323 (author)mrdakota2012-03-28

Sorry this is so late but for some reason I didn't even see your post until now...
Thanks for the info and for trying out my instructable!!!!!
I didn't even know that Wireless SD Shield existed, its pretty cool.
In fact, you have stirred up an old project that I have had in mind for a while now :)
Anyways I''m glad you got this all figured out..


Rustie0125 (author)jonnyboy3232012-03-31

HI Jonny any News on the Accuracy problem in the code? , im buring to get this working

jonnyboy323 (author)Rustie01252012-04-01

Well just spent the last 4 hours working with my brother trying to get this to work. We ended up essentially re-writing the code. There are still a few strange little things that I'll make comments on in hope someone optimizes it, but once I clean up the code I'll post it and update the instructable.

Thanks for your patience.

Rustie0125 (author)jonnyboy3232012-04-09

HI Jonny any news ?

Rustie0125 (author)2012-03-26

Hi Thank you for sharing your hard work .! i have all the components but non is on the shields they all stand alone breakout boards. when i try and compile your code it gives me Alot of errors can you help ? mainly ones of missing Files or libraries can you please maybe add the links to all libraries needed


jonnyboy323 (author)Rustie01252012-03-28

Thanks for giving my instructable a try. I'll do my best to help you, just let me know after this if anything else isn't clear and I'll got back and update the steps. It is possible the libraries have updated and no longer compatible with my code. I'll have to start from scratch and test it.

But for now, I'll take these problems 1 at a time.
First off, what hardware/breakout boards are you using?

Second: Libraries....
Which libraries do the errors seem to be referring to?
You will need the NewSoftSerial and TinyGPS (links in step 3).
You will also need the SdFat library.
You can get this here:
While you are there PLEASE read the tutorial. I had a terrible time getting that shield working. Then of course after my struggle they seem to launch a tutorial.... It is extremely helpful. (especially when you start getting into some of the harder stuff like writing/reading data to/from the sd card.
Make sure all of these libraries are extracted in the libraries folder of Arduino.

Now onto the hardware.
The first thing I would do is make sure all of your components work individually. There are thousands of arduino tutorials out there. Once you are sure each one works, you can then use use the working code you have found and compare it to what I am doing here (and hopefully modify it to fit your needs!!!!) That is essentially what I did for this project. Just google everything (including the errors) and keep trying until things begin to work.

Lastly pins:
This is a chopped up quote from the sparkfun microSD tutorial I mentioned above. Its about 3/4 of the way down under the section labeled "I downloaded a FAT library for Arduino on my own from the Web but it's not working! Why not?"

"On Arduino, the default pins are D10 (CS), D11, (MOSI), D12 (MISO) and D13 (SCK). The microSD shield, however, uses pin D8 for the CS signal. If this is left unchanged, the library will not work. You'll need to read your libraries documentation to find out where the signals are defined and change the definition accordingly. For example, in the SdFat library the definition is located in the file named 'ArduinoPins.h' and to change the signal on line number 518 from: #define SS_PIN 10 to #define SS_PIN 8"

If the issue is with the gps module, then the look at this line in my code:
NewSoftSerial nss(3, 2); Look at the documentation on NewSoftSerial. I cant remember off the top of my head which is which but for the gps shield it has the option to change the tx/rx pins from 0 and 1 (which are the arduinos tx/rx pins) and 2 and 3 with a little switch. Just adjust the numbers to whatever pins you are using. If it doesn't work, try flipping them. That is one problem that I know I ran into.

Whew that was a lot. Hopefully thats enough to give you a push in the right direct. Just post anything else that comes up and I'll dig out this project to test these things. Please post your results either way!

Thanks again.

Rustie0125 (author)jonnyboy3232012-03-28

Hi Johnny

I got it to work thank you , I wantted to ask if you were aware that your GPS readings is very inaccurate . Iv done some research and it seems where the problem is is where you convert the output to int. instead of keeping them as is and saving them like that . I have media tek gps and the best accuracy I get when using your code is +- 10km range but when using a GPS example from Arduino I get 3 foot accuracy .

Is there a way you code step away from converting the output to int? And just print them as floats . ? Iv tried but I can get it working then

Thanx for the post very helpfull

jonnyboy323 (author)Rustie01252012-03-28

It's funny you mention that. I had never actually used this project to track something. But about a month after I made this instructable I decided to take it camping with me to give it a test. When I got home and uploaded the data it was really far off. I figured it was just a fluke, because when I tested the code before, it was right on (or so I thought.....). Anyways thank you for pointing out that bug. I'll have to look at it later on this week and see what I can do and re-upload the code.


Rustie0125 (author)jonnyboy3232012-03-28

Hi Jonny

Looking forward to your fix , I'm buzy with same setup . Please let me know if you got it fixed .

Rustie0125 (author)2012-03-26

Also something else that I cant get from looking at the code is where or what pins is the Sd card attached to?

manashraja (author)2011-11-07

Sir, excuse me. The link you have provided is making me download "FADFMAUGTW2B6VB.tmp". I am not getting the required "GPSDataLoggerInstructable.pde" file.

jonnyboy323 (author)manashraja2011-11-07

That's very strange, the link used to work, but I see what you are talking about.
I tried re-uploading but it is still showing up as a .tmp file.

I do have 2 solutions for you however for now, until a moderator gets back to me:
1. Try a different browser. When I tried Internet Explorer it opened as a link and the full text showed. Simple Copy/Paste.
2. Change the filetype to .pde instead of .tmp and it opens just fine.

Thanks for your interest and sorry for the slight incontinence for now!

mikeasaurus (author)2011-10-19

great project!

About This Instructable




More by jonnyboy323:Arduino GPS Datalogger
Add instructable to: