ESP8266 Peripherals: uBlox GPS Module

Almost 20 years ago when I studied a few semesters of electrical engineering at the famous ETH in Zurich I had a lecture about the basics of digital electronics. And I remember the professor doing many practical demonstrations such as drilling holes into a CD to show the quality of error correction in different price categories of CD players. I also remember that he talked about tiny and cost efficient GPS receivers that soon would be part of every cell phone (remember, 20 years ago the real age of smart phones had still been a few years away). That Professor, Gerhard Tröster, followed that vision and co-founded a company called u-blox, a non-fab producer of positioning systems with about 450 employees today. I was very excited indeed when I found a very affordable GPS module in my favourite Chines online shop, with a design by u-blox! So in this second post of my ESP8266 peripheral series I will review this module, show you how to use it with the ESP8266 and give you some ideas for applications.


The uBlox module VK2828U7G5LF for under $10

What is this module doing?

At least since the iPhone 3G came to the market GPS based navigation has become a commodity for many people. The global positioning system receives signals from satellites. If the signals of at least four satellites are received the position of the device can be calculated. It can do this by comparing small differences in the  time the signal took to reach the receiver. Since the satellites broadcast these signals with relatively weak signal the receiver requires direct line-of-sight to the satellites and this means pure GPS often doesn’t work well indoors.

Enough about the theory, how can the ESP8266 talk to the u-blox module? The module exposes the positioning information through a serial interface, just like the one you are using to program the ESP8266. By default it is set to 9600 baud but this value can be changed also through the serial interface. Apparently it is a very common thing that GPS modules have a serial interface and another partially standardized aspect is the message format. This module sends messages in the NMEA (0183 V3.0) format. This format knows many different types of messages, some of them are vendor specific. We are here interested in general messages. If you look directly at the serial output you will see messages like this:



Setting up the module with the ESP8266

Connecting the uBlox Module to the ESP8266

Connecting the uBlox Module to the ESP8266


Now that we have connected the u-blox module it is ready for our first code. We want to read the NMEA messages in the NodeMCU and forward them to the serial console on the PC. This code here does the trick:

#include <SoftwareSerial.h>

// if you are not using a NodeMCU but another type of ESP8266
// you might want to replace this with the correct GPIO pin numbers you used
SoftwareSerial mySerial(D5, D6); // RX, TX

void setup() {
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  // set the data rate for the SoftwareSerial port


void loop() {
  if (mySerial.available()) {
  if (Serial.available()) {

Upload the sketch to your ESP and open the serial console. Now you should see the NMEA messages come in.
At first there might be values missing, but the more satellite signals the module receives the more complete the positioning information will be. After this first smoke test lets continue with a library that can make sense of the NMEA messages.

Related:  ESP8266 Peripherals: Indoor Positioning with IR Camera


The TinyGPS+ library

By installing this library you can finally get to the core of the GPS information: latitude, longitude, altitude, speed, etc. Go to and download the library, extract it to your Arduino/libraries folder and restart your Arduino IDE. Then go to File > Examples > TinyGPSPlus and open the FullExample file. Now you have to adapt the baud rate to 9600 (this is the default serial speed of our u-blox module) and change the serial pins to D5 and D6 and run the code.

static const int RXPin = D5, TXPin = D6;
static const uint32_t GPSBaud = 9600;

If you are not getting any position information you might want to get closer to the window or even go outside. Pure GPS is notoriously famous for not working indoors, due to the weak satellite signals and interference with other RF sources.


Application Ideas

Ok, great. Now we have a working GPS module. But what can we do with it? Here are a few ideas:

  • Bike computer: mix together an OLED display, NodeMCU, a USB power bank and the GPS module and mount everything on your bike. With a little bit of code you can display information on the OLED display such as speed, altitude and you can use way points even to some basic navigation. Store the tracking data in the EEPROM and upload it to the cloud as soon as the device detects your home device
  • War Drive Module: okay, I admit, this might not have the relevance anymore that it once had, but you could build it for less than USD $20! Wire up the GPS module and the NodeMCU and a Power Bank and bring it with you to work while it is running. Every 30 seconds or so list the SSID the NodeMCU lists through the Wifi Interface together with the location and store it in the EEPROM. Later use that information to create a map of (free?) Wifi access points
  • High precision real time clock: In order to calculate your current position the satellite send highly precise time stamps which you can read with help of the TinyGPS+ library. True, you can use the network time protocol (NTP) to fetch the current time if your ESP is connected to the internet. But if you are offline for some reason the GPS clock might be handy. You could actually implement your own NTP server, backed by the GPS module
Related:  ESP8266 Peripherals: KY-040 Rotary Encoder



The module is easy to use and with less than USD $10 it was a no-brainer to order it and to try it out. The serial interface makes it very convenient to use if you have two GPIO pins to spare. Without problems I could use the SoftwareSerial module so I still could be using the hardware serial interface for debugging. While I think it is a great module for your outdoor positioning project it doesn’t work very well indoors. Nowadays we are spoiled by quickly locking GPS modules on smartphones which also perform well indoors. But be warned: the GPS module isn’t as good as that, since it cannot use information like (GSM) cell Ids or Wifi SSIDs to improve speed and accuracy of the position signal. But the module will be a great addition to your tool box for your next project (see ideas above). I forgot to mention that the GPS module has a convenient way to save energy in case you don’t need it: setting the yellow pin to LOW will basically shutdown the module completely.


Where to buy?

If you are a frequent reader of my blog you will know that I usually order my electronic ingredients from China. Most of the time I don’t care about the relatively long delivery time of 10-20 days. My favourite shop is Banggood where I barely had problems with bad quality or missing orders. If you like my posts please consider following one of my affiliate links. I honestly only recommend products I believe they are worth your money. And buying after following one of the links I will get a small kick back from your purchase to support this blog. Here is the link:


Now a beer! Did you like this post? It often takes me several hours of my free time to write one. If I was your neighbour would you offer me a beer for the hard work I did for you? The beauty is: beers can be teletransported with a painless donation using Paypal. A beer in a Swiss bar costs about USD $4.80. Or use this affiliate link if you order something on Banggood and I'll get a small kickback. Thank you!