LESSON 24: Understanding GPS NMEA Sentences

GPS units spit out data in a dizzying array of formats. It can become a challenge to take the output from a GPS unit, like the Adafruit Ultimate GPS breakout board, and get that data to play nicely with mapping programs like Google earth. It is as if no one is speaking the same language. In this lesson we will look at what the data coming off the GPS means, and how you can work with it, and get it to display properly in programs like Google Earth.

Arduino GPS
We are using the Adafruit Ultimate GPS

When you connect a GPS board up, and look at the data coming off of it, you are likely to see something like this:


This is what the data looks like when your GPS does not have a fix. When it does have a fix, there will be all types of numbers between the commas in the lines above. So, how do we make sense of all this? The first thing is to learn some of the lingo. Each line above is referred to as a NMEA sentence. There are different NMEA sentence type, and the type is indicated by the first characters before the comma. So, $GPGSA is a certain type of NMEA sentence, and $GPRMC is a different type of NMEA sentence. To make this whole thing a manageable problem, the first thing we must realize is that the data that we want will be in the $GPRMC sentence  and the $GPGGA sentence. If your GPS unit has options to turn the other sentences off, then turn them off to simplify the data getting thrown at you. If you can not turn the other sentences off, then just ignore them, and focus on the two you care about,  $GPRMC, $GPGGA.

If your GPS has a fix, then your GPS sentences should look something like this:

Lets start by breaking down the $GPRMC sentence.

The $GPRMC is simply telling what sentence type is on the line. The next number,  represents the Coordinated Universal Time (UTC). It works like this, 194530.000 would be 19:45 and 30.0 seconds in UTC. Since converting from UTC to your local time is simply a matter of knowing what time zone you are in, you can see that one thing you get from a GPS is a very accurate clock. The next letter just lets you know if your signal is Active (A) or Void (V).  An ‘A’ indicates you are getting a signal and things are working properly. A ‘V’ means you do not have a signal.

Now, for the good stuff, the next number and following letter gives you your lattitude.  3051.8007,N should be interpreted as follows:

Your Latitude is: 30 degrees, 51.007 minutes, in the Northern Hemisphere.

Similarly, the next number, 10035.9989,W,  is Longitude. This is interpretted as:

Your Longitude is:  100 degrees 35.9989 minutes, in the Western Hemisphere.

Degrees could be a one, two or three digit number. Hence you have to be careful parsing this data. What is always the case is that the first two numerals to the left of the decimal place, and the numbers to the right of the decimal represent the minutes. So, always take the number starting two to the left of the decimal, and those following all the way to the comma, and that is your minutes. Unfortunately, if you simply try to put 3051.8007,N,10035.9989,W, into Google Earth, it will not recognize it. The simplest thing you can do to get Google Earth to recognize and properly display the coordinate would be to enter the following:

30 51.8007N, 100 35.9989W

Notice the space inserted between degrees and minutes, and no comma before hemisphere designation. This would properly display that single point via the Google Earth search bar. The challenge however is that if you want to log data from your GPS and then show a track of where you have been, you will have to create a KML or KMZ file. These files are even more particular about the format of the coordinate data. These files want both latitude and longitude as decimal numbers, so we must convert degrees, minutes to decimal degrees. You can do this simply by realizing that there are sixty minutes in a degree. So, for the case above, 51.8007 Minutes = 51.8007/60 degrees = .86335 degrees. So, to make a KML file that Google Earth will like, 30 51.8007N should be converted to 30.86335. We still have to deal with the N and W. KML files do not know what to do with the N, S, E, W. So, you must do the conversion. On Latitude, if you have a N, leave Latitude positive, if you have a S make your Latitude negative. On Longitude, if you have an E leave your number positive. If you have a W make your Longitude negative. Following these rules:

Should become:

30.8633, -100.5999

Those numbers will not only display properly in a KML file, they will also work if directly typed into the search bar on Google Earth.

We will talk more about KML files in the next lesson, but we will state here that in the KML file, you should put Longitude first, followed by Latitude. Opposite of how you put the numbers in Google earth, which wants latitude followed by longitude.

OK, that is the hard part, now for the rest of the characters in the sentence. The next number, 1.49 in the example above is the speed in knots. I was walking, so you can see this is a small number in the above example. The next number represents track angle, not something I find useful or use.  Then after that, you see the number  310714. This is the date, which would be DD/MM/YY so this date is July 31, 2014. You can see on my NMEA sentence, I just get commas after that. Some units report magnetic variation here, but mine doesn’t. Then finally, the final characters represent a checksum, something we do not need to worry with.

So there, our first NMEA sentence parsed. You can see that you get just about everything you need in this one sentence.

So why do we need the $GPGGA sentence you ask. Well, it has a couple of nuggets of info we need, particularly if we are doing High Altitude Ballooning/Edge of Space work. Lets look at the $GPGGA sentence:

Again, the first number represents the time.

194530.000 would be 19:45 and 30.000 seconds, UTC

The next numbers represent Latitude and Longitude, just as in the $GPRMC sentence above, so I will not go through that again.

Now the next number, 1 above, is the fix quality. a 1 means you have a fix and a 0 means you do not have a fix. If there is a different number it is more details on the type of fix you have. Next number is how many satellites you are tracking. For us, 4. The larger number here the better. Next up, 2.18 is the horizontal dilution of position. Something I don’t worry with. Next one is an important one . . . 746.4 is my altitude in meters above mean seal level. This is hugely important for projects like high altitude ballooning. It is a direct indication of your altitude. Next number is the altitude of mean sea level where you are. This is something you do not need to worry about in most applications but is related to a geometric approximation of the earth as an ellipsoid. Look up WGS84 Ellipsoid if you really want to understand this number.

OK, lets bring this all home now. Using the  $GPRMC and $GPGGA NMEA sentences, we can get our latitude and longitude coordinates, and convert them to numbers that can be recognized by Google Earth, or put into a KML file. We also have our speed in knots, and our altitude. These are all the things we would want for projects like unmanned aerial drones, or high altitude balloons.

34 thoughts on “LESSON 24: Understanding GPS NMEA Sentences”

  1. sir is there any direct function by which we can directly access latitude or longitute like GPS.lat or GPS.lon in this library?

  2. i am working on a project called speedometer using gps shield
    the value of speed is not accurate it is giving 0.5 even if the gps is stationary.can you suggest a solution.
    thanks in advance

    1. There is a several foot uncertainty in position on the GPS LAT/LON value. This translates to an error in the still position velocity. This would be hard to eliminate, given the intrinsic uncertainty in position.

  3. Hello sir,
    Can we build a speedometer using gps shield?
    I am using ‘adafruit ultimate gps shield with sd logger’ for tracking. While reading NMEA sentences we get a speed in knots.
    Can that speed be used to build a speedometer?
    Also i would like to know how that speed is estimated by gps?

    1. You could convert speed in knots to speed in MPH. Also, you have position and time in the NMEA sentences, so there are many ways to calculate speed from the data coming from the GPS

    1. If you want to use a camera you are probably better off moving to the Raspberry Pi. It has the speed needed to operate a camera.

    1. It might demand it, but I do not know if that is possible. The arduino barely has the speed to work with audio. I have not seen anyone use it for video

  4. Sir,
    I am using arduino due which has a clock of 84Mhz unlike arduino due.I want to integrate a camera with it and send the images via xbee

  5. Howdy,

    I was wondering if you have any experience using RTK or RTKLIB for accurate GPS positioning?


  6. Beware a trap with GPRMC speed that when the speed goes above 100 knots the decimal point (and tenths of a knot) values will no longer be present in the sentence. EG above 99.9 the sentence will read 100 with no decimal point.

  7. Thanks for any lesson you had teach hope world be a better place, ive question if theres any possibilities give commands to control servo depend NMEA data we`ve got from GPS in realtime ?

  8. hi. i appreciate for taking your time to make these wonderful videos that i have found to be very helpful to create my own projects using Arduino devices.
    I recently purchased SIM800L GSM/GPRS and i want it to send me GPS coordinates coming from ARDUINO GPS breakout through SMS messages. I am having trouble programming my UNO to do the task. Any information would be felpfull.
    Thank You

  9. helo sir,
    i am beginer for gps,i connected my gps module skg13bl to pc through serial,but NMEA data not displaying properly,some dot and semicoln is comming,
    u said make gps fix,
    please tell me how to fix gps.

    1. 1. Perhaps you are inside home. If that is the case you may go outside with your entire setup, under the clear sky for about 15 minutes and then after getting enough signal you may enter your room.

      2. Check your Baudrate.

  10. Hello Sir,

    I’d like to know if it’s possible to convert a gps file (N1R) with GLL mnea to GGA?

    Thank you for your attention.

    Best regardsm

  11. sir, i was using A7 AI-Thinker GPS/GPRS module.
    I try to get the GPS data. But why, my GPS data just like this?

    “$GPVTG, , , ,T, , , , M, , , , ,N, , , , ,K, , , , N*2C
    $GPGGA, , , , , , , , , V, , , , , ,, , , , , 0000, , , *71
    $GPRMC, , , , ,, , , , ,, , , , ect ”

    Do you have any idea what should i do?

  12. Hmm, I founda blog with a “gps fix” of 13T 0422126,4476509
    Can you point me toward a resource that explains this.
    I tried to convert to 42.2126,44.76509, but does not point to the correct location

  13. Thanx for reply.
    Have you using the A7 Ai-thinker gps module?
    i was parsing the GPS data if i get $GPRMC or $GPGGA.
    and i got my lattiude and longitude. But sometimes the Data error. i mean, For example my fix lattitude is 0612.7999,S but sometime i get 0612.7999,S7 or 0612.7999,S70639.0127.

    Do you have any idea what should i do?

    1. Hey, I’m using A7 board too and it’s really hard to get gps signal inside the building. I have heard from youtube review that given antenna isn’t suitable for the GPS frequencies, but anyway after waiting for some minutes I finally get fix data.

      And I want to ask you that could you give me tutorial about parsing NMEA data? I want to log just lon and lat to sdcard.
      My code from A7 echo is:
      if(A7board.available()) //A7board is my serial name for module
      char c=A7board.read();

  14. Sir,
    Can we use multiple software serial for declaring more than 2 serial port in ATmega328 ?

    1. I think we can have only one software serial active at a time. Maybe you can have one software serial and the one hardware one at the same time.

  15. my gps is giving me
    this result what i do know………..pls help
    Thanks in advance

Comments are closed.