Tutorial 15 for Arduino: GPS Tracking


This tutorial was featured on the Cooking-Hacks website on 07/18/2012

This was easily the most time I’ve spent producing an Arduino Tutorial. I’ve been sporadically walking around NYC with this GPS for weeks as I’ve tweaked the code and gotten it just right. If it wasn’t obvious from the title, this tutorial will teach you how to use an arduino paired with a GPS Module and an SD Card Module to log your latitude and longitude over the course of a day. As a bonus, I’ll also show you how to easily overlay this data onto a map using services like Google Earth and Google Fusion Tables. I added a short “history lesson” to this episode to explain how GPS came to be; it’s the first time I’ve done that, so please let me know if you like the extra knowledge. Grab some popcorn and your Arduino, because this tutorial is pretty long – GPS is complicated! The schematics, programs, parts list, sample data, and important links are available for download below.

I used the tinyGPS library to decode the NMEA GPS Data. Cooking-Hacks generously supplied both the GPS shield and SD Card shield that I used in this tutorial.

You can download the files associated with this episode here: Arduino Tutorial 15 Files

Source materials for all my arduino tutorials can be found in my github repository.
GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.

This video can also be viewed at


  1. Hi
    I have
    1. An Arduino
    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

    would what i have work with this code

  2. Hi, i was trying with your code for GPS shield, but i got all this errors: I’m using Arduino 1.6.1 compiler, can you help me?

    GPS_cesar.ino: In function ‘void loop()’:
    GPS_cesar.ino:38:17: error: ‘class TinyGPS’ has no member named ‘satellites’
    GPS_cesar.ino:38:31: error: ‘GPS_INVALID_SATELLITES’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:39:17: error: ‘class TinyGPS’ has no member named ‘hdop’
    GPS_cesar.ino:39:25: error: ‘GPS_INVALID_HDOP’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:41:21: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:42:21: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:45:33: error: ‘GPS_INVALID_F_ALTITUDE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:46:31: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:47:35: error: ‘GPS_INVALID_F_SPEED’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:48:31: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:48:71: error: ‘cardinal’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:49:21: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:49:80: error: ‘distance_between’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:50:23: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:50:54: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:50:85: error: ‘course_to’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:50:141: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:51:21: error: ‘GPS_INVALID_F_ANGLE’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:51:61: error: ‘cardinal’ is not a member of ‘TinyGPS’
    GPS_cesar.ino:51:79: error: ‘course_to’ is not a member of ‘TinyGPS’
    Error compiling.

  3. Hi, Thank you very much for posting this, I managed to get it working but for some reason the SD part does not work, I keep getting the error below even thought the CSV file is on the SD card . please help me, i need urgently help, doing this for my university project

    Couldn’t open the log file!
    Card Failure

  4. i got the latitude and longitude but cant log the data in sd card.
    couldn’t open the log file
    help me plzzz

  5. Thanks for sharing this, I have plan with my GPS project module. this is really help!

  6. GPS_EM-406A is need any sim and gsm module

  7. I could not get the test_with_gps_device code to work. I am also using a mega 2560 and set it up as per your instructions. I get the same readings you got in the video on the serial monitor, but I shouldn’t because the module has a gps fix. I verified it with adafruit’s parsing code prior to uploading the test_with_gps_device sketch. The module (an adafruit ultimate gps breakout) also has an led indicating that it has established a fix. Any ideas on what might be preventing the serial monitor from displaying the data?

  8. Hello, hi jeremy….
    Nice job!!!
    Hey I am working on gps REB 4216. previously I tried with following code and I am getting the result as
    this data is correct but I am not able to decode it even after using .csv format.
    I found tha u did a great job as getting prety tabular formatfor the parameters latitude and longitude.
    With your code I am just geting invalid data string..:(
    Please help!!!
    Thank you!!

  9. Is there any sd card module for arduino leonardo ?

  10. You make great tutorial, but I’m not English speaking person, so for my is hard understand yours fast talk. And, can you make sketch of this devise connections, I can’t understand, what cable where have to go. Thanks

  11. Please Help
    I am trying to track the GPS but i am not able to receive my longitude and latitude data.
    I am using “Adafruit Ultimate GPS Breakout V3” GPS module and “Arduino UNO R3”

    Here is my code. I have tried both

    :::First Code:::

    long flat, flon;

    SoftwareSerial gpsSerial(2, 3); // Create GPS pin connection
    TinyGPS gps;

    void setup(){
    Serial.begin(9600); // connection serial
    gpsSerial.begin(9600); // gps burd rate

    void loop(){
    while(gpsSerial.available()){ // check for gps data
    if(gps.encode({ // encode gps data
    gps.get_position(&flat, &flon); // get lattitude and longitude
    // display position
    Serial.print(“Position: “);
    Serial.print(“lat: “);Serial.println(flat);
    Serial.print(“lon: “);Serial.println(flon);

    :::Second Code:::
    #define RXPin 3
    #define TXPin 4
    #define GPSBaud 9600
    #define ConsoleBaud 115200

    // The serial connection to the GPS device
    SoftwareSerial ss(RXPin, TXPin);

    // The TinyGPS++ object
    TinyGPSPlus gps;

    void setup()

    Serial.println(“GPS Example 2”);
    Serial.println(“A simple tracker using TinyGPS++.”);

    void loop()
    // If any characters have arrived from the GPS,
    // send them to the TinyGPS++ object
    while (ss.available() > 0)

    // Let’s display the new location and altitude
    // whenever either of them have been updated.
    if (gps.location.isUpdated() || gps.altitude.isUpdated())
    Serial.print(“Location: “);
    Serial.print(, 6);
    Serial.print(gps.location.lng(), 6);
    Serial.print(” Altitude: “);

  12. Hi jeremy
    Im not very good in english.
    I have some problem with my board is 2560.i tested your third tutorial.when i defined a port as input it gets high voltage when i bring my fingers near it.plz help

  13. Can u please explain each of the data being displayed. I am doing a project on it and I need to filter the unwanted data, to avoid stack overflow. Could you please help me out? I am using it in a drone project and i need the latitude, longitude, altitude, speed, distance to target and heading angle.

  14. hey…. i hav a project to log the gps data in any database or cloud storage… can u help me with the codings… my gps program worked wonderfully bt now the database is a issue.. can u suggest me some links fr the codings… please….

  15. And i want to the storage without using any wifi or ethernet shield…. and i hav device such as gsm sim900a mogule, gps module and arduino… please provide some help asap….

    • Hi Pratiksha

      I am doing a similar thing for a student. May be this could help you. Can you ping me with your code and I can include the database part to jmkrecruitments (at) gmail (dot) com

  16. hi
    ı want to make a android project with ardiuno gps module . project is vehicle tracking system.
    ı dont know How do I connect the arduino and android ?
    please help me

  17. Hi!

    I would like to ask some help.

    I have an Arduino Mega 2560, I bought it from the ebay, about 5-6 years ago, but I never used it before. I borrowed from a friend of mine an Arduino Uno+ made by Hobbycomponents, and I can upload the sketches to the Uno+, but the Mega always throws programmer timeout error.

    I tried it on three several computers (Win 7 ultimate 64bit, with arduino 1.6.9, Win7 enterprise 32bit, with arduino 1.0.5, 1.6.10, and 1.0.0, and Win XP SP3 with arduino 1.6.10), and I get the same errors.

    I tried to google it, but I found nothing useful information, I didn’t use in the code “!!!”, or something similar errors, the sketch runs on the Uno+, but instable, uses cc 88% of the memory.

    Could you help me, how can I fix it?
    Can be originally damaged a brand new Arduino Mega?
    When I bought it, a friend of mine bought another Mega 2560, from the same seller on ebay, and that one works fine.

    Thank you for your help.

  18. Hi
    I’m using a Ublox NEO-6M GPS Module Aircraft Flight Controller according do your tutorial. But it gets a wrong time value. There is no problem with date, latitude and longitude. Any suggestions?
    thank you!

Leave a Reply

Required fields are marked *.