BLOG > 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 (NOTE: Fusion Tables is being phased out by Google, so I recommend against using it – Edit from February 2019). 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 element14.com.

250 comments

  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

    1. Hey, how are I see that you got the code to work. Unfortunately I couldn’t. Did you have to make any adjustments?

  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. 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?

  6. 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
    ……………………………………………………………………………………………………………………….
    “$GPGGA,030940.000,2446.5775,N,12102.6593,E,1,11,0.7,136.3,M,15.1,M,,0000*5A”
    “$GPGSA,M,3,19,04,11,27,07,16,01,09,23,26,30,,1.5,0.7,1.3*38”
    “$GPGSV,3,1,12,19,69,346,37,04,48,162,25,11,47,199,24,27,41,029,34*78”
    “$GPGSV,3,2,12,07,38,320,40,16,30,067,35,01,27,184,21,09,27,252,23*73”
    “$GPGSV,3,3,12,23,23,212,25,26,11,089,25,30,08,320,26,08,52,020,34*7A”
    “$GPRMC,030940.000,A,2446.5775,N,12102.6593,E,0.00,295.95,270715,,,A*69”
    “$GPGGA,030941.000,2446.5775,N,12102.6593,”
    …………………………………………………………………………………………………………………………………..
    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!!

  7. 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

  8. 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:::
    #include
    #include

    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(gpsSerial.read())){ // 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:::
    #include
    #include
    #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.begin(ConsoleBaud);
    ss.begin(GPSBaud);

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

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

    // 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(gps.location.lat(), 6);
    Serial.print(“,”);
    Serial.print(gps.location.lng(), 6);
    Serial.print(” Altitude: “);
    Serial.println(gps.altitude.meters());
    }
    }

  9. Hi jeremy
    Im not very good in english.
    I have some problem with my board.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
    Thx

  10. 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.

  11. 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….

  12. 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….

    1. 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

  13. 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

  14. 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.

  15. 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!

  16. Hi,
    Will this code work for Arduino Uno?
    I don’t have a sd card, but I have a transceiver. Is it possible to print gps data?

    thanks a lot!

    1. I tried this sketch on a CH340 based Uno compatible board, and it runs, but instable, so I think, you remove some functions from it, it could be useful, and stable.

      I used a Beitian BN-880 GPS receiver, and this receiver does not support the 10Hz refresh rate for the GPS information, I used it on 4Hz with the Mega2560 R3 board (the whole sketch with my functions and features runs cc 250ms, so I could not use it on 5Hz)

  17. hello Jeremy :) i have the globalsat EB 5365 RE gps shield , with an arduino uno , and i cant make it happen to work with the tinygps libraries , you have any recommendations how to make it work ?

  18. To all of the commentators above ….have you got any replies from Jeremy?
    Its pitiful that these queries are valid yet no answers have been posted. Im posting obviously I dont want to ask the something thats already been asked.

  19. hey,

    I am trying to do the same project but instead of using SD card, can use phone for receiving GPS data.

    so any idea about the code to receive the gps data to a single phone number.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement