Arduino Tutorial: Global Positioning System (GPS)

The Global Positioning System (GPS) has been around since the 80's and it's still one of the most important features you can add to any electronic system. The idea of tracking something (or someone) is cool enough, but it's much cooler without a phone or internet connection. In this Arduino GPS tutorial, we'll discuss the basics of GPS and hopefully help you build Arduino GPS projects.

How is the location tracked?

The entire GPS system depends on 24 (minimum) satellites orbiting the Earth. Each satellite constantly broadcasts its current time and position. Generally, a GPS receiver requires a connection to at least four of these satellites to receive data to calculate position. The receiver also calculates the clock difference between it and the satellite.

The standard horizontal accuracy of a GPS receiver is 15 meters. Enhancement schemes such as WAAS and DGPS are implemented to improve the accuracy to 2-3 meters. Assisted GPS (A-GPS) is another augmentation scheme mainly used by cell phones. In this scheme, the GPS receiver seeks "assistance" from cellular networks to improve accuracy.

NMEA sentences

The calculated longitude, latitude and altitude can be read by devices using the NMEA 0183 protocol. This protocol creates "sentences" in ASCII format that contain this data as well as additional information such as bearing and speed. Each sentence begins with a set of $ GPXXX codes that describes what information is contained in the sentence. Here is a list of all these codes.

Of all these codes, only 19 have been interpreted. Of all these 19, only one code type is generally used to read the item: $ GPRMC, which is defined as "recommended minimum specific GPS / transit data".

Here is an example of a $ GPRMC record:

GPRMC, 220516, A, 5133.82, N, 00042.24, W, 173.8,231.8,130694.004.2, W * 70

The above block contains 9 pieces of information:

  • 220516 - time in UTC. This would be 22.05.16
  • A - Validity. A = valid, V = invalid
  • 5133.82, N - latitude
  • 0.0042.24, W - longitude
  • 173.8 - Receiver speed in nautical miles per hour (knots)
  • 231.8 - True course in degrees
  • 130694 - Date in UTC. This would be June 13, 1994
  • 004.2, W - magnetic deviation in degrees
  • * 70 - mandatory checksum

An alternative to $ GPRMC is $ GPGGA, which is defined as "Global Positioning System Fix Data".

Here is an example of a $ GPGGA record:

$ GPGGA, 154655,4328,1874, N, 00340,5185, W, 1,03,08,5, -00044,7, M, 051,6, M, * 79

This is what is contained in the above theorem:

  • 154655 - time in UTC. This would be 15:46:55
  • 4328.1874, N - latitude
  • 00340.5185, W - longitude
  • 1 - GPS quality indicator. 0 is invalid, 1 is GPS fix, 2 is differential GPS fix.
  • 03 - number of satellites used
  • 08.5 - horizontal reduction of accuracy
  • -00044.7, M - antenna height above / below mean sea level in meters
  • 051.6, M - geoidal separation in meters
  • (blank) - age in seconds since last update from diff. Reference station (empty, because GPS quality indicator is GPS fix)
  • (empty) - diff. reference station ID (also empty since GPS mode is enabled)
  • * 79 - mandatory checksum

Since NMEA sentences are strings, we can easily extract the required information using various programming techniques. The NMEA sentences can be read by GPS devices via serial communication, especially RS-232, so any microcontroller with USART function can read data from a GPS peripheral.

Arduino GPS Logger Shields

To be able to use GPS data easily and quickly in the Arduino environment, so-called GPS Logger Shields are often used.

An Arduino GPS Logger Shield is basically a 2-in-1 shield. It has a GPS shield with an SD card slot where the GPS data can be recorded. These two functions are combined into one shield to form a powerful Arduino GPS logger.

In the further part three logger shields for Arduino are presented. If you don't want to work with a shield or haven't found your suitable module, please have a look at our selection of GPS modules.

SparkFun Arduino GPS Logger

The Arduino GPS logger features a GPS module with very high sensitivity, as well as an SD card slot and a battery compartment. The battery socket is used to operate the RTC on the GPS module.

This shield can communicate with Arduino via the UART pins (pins 0 and 1 of Arduino) or via two other pins and the SoftwareSerial library. You can switch between these two modes by using a small switch on the Shield.

An important aspect to consider when dealing with a shield that can use both SoftwareSerial and the Arduino's UART is the UART switch. When uploading the sketch, it should always be on the SoftwareSerial side to ensure that the sketch is uploaded correctly. Then you can move the switch back to the HW UART side after uploading the code. This applies to all shields that could use both SW-UART and HW-UART.

Please read the SparkFun hook instructions before purchasing and note that this requires soldering the headers.

Adafruit Ultimate Arduino GPS Logger Shield

The Shield uses a GPS module that has the same sensitivity and nearly the same power consumption as Sparkfun's GPS Logger.

The Shield also has a uFL / SMA connector. This is a connector next to the GPS module where you can connect an external antenna and pack your project in a box, for example. This antenna is not included, but can be a great addition to an advanced project.

SparkFun Mini GPS Shield

To be brief, this shield is completely different from the other shields and is not even compatible with the Arduino UNO. It is only compatible with the Arduino Mini board, hence the name.

The shield is sold without the GPS module. However, it has a set of pins that you can connect to a GPS module via a connector. The GPS module supported by this shield is slightly different from the other modules. It has almost the same sensitivity and higher power consumption. However, the update rate is several times higher than all other modules.

The GPS module can also be purchased additionally from us.

Matching products

15136-SparkFun_GPS-RTK2_Board_-_ZED-F9P__Qwiic_-03_600x600.jpg15136-SparkFun_GPS-RTK2_Board_-_ZED-F9P__Qwiic_-04_600x600.jpg
Sparkfun SparkFun GPS-RTK2 Board - ZED-F9P (Qwiic)
Sale price173,67 €
Only 3 units left

Matching this article

View all
15136-SparkFun_GPS-RTK2_Board_-_ZED-F9P__Qwiic_-03_600x600.jpg15136-SparkFun_GPS-RTK2_Board_-_ZED-F9P__Qwiic_-04_600x600.jpg
Sparkfun SparkFun GPS-RTK2 Board - ZED-F9P (Qwiic)
Sale price173,67 €
Only 3 units left
flora-wearable-ultimate-gps-module-03_600x600.jpgflora-wearable-ultimate-gps-module-02_600x600.jpg
Adafruit Adafruit Flora Wearable Ultimate GPS Module
Sale price12,05 €
Only 3 units left
18019-SparkFun_RTK_Express-02.jpg18019-SparkFun_RTK_Express-04.jpg
Sparkfun SparkFun RTK Express
Sale price385,56 €
Only 1 unit left
18774-SparkFun_GNSS_Timing_Breakout_-_ZED-F9T__Qwiic_-01.jpg18774-SparkFun_GNSS_Timing_Breakout_-_ZED-F9T__Qwiic_-02.jpg
Sparkfun SparkFun GNSS Timing Breakout - ZED-F9T (Qwiic)
Sale price193,11 €
In stock, 5 units
15005-SparkFun_GPS-RTK__Qwiic__-_NEO-M8P-2-00_600x600.jpg15005-SparkFun_GPS-RTK__Qwiic__-_NEO-M8P-2-01_600x600.jpg
Sparkfun SparkFun GPS-RTK Board - NEO-M8P-2 (Qwiic)
Sale price145,80 €
Only 2 units left
SparkFun Triband GNSS RTK Breakout - UM980SparkFun Triband GNSS RTK Breakout - UM980
Sparkfun SparkFun Triband GNSS RTK Breakout - UM980
Sale price178,20 €
Only 2 units left