ESP8266 - GPS
This tutorial instructs you how to use ESP8266 with a NEO-6M GPS module. In detail, we will learn:
- How to connect ESP8266 to a NEO-6M GPS module
- How to program ESP8266 to read GPS coordinates (longitude, latitude, and altitude) from a NEO-6M GPS module
- How to program ESP8266 to calculate the distance from the current GPS position to a predefined GPS coordinate (e.g. coordinates of London).
Apart from longitude, latitude, and altitude, ESP8266 is also able to read GPS speed (km/h), and date time from a NEO-6M GPS module.
Hardware Preparation
1 | × | ESP8266 NodeMCU | |
1 | × | Micro USB Cable | |
1 | × | NEO-6M GPS module | |
1 | × | Jumper Wires | |
1 | × | Breadboard | |
1 | × | (Optional) 5V Power Adapter for ESP8266 | |
1 | × | (Optional) Screw Terminal Expansion Board for ESP8266 |
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of NEO-6M GPS module
NEO-6M GPS module is a GPS module that can provide the following information:
- Longitude
- Latitude
- Altitude
- GPS speed (km/h)
- Date time
The NEO-6M GPS Module Pinout
The NEO-6M GPS module has 4 pins:
- VCC pin: This should be connected to VCC (5V)
- GND pin: This should be connected to GND (0V)
- TX pin: This is for serial communication and should be connected to the Serial (or SoftwareSerial) RX pin on ESP8266.
- RX pin: This is for serial communication and should be connected to the Serial (or SoftwareSerial) TX pin on ESP8266.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
ESP8266 Code
Reading GPS coordinates, speed (km/h), and date time
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Launch Arduino IDE
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search “TinyGPSPlus”, then find the TinyGPSPlus library by Mikal Hart
- Click Install button to install TinyGPSPlus library.
- Copy the code given and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the ESP8266.
- Check out the result on the Serial Monitor.
Calculating the distance from current location to a predefined location
This code computes the distance between the present location and London (latitude: 51.508131, longitude: -0.128002).
Detailed Instructions
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Copy the code and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the ESP8266.
- Check out the result on the Serial Monitor.