LESSON 22: Build an Arduino GPS Tracker

OK, it is time for us to take our projects up to that next level. We are going to build a GPS tracker from scratch. This is going to take several lessons to complete, but it will build on what you already know, and is really not going to be that difficult of a project. We will be using the most excellent Adafruit Ultimate GPS module. This is an excellent GPS. I like it because it is affordable, easy to use, and is one of the few that will work at extreme elevations, making it ideal for our Edge of Space/High Altitude Balloon work.

Arduino GPS
We are using the Adafruit Ultimate GPS

This unit is pretty easy to hook up, as you can see in the Table below:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS Pin Arduino Pin
Vin 5V
RX Pin 2
TX Pin 3

Our goal in this lesson is to get the GPS connected, and get it reading NMEA sentences. NMEA is a data format used by GPS and mapping devices and software to keep track of position coordinates. There are lots of different NMEA sentences, but the two that contain the most useful information are the $GPRMC and $GPGGA sentences.

Our interest is in creating a location tracker for our High Altitude Balloon work, and the $GPRMC and $GPGGA sentences contain all the information and data we would need for that work. These sentences contain the lattitude, longitude, time, altitude, and velocity.

The GPS modules are pretty easy to work with. When you apply power to the GPS, it immediately starts spitting out NMEA sentences to its serial port. Our job on the arduino side is to simply read these data strings, and then parse them into useful data. The thing that is a challenge is that they constantly spit out data, whether you want it, or whether you are ready for it or not. In developing the software, we have to be mindful the the data is always spewing out of the GPS. Typically, we will have other components on our package, like temperature, pressure and inertial sensors. While our arduino is out making measurements on these other sensors, data continues to stream in from the GPS, likely overflowing our serial buffer. When we return to make a GPS measurement, it is very likely that the serial buffer will have old or corrupt GPS data in it. Hence,  we must be mindful to deal with this issue in developing our software.

The video above takes you step-by-step through connecting and reading the NMEA sentences step-by-step. Then in the next lesson we will parse and log the data to create a portable GPS tracker. The code below is explained in the video. You need to watch the video to understand this code, and so you will be able to begin to work with this code to create a portable GPS tracker.

In order for this software to work, you need to download and install the Adafruit GPS Library.


82 thoughts on “LESSON 22: Build an Arduino GPS Tracker”

    1. It looks to me like you do not have your baud rate set the same on program and in serial monitor. Look for typos on baud rate.

      1. i have kind of the same problem:

        i copied your code an watched your video but my serial monitors doesnt do anything, i tried to set the monitor to 9600 and 115200 but it isn’t working

        note: i got the adafruit gps

      2. Hello Paul,

        I get have a similar problem. I used your code, but I don’t get consistent NMEA sentences. I only get 1 sentence, not an alternating pattern the way I should. Baud rates seem to match the code.

        I’m using and Arduino UNO v3, the ultimate Adafruit GPS, and they’re connected to my Macbook pro running OS X El Capitan.

        Any ideas?

        Thanks in advance!

    2. somebody help me ,i have neo 7m gps and 10 dof imu sensor b .,i want to tack location and angle position so how to do?pls

  1. I am using the GPS Holux GR-89 and want to know if this code can be used for this gps
    thank you

  2. I’m finding these tutorials quite useful. I’ve been playing with the Adafruit Ultimate GPS Logger to track our cruises.

    On this one you mention wanting to have the GPS work more in a client-server mode. Have you looked at calling the “c = GPS.read()” in a timer interrupt like Adafruit shows in their examples.

    This tutorial caused me to use my limited C knowledge to dive into their Adafruit_GPS library and it seems that they have designed it around using the timer interrupt.

    The library double buffers the NMEA sentences into two variables (line1, line2). When it senses the NL character for a sentence, it makes that line available as GPS.lastNEMA and starts buffering into the other line variable.

    It will keep doing this regardless of whether you check on or parse the data, it will just keep toggling between it’s two buffers. When you do get around to checking on it, it will always have the latest NMEA sentence available.

    The key is having the read command done in the interrupt that is firing off every milliseconds. This kicks the library to keep the serial buffer flushed out.

    I am a little troubled that they are using Timer 0. This is the one that is used by the Arduino for its various timing functions. There are three timers available and Arduino uses all of them for various things. You can use it but have to be careful. I’m assuming that the Adafruit staff that wrote the examples know more than I do, so I’m relying on them, but I haven’t had any problems yet.

    I’m combining the GPS logger with the Adafruit 10 DOF board now and will need to move from an UNO to a Mega because of the space taken up by all the libraries. The Mega has timers available that Arduino isn’t using, so I’ll probably switch to one of them to avoid any possible problems.

    Love your stuff.

    1. The adafruit example works as if the GPS is the only thing going on and sits and continuously makes measurements. For my application, I was more interested in having multiple sensors and devices, and only make a GPS measurement when the overall controlling system wants one. Hence, their free running interrupt driven approach was not a good match for my needs. It might be perfect for most people.

  3. Hello sir I have been following your tutorials from a month. Its really good and useful.

    Now I am working on a project on GPS tracking system its my academic project and I have to submit this in my college by this month. Now I am facing problem with GPS. I have purchased Neo-6M GPS module but in your tutorial it is adafruit so I am facing problem with library files. So can you please help me out with this. I am from a computer science background and i don’t have much knowledge on electronics.

    1. All the GPS are different. This tutorial will only be useful for the adafruit. See if you can get that one.

  4. Good day Sir,
    I already have the device and the Arduino, when I first run the software it really works. But when I plugged it again,no NMEA sentences appear. Can you help me?What should I do?
    Thank you so much.

  5. Hei Paul. I still got all NMEA Sentences even when i copie your code. ” GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);” has no reference for my gps. Can you help me how i can get only these two sentences ?

  6. Hi sir,
    I’m trying to get a GPS signal in my place and its working okay but we I’m moving to another place it gives me corrupted signal, I want to know what is the reasons for this corrupted signal.
    Thanks in advance my teacher

    1. Make sure the top of the GPS has good visibility to the clear sky. It must be able to find the satellites.

  7. Hi , I just want to know in which language the code is written for lesson 22 (Creating a GPS tracker)

  8. sir,
    i want to know how can i get data from neato lidar sensor in arduino mega and display in serial monitor.

  9. My code is down below, however I keep receiving the error message:
    ”readGPS’ was not declared in this scope”
    As far as I can tell, it is exactly as what is on your website. What do I need to do?


    SoftwareSerial mySerial(3,2);
    Adafruit_GPS GPS(&mySerial);

    String MMEA1;
    String MMEA2;
    char c;
    void setup() {
    GPS.begin(9600); //Turn on GPS to 9600 Baud


    void loop()


    void readGPS(); {

    while(!GPS.newNMEAreceived()) {
    c=GPS.read(); //read a character from the GPS

    void clearGPS() {
    while(!GPS.newNMEAreceived()) {


  10. Look at this line in your code:

    void readGPS(); {

    That Semicolon should not be there. No semicolon on function declarations.

  11. Dear Paul,

    thank you very much for your absolutely amazing tutorials! They are really motivating me to work with micro-controllers!

    At the moment I am trying to get my “Freeduino” (ATmega168, Arduino IDE 1.0.5) board to work together with the GPS module you suggested in tutorial 22.

    All the codework and upload is done. When checken the serial port via serial port monitor the following chars appear:

    Do you have any idea what I was doing wrong?

    Thank you very much for your help in advance!

    Best regards,

    1. Make sure the baud rate of your serial monitor is set the same as the baud rate in your program.

      1. Thank you very much for your fast reply.

        The baudrate is the same as in the code (9600).

        Also, it is confuisng for me, that if I connect the RX-Pin of my Freeduino to the TX-Pin of the GPS module the data streams to the monitor, But, if I connect the pins in the right order, there is nothing happening?

    1. Hi Jay,

      Did you ever figure out the issue? we’re having the same one. We’ve plugged in the GPS to the arduino correctly, and both boards are receiving power, but when trying to load and then run blank code just to see if the GPS was transmitting any data, but when we opened up the viewer it was blank (and we also tried changing the baud).

  12. Paul, what is your reccomendation for transmitting GPS data in a near space balloon so that we can follow it while it goes on it’s course? Do you have a reccomendation for a balloon release once it’s ruptured? (a way for the balloon to be released from the cargo once it’s exploded)

    1. Zachary, I can not give advice on an actual balloon flight. There are just way too many safety and legal issues for me to give engineering advice on something like that. On the radio communication, we use the Ubiquiti Bullet Radios. You have to be careful to use antenna and configuration that remains within FCC rules and laws. Also, the Ubiquiti radios will only track the balloon for part of the flight. Curve of the earth and overall distances involved, you will lose contact with the balloon. We use a spotgen tracker on the instrument package to tell us the final location of the landing. Also, you can use mini-APRS trackers if you have a HAM license. These will track usually to within the last few minutes of flight.

  13. Good morning Sir,
    first of all I’d like to thank you for your great work that inspired me for my thesis work. At the moment I’m parsing data from the Adafruit GPS with an Arduino Mega, but I think I will try to manage all this data with the BeagleBone Black because I need more computational resources and also beacause I’m interested in Python. However, I’ve tried your Arduino code and I was wandering why you need the function clear GPS (). You’re right when you say that the firsts NMEA data are corrupt, but it is a problem that goes away after few Serial prints. I’ve decided to delete this function because I think that when you see the sequence $RMC-$GGA instead of $GGA-$RMC you’re mixing data from different GPS data sets.

    Let me know what do you think and thanks again.

    1. Yes, if you continued to read the serial port in rapid succession, you would likely not have the problem. However, if your microprocessor is doing other things . . . maybe working with other sensors and devices, and only periodically coming for a GPS read, you would have the problem again. For my application, I have a lot of sensors, and just read the GPS when I need to. Hence, I wrote the software so that it would always return a good read, independent of the time delay between reads.

      1. Thanks for your reply Sir.
        I have another question for you. Adafruit Library reads data using interrupts which means that whatever Arduino is doing, when data arrive it stops any activity and parse that data ( if I’ve understood it well ). The question is: have you ever had any problem with this interrupts considering the other sensor that you have in your project ?

        1. I went through the code, but could not really understand exactly how that was doing the interrupts. Given that I want to have my arduino doing other things, and then just come and make a measurement when I wanted a data point, I did not want to do it with interupts.

  14. I understand your point and I think that I’ll follow your approach for the same reason. Thanks again for your time Sir.

  15. Good day sir.
    your previous tutorials really help us .
    we’re building our thesis with a lawnmower controlled by a gps
    and we got problem on how to send data via. google earth or map to our micro-controller arduino.
    can you help us sir.

  16. Howdy
    I like your Arduino GPs Locator. You say it good above 30000FT on a slow moving balloon. I need a GPS locator for a bird I an working on. The problem this bird will be traveling a super sonic speed. Of course when it appropriates apogee it will slow down to zero then increases as it free falls intil the chute opens.

    Which GPS unit should I use that will work in this involvement?

    Thank in advace 🙂
    Rocket Nut

    1. This is something you really have to check the laws in detail on. Fast and high at the same time can be a problem.

  17. Yes your right I can not fly here locally. I can at the anally event sponsored by Tripoli at Black Rock NV. At these event we have a FAA waver to 100,000FT. This is the only time and place I fly my bird.

    The bird I am working on is a 3 stage bird that;s predicted 80,000 FT apogee. So you can see I need GPS to recover the bird.

    Another problem is how to put GPS locator in each stage. I was going to use WIFI modules in each. Then using there MAC addresses I could track each stage. That was quickly becuase there is cell service at Black Rock. If you have any ideas on how to tack the stage I;m all ears.

    Rocket Nut

    1. My bad typing
      Bad text => That was quickly because there is cell service at Black Rock.

      Proper Text => That was quickly out the window because there is no cell service at Black Rock Dry Lake Bed.

  18. Thank you very much for taking the time to share this valuable information with us.
    I am using the nano, pins A2 and A3 , the code uploads properly, I did a verbose check and I have tx and rx from the adafruit ultimate gps connected to those two pins, set up my com port to 115200 bps and don’t get anything, I can see the red LED blinkin on the GPS telling me there is no fix so I think the GPS is working and should be spewing NMEA, what else can I check at this point to verify this further? maybe change it to port A4, A5 to find if the ports are working?

  19. Hi Sir,

    Firstly, I’ve really enjoyed listening to your tutorials and have learned so much, thank you

    Due to memory problems, i have gone from using an UNO to a Mega which provides more memory but now I’ve found, due to a process of elimiation, my GPS program wont run the void clearGPS () code. If I attach the GPS back to the UNO, it works.

    Do you know of anything i should add or delete for the code to run on the Mega?

    I’ve searched and only found codes that dont make use of an SD card. Please could you help



  20. Hi I have also had memory problems, although the sketch works very well. I am trying to convert to Mega , serial port 3. (14, 15).
    My changes to the sketch just don’t work. Other sketches I have managed to convert. Have you tried variations to the sketch for Mega ? Any help please as my 70 + year old brain is over heating
    All the best and thanks for all your hard work, the tutorials are magic.

  21. Hi,
    I am using the adafruit ultimate GPS logger shield and I am having serious trouble getting this code to work. I have tested the shield by uploading a blank sketch and the opening the serial monitor and that works i can see all the nmea sentences coming in. But once i begin to use the code and open the serial monitor I get nothing most of the time and occasionally i get a GGA and GSA sentence and that is it i was wondering if you would be able to help with this problem.

  22. Hi there .
    i have followed all the instructions but am facing one tiny problem .
    on my serial monitor i recieve $GPVTG and $GPGGA.
    I was supposed to get RMC and GGA from my gps .
    kindly guide me .

    1. Make sure you are sending the commands to the GPS to send only RMC and GGA sentences. If you have a typo in these setup commands, you will get the problem you are describing.

  23. I’d want to directly wire the GPS output to a bluetooth input which will be paired with an android smartphone. I think it’s simple, but I don’t know how to wire, specially because the bluetooth logic level works with 3.3V only. Can you help?

  24. Build it with a 3V3 generic GPS, attached to a TTL Level converter from 3V3 on GPS Tx port and 5V to Arduino Nano port 3 and works OK!

    The Tx from GPS goes to the #3 Digital IO on Arduino. Pay attention to this!

  25. Hi Sir need your help
    I have Adafruit GPS i followed your tutorial but the thing is i want to connect it with udoo neo for my college project The compilation of the code is successful but I doesnt get any output.

    this is my code

    Adafruit_GPS GPS(&Serial0);

    String NMEA1;
    String NMEA2;
    char c;

    void setup(){
    Serial.println(“Adafruit GPS library basic test!”);

    void loop(){



    void readGPS()



    Serial.println(“Adafruit GPS library basic test!”);


    I have done a change since udoo neo doesnt support SoftwareSerial so i added Adafruit_GPS GPS(&Serial0);
    but I am not getting any output could you help me. I have connected rx and tx pin to 0 and 1 respectively. I even tried with 2 and 3 but no output. Could you please help me.

    1. Did you install the library correctly? Is your arduino looking in that folder for libraries?

  26. i am using aurduino UNO , GPS SKG13BL receiver. Iam receiving this result when i load the coding. please help me to finish my project
















    1. It looks like you are properly getting the NMEA sentences, but you do not have a fix. YOu have to move outside so the GPS unit can have a clear view of the sky. Then your sentences should have data.

  27. Sir, I need a help ….
    now my problem is rectified, now iam receiving only RMC and GGA sentence .sir i want to know how to get only extract of latitude ,longitude and time

    1. You have to parse the NMEA sentences. I do this by passing them to Python, and doing the parsing there. Don’t I show this in the videos?

  28. Hello, Paul.
    I’ve been trying to use your code but when I try to upload it to the Arduino UNO it keeps telling me:

    “readGPS” was not declared in this scope.

    I’ve looked for semicolons ,which can’t be used on function declarations as you said earlier bur I haven’t found the mistake.
    I’d appreciate If you helped me.

    Thanks in advance.

    SoftwareSerial mySerial(3,2);
    Adafruit_GPS GPS(&mySerial);

    String NMEA1;
    String NMEA2;
    char c;

    void setup() {



    void loop() {



    void readGPS() (

    while(!GPS.newNMEAreceived()) (

    while(!GPS.newNMEAreceived()) (



  29. I am very interested in using the Adafruit Ultimate GPS Logger shield, product id 1272 for a high altitude balloon project. Before finding your excellent “lesson 22” I had reviewed the specs for the logger shield. On the datasheet web page for the logger they have a hot link labeled “Datasheet for the PA6H (MTK3339) GPS module itself”. The PA6H and MKT3339 are 2 different gps modules from 2 different companies. The PA6H datasheet says it is limited to 60k feet. The MKT3339 is silent on an altitude limit.

    I asked Adafruit on their Shields forum to explain why there are 2 chips mentioned, and if the shield has an altitude limit. Here’s their response…

    “We’ve asked the vendor to remove the altitude restriction and they say they have, but we don’t have the equipment to test the limit ourselves.

    Information from people who’ve tried using the modules for HAB systems have been mixed, some saying it works, others saying it cuts out at some multiple-of-1000m altiitude.

    That being the case, we can’t in good conscience promise that the units will work at high altitude. You’ll be better off working with a vendor that can guarantee their sensor’s high-altitude performance.”

    What gps chip is on your Ultimate GPS Breakout Version 3 shield (product ID 746) that you use for HAB projects?

    I have some HAB friends that use only Ublox gps chips. I found an Arduino shield with the Ublox chip here: http://www.ebay.com/itm/GPS-Shield-Ublox-NEO-Module-Sensor-for-Arduino-3-3V-5V-with-SD-Card-Slot-/281638590492?hash=item4192f7d81c:g:dLgAAOSwPhdVD8RW

    But (1) I’m not sure if I trust buying this on ebay, and (2) it is from china.

    Do you have any recommendations for what I should do? Thank you, again, for the lesson 22 video.

  30. Hello, Paul
    Your tutorials have been extremely helpful. I am thinking of now doing the same project on a raspberry pi . The raspberry pi has now analog input but I do not think it is necessary when using the adafruit gps. Is it possible to use it on the raspberry pi or am i mistaken. Do you have any experience with the adafruit gps module on the raspberry pi, and aware of any potential hiccups?

    1. Yes, I have made it work on the raspberry pi. The challenge is that the new Pi 3 operating system has bluetooth, and the bluetooth functionality has disabled the tx/rx needed by the gps. After several weeks of work, I found a work around and got it working, but to be honest, I do not remember how I solved it. Check the adafruit WEB site. earlier they indicated the adafruit GPS to not be compatible with the Pi 3. If this is still the case, I recommend not doing the project until they offer a canned solution. LIke I say, I do not remember how I fixed it, but remember it was painful.

  31. I have two Uno’s and two Mega’s. Your code works perfectly on the Uno, but does not display the serial information on the Mega as written. Anyone have any ideas why?

  32. Hello Paul,

    i followed your videos with much interest. Your videos are quite helpful 🙂

    Now i have to write a scientific paper about the usage of the gps shield (the adafruit ultimate gps breakout v3) with an arduino (i use the mega 2560) in math classes.

    I achieved to get the mikrocontroller working and everything is doing fine.

    My problem is, that i need some literature or a respectable internet source for all the commands that i am using (especially for the commands to address the gps shield).

    Unfortunately i didn’t find something like that so far, not even on the adafruit website.
    May you tell me where i can find such a respectable source?

    I’d appreciate some help.

    Thanks in advance

  33. For those NOT using the Adafruit Ultimate GPS module,

    If you are not receiving anything by plugging the TX pin of your device directly into the TX pin of the Arduino or if running the code results in a jumbled mess then it is possible that the NMEA stream from your device is inverted. (This happen when I tried to read data from a Garmin GPS)

    To fix this you can use an inverter to flip the signal or use an interrupt that outputs the opposite of the NMEA input to a different pin. A jumper can then be used to connect the inverted pin to the serial pin.

    Hope this helps

  34. sir, i have problem regarding the WiFi module(ESP8266)
    its creating the hot spot network but we are unable to join the WiFi as there is a problem in coding it’s giving me an library(actually functional ,memory error) error. in the header code of ardiuno.
    so, can u solve the problem .an GPS is working fine .
    kindly give me correct wifi coding for ardiuno uno r3 please its regarding our university project.
    thank u.

  35. Hi Sir,
    Very helpful tutorials, really enjoy. I am having a problem with this one though. As noticed previously with some other comments, I am experiencing the same issues with limiting the sentences. I have checked spelling errors and have even done the tutorials provided with the library but still getting all sentences on the serial monitor. I’m using a mega if that makes any difference.
    Thanks in advance

  36. hii paul i have done the coding according to the tutorial but getting only garbage values.i am not getting A and C values as u got.

  37. hello sir i was wondering if there s a way to integrate that arduino gps into an android app with google maps??thanks.

  38. is there a way to track in real time and send data to webserver ??? i want to build gps tracking system for buses .thanks

  39. hi sir,
    i have followed all the instructions but am facing one problem .
    I still got all NMEA Sentences even when i copie your code
    I was supposed to get RMC and GGA from my gps .how i can get only these two sentences?
    kindly guide me.

  40. how can i get only $GPRMC and $GPGGA NMEA sentences?
    my serial monitor :








  41. The GPS module was working when I brought it. After two months it gives some values but not the latitude, longitude, altitude . . .
    I am following your code and circuit. What should I do ?

    1. Are you sure you are getting a fix? Look at the NMEA sentence and see how many satellites you have.

  42. hello paul

    i’m in india, and that gps module is not there in india so i got the gps6mu2 and can u tell me how to use it


  43. Hello sir,
    I was wondering if you could help me. I am trying to add more parsed data types such as Speed, The date, and also the number of satelites. The one problem that I am continuously recieving though is an error. It states ‘readGPS was not declared in this scope.’ I was wondering if you could help me solve this.
    Thanks in advance.

  44. I am using a slightly different set up. It is an Adafruit UNO with a FONA cellular module.
    I am “tethering” the unit to my laptop (Adafruit UNO USB port to laptop, FONA microusb port to laptop usb port).
    That is how the PWR lights are on in the UNO and the FONA.
    It does pick up GPS latitude and longitude, but one question nags me, Is it necessary to keep the Adafruit + FONA attached to the laptop?
    If I detach the unit from the USB cables the board goes dead or at least the lights go off?
    In this tutorial: https://learn.adafruit.com/geofencing-with-the-fona-808-and-adafruit-io/hardware-configuration
    the author says this: “, you could place this project in a bag, and immediately know if it has been stolen.”
    My LiPo battery appears to be fully charged, so the light on the FONA should be blue and the PWR light because it should draw power from the battery.

    Something is missing here that I quite do not understand.
    Can you throw some light on this, please.
    Thanks for your amazing tutorial.

Comments are closed.