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.

Passend dazu

SparkFun GNSS Combo Breakout - ZED-F9P, NEO-D9S (Qwiic)SparkFun GNSS Combo Breakout - ZED-F9P, NEO-D9S (Qwiic)
Sparkfun SparkFun GNSS Combo Breakout - ZED-F9P, NEO-D9S (Qwiic)
Sale price350,00 €
Not in stock, available for backorder
16344-SparkFun_GPS-RTK_Dead_Reckoning_Breakout_-_ZED-F9R__Qwiic_-01a_600x600.jpg16344-SparkFun_GPS-RTK_Dead_Reckoning_Breakout_-_ZED-F9R__Qwiic_-03a_600x600.jpg
Sparkfun SparkFun GPS-RTK Dead Reckoning Breakout - ZED-F9R (Qwiic)
Sale price248,00 € Regular price278,00 €
In stock, 4 units
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 price268,00 €
In stock, 5 units

Passend zu diesem Artikel

View all
Adafruit-Ultimate-GPS-Breakout_1_600x600.jpgAdafruit-Ultimate-GPS-Breakout_2_600x600.jpg
Adafruit Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates - Version 3
Sale price28,45 €
Not in stock, available for backorder
Adafruit-Ultimate-GPS-FeatherWing_1.jpgAdafruit-Ultimate-GPS-FeatherWing_2.jpg
Adafruit Adafruit Ultimate GPS FeatherWing
Sale price26,20 €
In stock
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 price268,00 €
In stock, 5 units
14414-02_600x600.jpg14414-06_600x600.jpg
Sparkfun SparkFun GPS Breakout - XA1110 (Qwiic)
Sale price38,00 €
Only 2 units left
17285-SparkFun_GPS_Breakout_-_NEO-M9N__SMA__Qwiic_-01.jpg17285-SparkFun_GPS_Breakout_-_NEO-M9N__SMA__Qwiic_-02.jpg
Sparkfun SparkFun GPS Breakout - NEO-M9N, SMA (Qwiic)
Sale price73,20 €
Only 2 units left
16481-SparkFun_GPS-RTK-SMA_Breakout_-_ZED-F9P__Qwiic_-01a_600x600.jpg16481-SparkFun_GPS-RTK-SMA_Breakout_-_ZED-F9P__Qwiic_-03a_600x600.jpg
Sparkfun SparkFun GPS-RTK-SMA Breakout - ZED-F9P (Qwiic)
Sale price269,00 €
In stock, 7 units
adafruit-fona-808-shield-mini-cellular-gsm-gps-for-arduino-03_600x600.jpgadafruit-fona-808-shield-mini-cellular-gsm-gps-for-arduino-04_600x600.jpg
Adafruit Adafruit FONA 808 Shield - Mini Cellular GSM + GPS for Arduino
Sale price49,56 €
Not in stock, available for backorder
adafruit-ultimate-gps-logger-shield--_EXP-R15-147_1_600x600.jpgadafruit-ultimate-gps-logger-shield--_EXP-R15-147_2_600x600.jpg
Adafruit Adafruit Ultimate GPS Logger Shield - Includes GPS Module
Sale price33,00 €
Not in stock, available for backorder