IOT

How to design Real-Time GPS Tracker using ESP8266 & Blynk with Maps.

GPS stands for Global Positioning System. GPS module finds the location (latitude, longitude, altitude) by comparing the time taken for receiving signals from satellites in its vicinity. GPS offers great accuracy and also provides other data besides position coordinates.

This post is about an IoT-based real-time GPS tracker that utilizes the NodeMCU ESP8266 and Blynk, as well as Google Maps. Previously, we developed a GSM+GPS-based vehicle location tracker. To track location, we will utilize an ESP8266 WiFi Module instead of a GSM Module.

In this project, we’ll connect a Quectel L86 GPS Module to a NodeMCU ESP8266 Board. You can use the Neo-6M GPS Module or any other similar GPS Module instead of the Quectel L86 GPS Module. We’ll use the TinyGPS library to calculate the latitude, longitude, speed, bearing, and map location. All of these characteristics will be sent to the Blynk Application, where they will be monitored in real-time alongside the map on the Blynk Dashboard.

Components Required:

  • NodeMCU-ESP-12E based Wi-Fi module
  • Quectel L86-POT (patch antenna on top) GPS module
  • Breadboard
  • Connecting Wires

Global Positioning System

The GPS (Global Positioning System) is a satellite-based navigation system with at least 24 satellites. 

Global Positioning System (GPS) makes use of signals sent by satellites in space and ground stations on Earth to accurately determine their position on Earth. The GPS receives radio frequency signals from satellites and ground stations. These signals are used by GPS to identify their precise location. With no subscription fees or setup charges, GPS works in any weather condition, anywhere in the world, 24 hours a day.

How does GPS work?

GPS satellites circle the Earth twice a day in a precise orbit. Each satellite transmits a unique signal and orbital parameters that allow GPS devices to decode and compute the precise location of the satellite. This information, together with trilateration, is used by GPS receivers to calculate a user’s actual location. The GPS receiver calculates the distance between each satellite by the time it takes to receive a broadcast signal. The receiver can determine and show a user’s position using distance measurements from a few more satellites.

A GPS receiver must be locked on to the signal of at least three satellites to determine your 2-D position (latitude and longitude) and track movement. The receiver can calculate your 3-D position if there are four or more satellites in view (latitude, longitude, and altitude). A GPS receiver will often track eight or more satellites, depending on the time of day and where you are on the planet.

After determining your location, the GPS unit can calculate additional data, such as:

  • Speed
  • Bearing
  • Track
  • Trip dist
  • Distance to destination

Quectel L86/L80 GPS Module

Because of its ultra-compact form and low power requirements, the L86 is an excellent choice for wearable fitness devices. While in static reception mode, its Low Power function allows GPS connectivity at about half the power usage of the standard model. The L86 is appropriate for a wide range of IoT applications, including portable devices, automotive, personal tracking, security, and industrial PDAs, thanks to its precision and high sensitivity.

With 66 acquisition channels and 22 tracking channels, the L86 includes a patch antenna on top that measures 16.0mm x 16.0mm x 6.45mm. Even at the indoor signal level, it gathers and tracks satellites in the shortest time possible. The module runs between 2.8 and 4.3 volts, with an average power usage of 20 milliamperes, and a standby power consumption of roughly 1.0 milliamperes. As seen in the diagram below, the Quectel L86/L80 GPS Module has 12 pins.

L86 Pinout

The L86 is a miniature SMD-type module with no male/female header pins for testing. As a result, you can use the 2.54-spacing male header pins and solder them on the L86 PCB from the bottom.

  • Once you’ve soldered all 12 pins on the L86 Module, it’s ready to use on a breadboard. You may now easily place the module on the breadboard.

Circuit for GPS Tracker using ESP8266

Let’s get started on the project and construct a Real-Time GPS Tracker with the ESP8266 and Blynk. The connection diagram is straightforward.

GPS Tracker using ESP8266

Connect the L86 GPS Module’s VCC/GND to the NodeMCU ESP8266’s 3.3V/GND. Don’t go above 3.3 volts. Connect the VCC backup (V BCKP) to VCC or an external battery in the same way. If this pin is not energized, it will not work.

Connect the RX/TX of the L86 to the NodeMCU’s D1/D2. This is for Software Serial Communication.

You can connect directly with a jumper wire or assemble the circuit on a breadboard. As a result, the hardware for a GPS tracker based on the ESP8266 is complete.

Installing the Blynk App

  • We’ll utilize the Blynk application to track GPS location and all of its information. Google Maps is also available through the Blynk App.
  • Blynk is a new platform that lets you easily create interfaces to manage and monitor your hardware projects from your iOS or Android mobile. You can create a project dashboard after downloading the Blynk software and arranging buttons, sliders, graphs, and other widgets on the screen.
  • Download the Blynk App from your Android Playstore.
  • Sign up using an Email ID & Password or if you are new, create an Account.
  • Then start a new project with an ESP8266 and a WiFi connection. As a result, a project will be created for you, and an Authentication Token will be emailed to you.

This Authentication Token should be copied because it will be needed in the Arduino code. The ESP8266 will not be able to connect to Blynk without this token.

You must now develop a widget for each of the six parameters.

  • Latitude – Value Display – Virtual Pin V1
  • Longitude – Value Display – Virtual Pin V2
  • Satellite – Value Display – Virtual Pin V3
  • Speed – Value Display – Virtual Pin V4
  • Bearing – Value Display – Virtual Pin V5
  • Map – Map – Virtual Pin V0

Once all widgets are created and values are assigned, the dashboard will look something like this.

The setup for the Blynk-based ESP8266 GPS Tracker is now complete. So you’re all set to go.

Source Code/Program for ESP8266 Based GPS Tracker

The Arduino IDE is used to write the code for the GPS Tracking System. Combining TinyGPS Library and Blynk sample code, the code was written.

For code compilation, we’ll require the following two libraries. These libraries can be downloaded and placed in the Arduino Library Folder.

1. TinyGPS++ Library: https://github.com/mikalhart/TinyGPSPlus

2. Blynk ESP8266 Library: https://github.com/blynkkk/blynk-library

A few lines in this code must be changed. Enter the SSID, password, and Blynk Authentication Code for your WiFi network.

char auth[] = “************************”; //Blynk Authentication Token
char ssid[] = “************************”; // WiFi SSID
char pass[] = “************************”; // WiFi Password

Here is the complete code for a Real-Time GPS Tracker with Blynk and Maps using an ESP8266 and Blynk. Copy and paste the code onto the NodeMCU ESP8266 Board.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

static const int RXPin = 4, TXPin = 5; // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS
static const uint32_t GPSBaud = 9600; //if Baud rate 9600 didn’t work in your case then use 4800

TinyGPSPlus gps; // The TinyGPS++ object
WidgetMap myMap(V0); // V0 for virtual pin of Map Widget

SoftwareSerial mygps(RXPin, TXPin); // The serial connection to the GPS device

BlynkTimer timer;

float latitude; //Storing the Latitude
float longitude; //Storing the Longitude
float velocity; //Variable to store the velocity
float sats; //Variable to store no. of satellites response
String bearing; //Variable to store orientation or direction of GPS

char auth[] = “********************”; //Blynk Authentication Token
char ssid[] = “********************”; // WiFi SSID
char pass[] = “********************”; // WiFi Password

//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now


void setup()
{
Serial.begin(115200);
Serial.println();
mygps.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS); // every 5s check if GPS is connected, only really needs to be done once
}

void checkGPS()
{
if (gps.charsProcessed() < 10)
{
Serial.println(F(“No GPS detected: check wiring.”));
Blynk.virtualWrite(V3, “GPS ERROR”); // Value Display widget on V3 if GPS not detected
}
}

void loop()
{
while (mygps.available() > 0)
{
// sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(mygps.read()))
displayInfo();
}
Blynk.run();
timer.run();
}


void displayInfo()
{
if (gps.location.isValid() )
{
sats = gps.satellites.value(); //get number of satellites
latitude = (gps.location.lat()); //Storing the Lat. and Lon.
longitude = (gps.location.lng());
velocity = gps.speed.kmph(); //get velocity
bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction

Serial.print(“SATS: “);
Serial.println(sats); // float to x decimal places
Serial.print(“LATITUDE: “);
Serial.println(latitude, 6); // float to x decimal places
Serial.print(“LONGITUDE: “);
Serial.println(longitude, 6);
Serial.print(“SPEED: “);
Serial.print(velocity);
Serial.println(“kmph”);
Serial.print(“DIRECTION: “);
Serial.println(bearing);

Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
Blynk.virtualWrite(V3, sats);
Blynk.virtualWrite(V4, velocity);
Blynk.virtualWrite(V5, bearing);
myMap.location(move_index, latitude, longitude, “GPS_Location”);
}
Serial.println();
}

Testing Real Time GPS Tracker

Open Serial Monitor after you’ve uploaded the code. The ESP8266 will make an attempt to connect to the WiFi network. The GPS Module will begin scanning for the nearest satellite once it has connected to the WiFi Network. Depending on your indoor/outdoor environment, retrieving your location may take some time.

  • It will display the latitude, longitude, speed, bearing, and a number of satellites it is connected to after retrieving satellite data.
  • You can now open your Blynk App and press the play button in the upper right corner.
  • The Blynk App will immediately begin displaying all of the above information, as well as the Google Maps position.

You may now use this GPS device to track the whereabouts of your vehicle or any asset in real-time. The tracker should be linked to the WiFi network at all times.

Conclusion:

I hope all of you are clear about how to design Real-Time GPS Tracker using ESP8266 & Blynk with Maps. We MATHA ELECTRONICS will be back soon with more interesting topics.

Leave a Reply

Your email address will not be published.