ESP32 GPS Tracker (IoT based Vehicle Tracking System)

    Having trouble finding your car after parking? With this project you won’t have to worry about that anymore! By installing your GPS Vehicle Tracking System, you will be able to find your vehicle and track it wherever you are!

GPS is short for Global Positioning System, a worldwide radio navigation system. The GPS tracking system uses the Global Navigation Satellite System (GNSS) Network to track the device’s location. This network consists of a series of satellites that use microwave signals to transmit data to be received by the GPS receiver module.

In this project, we will set up an IoT-based GPS Vehicle Tracking System using ESP32, where we will display the latitude and longitude values ​​on the OLED Screen, as well as Blynk App, so that it can be monitored from anywhere in the world. You can also do the same with Loron and Cellron cards on our site.

Required Components

  • ESP32
  • GPS Module
  • OLED Display Module
  • Jumper Wires
  • Breadboard

OLED Display

OLED displays are one of the most common and readily available displays for a microcontroller. This display can be easily interfaced with the microcontroller using IIC or SPI communication and has a good viewing angle and pixel density, making it reliable for displaying small-level graphics. Compatible with any 3.3V-5V microcontroller like Arduino. The OLED display comes with a powerful single-chip CMOS OLED driver controller – SSD1306, which manages all RAM buffering. The SSD1306 drive has built-in 1KB Graphic Display Data RAM (GDDRAM).

Features

OLED Driver IC SSD1306
Resolution 128 x 64
Point of view >160 °
Input Voltage 3.3V ~ 6V
Pixel Color Blue
Operating temperature -30°C ~ 70°C

Neo 6M GPS Module

The NEO-6M module comes in a 16 x 12.2 x 2.4mm package size. It has 6 Ublox positioning engines that offer unmatched performance. It is a good performing GPS receiver with compact architecture, low power consumption and reliable memory options. It is ideal for battery powered mobile devices given its architecture and power demands. Initial Fix Time is less than 1 second and allows it to locate satellites almost instantly. The output is in the form of NMEA standards that can be decoded to find the coordinates and time of the location.

Power Supply 2.8V – 5V
Interface RS232 TTL
Internal EEPROM and external antenna
Default baud rate 9600 bps

Circuit Diagram

Circuit Diagram for ESP32 GPS NEO 6M is given below.

Here we are interfacing ESP32 with GPS Module and OLED Display. The Vcc and GND pins of the GPS Module are connected to the 3.3V and GND pins of the ESP32, and the RX and TX pins are connected to the TX2 and RX2 pins of the ESP32. I2C mode is used to connect OLED display Module (SSD1306) with ESP32 Connections between ESP32 and OLED Display are as follows:

OLED Pin

ESP32 Pin

Vcc

3.3v

GND

GND

SCL

D22

SDA

D21

Configuring Blynk App for ESP32 GPS Tracker

Download the Blynk app from the Google Play Store and create a new account or log in to your existing account.

Now click ‘New Project’ to start a new project.

Now give a name for your project. Select ‘ESP32 Dev Board’ in CHOOSE DEVICE option and ‘Wi-Fi’ in CONNECTION TYPE. Then click “Create”.

After that Blynk sends an Authorization to the registered Email id. Note the Authorization Token Code. It will be used in the program.

Now in the next window, click on the “+” sign to add a widget. Select the ‘Map’ widget inside the widget box.

After that, click on MAP widget and select virtual pin ‘V0’ as INPUT.

With this final step, you are ready to use your app. By pressing the ‘Play’ button you can switch your application from EDIT mode to PLAY mode where you can interact with the hardware.

Code Description

The full code of the ESP32 GPS Tracking System is given at the end of the page. Here we explain some important parts of the code. In this program, we will use the Wire.h, TinyGPS++.h, SH1106.h and BlynkSimpleEsp32.h libraries. These libraries can be downloaded from the following links:

As usual, start the code by including all required libraries. SH1106.h was created specifically for ESP modules.

#include 
#include 
#include 
#include 
#include 
#include 

After that define variables to store Latitude and Longitude values.

float latitude, longitude;
String lat_str, lng_str;

Enter your Wi-Fi name and password in the next lines and also enter the Blynk Authorization key.

const char *ssid = "Wi-Fi Name";
// Enter your Wi-Fi Nameconst char *pass = "Wi-Fi Password";
// Enter your Wi-Fi Passwordchar auth[] = "Blynk Key";

After that, create an example for the OLED display with the Address and pins to which the display is connected.

SH1106 display(0x3c, 21, 22);

Inside the setup() function, start the Serial Monitor at baud rate of 115200 for debugging purposes and also start the OLED display, GPS module and Blynk with the startup() method.

void setup()
{
Serial.begin(115200);
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
}
Serial.println("WiFi connected");
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V0, "clr"); 
}

Inside the loop() function, check if there is data from the GPS module. If data is available, the code encodes the data and checks whether the encoded data is valid, if the data is valid, further calculations are made to convert the NMEA data into intelligible data.

while (SerialGPS.available() > 0){
if (gps.encode(SerialGPS.read()))
{
   if (gps.location.isValid())
   {
     latitude = gps.location.lat();
     lat_str = String(latitude , 6);
     longitude = gps.location.lng();
     lng_str = String(longitude , 6);
    }
}
}

After that, the GPS data is sent to the Blynk app and the OLED display. The Blynk app uses the Map widget to pinpoint the user’s location using latitude and longitude data.

display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_16);
display.drawString(0, 23, "Lat:");
display.drawString(45, 23, lat_str);
display.drawString(0, 38, "Lng:");
display.drawString(45, 38, lng_str);
Blynk.virtualWrite(V0, 1, latitude, longitude, "Location");

Operation of ESP32 GPS Tracking System

When the hardware and program are ready, download the GPS tracking program to your ESP32 Card. Here Arduino IDE is used to upload the ESP32 GPS NEO 6M code to the ESP32 board, so connect the ESP32 to your laptop with a Micro USB Cable and press the upload button. After the code is uploaded, the OLED displays the Latitude and Longitude values. It will also show the location in the Blynk app on the Map like this:

Detailed code is given below.

Code

#include <TinyGPS++.h>
#include 
#include 
#include  // Only needed for Arduino 1.6.5 and earlier
#include 
#include 
float latitude , longitude;
String lat_str , lng_str;
const char *ssid = "Galaxy-M20"; // Enter your WiFi Name
const char *pass = "ac312129"; // Enter your WiFi Password
char auth[] = "loPrSaL0eQFY9clcQ518R1SmYsRVC0eV"; 
WidgetMap myMap(V0); 
SH1106 display(0x3c, 21, 22);
WiFiClient client;
TinyGPSPlus gps;
HardwareSerial SerialGPS(1);
void setup()
{
Serial.begin(115200);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print ... till not connected
}
Serial.println("");
Serial.println("WiFi connected");
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V0, "clr"); 
}
void loop()
{
while (SerialGPS.available() > 0) {
if (gps.encode(SerialGPS.read()))
{
if (gps.location.isValid())
{
latitude = gps.location.lat();
lat_str = String(latitude , 6);
longitude = gps.location.lng();
lng_str = String(longitude , 6);
Serial.print("Latitude = ");
Serial.println(lat_str);
Serial.print("Longitude = ");
Serial.println(lng_str);
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_16);
display.drawString(0, 23, "Lat:");
display.drawString(45, 23, lat_str);
display.drawString(0, 38, "Lng:");
display.drawString(45, 38, lng_str);
Blynk.virtualWrite(V0, 1, latitude, longitude, "Location");
display.display();
}
delay(1000);
Serial.println(); 
}
} 
Blynk.run();
}

Thank you.

FOLLOW US

Follow us on our social media accounts for our current news.