ESP32 GPS Tracker- IoT based Vehicle Tracking System

ESP32 GPS Tracker- IoT based Vehicle Tracking System

GPS stands for Global Positioning System, which is a worldwide radio-navigation system. To track the location of the device, the GPS tracking system uses the Global Navigation Satellite System (GNSS) Network. This network consists of a range of satellites that uses microwave signals to transmit the data which will be received by the GPS receiver module. 

Previously we used GPS with NodeMCU ESP8266 to build a Vehicle Tracking System and Accident alert system. In this project, we are going to build an IoT based GPS Vehicle Tracking System using ESP32 where we will display the latitude and longitude values on OLED Display as well as on Blynk App so that it can be monitored from anywhere in the world. 

 

Components Required

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

 

OLED Display

OLED Display

The OLED displays are one of the most common and easily available displays for a microcontroller. This display can easily be interfaced with microcontroller using IIC or using SPI communication and has a good view angle and pixel density which makes it reliable for displaying small level graphics. It is compatible with any 3.3V-5V microcontroller, such as Arduino. The OLED display comes with a powerful single-chip CMOS OLED driver controller – SSD1306 that handles the entire RAM buffering. The SSD1306 driver has a built-in 1KB Graphic Display Data RAM (GDDRAM). We previously interfaced OLED with ESP32

Specifications:

  • OLED Driver IC: SSD1306
  • Resolution: 128 x 64
  • Visual Angle: >160°
  • Input Voltage: 3.3V ~ 6V
  • Pixel Colour: Blue
  • Working temperature: -30°C ~ 70°C

 

Neo 6M GPS Module

The NEO-6M module comes with a dimension of 16 x 12.2 x 2.4 mm package. It has 6 Ublox positioning engines offering unmatched performance. It is a good performance GPS receiver with a compact architecture, low power consumption, and reliable memory options. It is ideal for battery-operated mobile devices considering its architecture and power demands. The Time-to-First-Fix is less than 1 second and it enables it to find the satellites almost instantly. The output is in the format of NMEA standards, which can be decoded to find the coordinates and Time of the location.

Neo 6M GPS Module

  • Power supply: 2.8V to 5V
  • Interface: RS232 TTL
  • Built-in EEPROM and external antenna
  • Default baud rate: 9600 bps

We previously used GPS module Neo 6M with NodeMCU and displayed the location coordinates on a web-page, check all the GPS based IoT projects here.

 

Circuit Diagram

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

Circuit Diagram For ESP32 GPS NEO 6M

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

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 Login into your existing account. 

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

Blynk App

 

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

After this, Blynk will send an Authorization to the registered Email id. Note down the Auth Token Code. It will be used in the Program. 

Configuring Blynk App for ESP32 GPS Tracker

 

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

Configuring Blynk App

 

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

ESP32 GPS Tracker using Blynk

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

 

Code Explanation

The complete code for ESP32 GPS Tracking System is given at the end of the page. Here we are explaining some important parts of code.

In this program, we are going to use the Wire.hTinyGPS++.hSH1106.h and BlynkSimpleEsp32.h libraries. These libraries can be downloaded from below links:

 

So as usual, start the code by including all the required libraries. SH1106.h is especially created for ESP modules. 

#include <TinyGPS++.h>
#include <HardwareSerial.h>
#include <WiFi.h>
#include <Wire.h>               
#include<SH1106.h> 
#include <BlynkSimpleEsp32.h>

 

After that define the variables to store the Latitude and Longitude values.

float latitude, longitude;
String lat_str, lng_str;

 

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

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

 

After that, create an instance for the OLED display that includes the Address and pins where the display is connected.

SH1106 display(0x3c, 21, 22);

 

Inside the setup() function, initialize the Serial Monitor at a baud rate of 115200 for debugging purposes and also initialize the OLED display, GPS module, and Blynk with the begin() 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 incoming data from the GPS module. If the data is available, the code encodes the data and checks if the encoded data is valid or not, if the data is valid, then the further calculation is done to transform the NMEA data to the understandable 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 this, the GPS data is sent to the Blynk app and OLED display. Blynk app uses the Map widget to pinpoint the user's location using the 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");

 

Working of ESP32 GPS Tracking System

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

ESP32 GPS Tracker

A working video and code for this IoT based ESP32 GPS Tracker are given below.

Code

#include <TinyGPS++.h>
#include <HardwareSerial.h>
#include <WiFi.h>
#include <Wire.h>               // Only needed for Arduino 1.6.5 and earlier
#include<SH1106.h> 
#include <BlynkSimpleEsp32.h>
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();
}

Video

31 Comments

i'm beginner, somehow mine it's now working, esp32 red led on, neo 6m not blinking, the oled is not display anything, when i try to measure dc voltage with multimeter, from esp32 plugin to breadboard, then connected to oled, it shows 0,8 - 0,9 dc volt. is that correct?

in Blynk app, it shows New Device Online. when i turn off esp32, few second later, its shows Offline Location. it mean its working, but in the oled not show anything, and the GPS not blinking.

I was so excited to get this project working. Unfortunately, I cant get the code to compile. I've Googled for hours and cant get past the 'esp8266-oled-ssd1306-master\src/SH1106Wire.h:49:7: error: 'TwoWire' does not name a type
TwoWire* _wire = NULL;' and the 'blynk-library-master\src/BlynkSimpleEsp32.h:37:14: error: 'class WiFiClass' has no member named 'mode'
WiFi.mode(WIFI_STA);' errors

Shouldn't you add a SIM card, which allows the ESP32 to connect to WiFi? Otherwise, how can I possibly track my car if I'm leaving my car and try to connect 'from anywhere in the world'. The GPS receiver lets the ESP32 know its position. But without connection to the WiFi , this won't work.
I hope there is something that escapes my notice. But I am afraid, that KIMMSUSU's unanswered comment is actually pointing to the same issue. Maybe you could create another project, with some SIM card breakout board.

Exactly why I came to this project... I wonder how they are keeping the gps position updated when out of wifi, this could be interesting... only to find out that the project doesn't do this. It is effectively useless unless it is within range of wifi that it has access to. I can see that the last known location might be transmitted through the phone of the vehicle driver, if the phone was in hotspot mode and the esp32 was connected, but otherwise your gps position may be 100% accurate, but that doesn't mean you have access to that information. Cool project, but very disappointed that the implementation misses the mark.

I simply needed to thank you very much once more. I am not sure what I could possibly have handled without the actual tips contributed by you on that subject. This has been a very intimidating matter for me personally, but taking a look at your skilled strategy you managed the issue made me to leap for joy. I will be happy for your guidance and in addition hope that you find out what a great job you have been providing teaching the mediocre ones by way of your websites. I am certain you've never encountered all of us.

I intended to create you this very little observation so as to thank you so much as before relating to the lovely guidelines you have discussed on this site. It's quite pretty generous with you to present freely exactly what some people would have offered for sale for an electronic book to make some profit for themselves, specifically considering that you could have tried it in case you decided. These good tips in addition served to be the fantastic way to comprehend some people have the same zeal similar to my very own to learn much more on the subject of this problem. Certainly there are numerous more enjoyable opportunities up front for folks who find out your site.

Thanks for all of the hard work on this site. Kim really likes going through investigations and it is easy to see why. I know all relating to the powerful manner you render insightful items by means of your blog and even invigorate contribution from other ones on the point and our own princess is now discovering a lot of things. Enjoy the rest of the new year. You have been doing a fabulous job.

Thank you a lot for providing individuals with an extremely nice chance to read from this site. It is often so useful and stuffed with a lot of fun for me personally and my office peers to visit your web site at the very least thrice every week to learn the latest things you have. And of course, I am just always contented with your awesome strategies served by you. Selected 2 areas on this page are undeniably the finest I've ever had.

I and my buddies were found to be checking the good tactics located on your web blog while suddenly got a terrible suspicion I never expressed respect to you for those tips. All the boys had been as a result very interested to read them and have really been enjoying these things. Thanks for simply being really kind and then for settling on these kinds of brilliant information millions of individuals are really desirous to learn about. Our honest regret for not expressing gratitude to you sooner.

Thanks a lot for giving everyone remarkably pleasant possiblity to read critical reviews from this site. It's usually so lovely plus jam-packed with a great time for me personally and my office mates to search your site at least 3 times in one week to see the fresh items you have got. And lastly, I'm so certainly fascinated with all the staggering ideas you serve. Selected 4 areas on this page are certainly the simplest I have had.

I truly wanted to construct a simple remark to thank you for these stunning ideas you are placing on this website. My particularly long internet search has at the end of the day been honored with high-quality concept to exchange with my contacts. I would suppose that most of us readers actually are very fortunate to live in a fine network with very many lovely people with interesting solutions. I feel pretty happy to have discovered your entire webpages and look forward to really more awesome moments reading here. Thanks once more for everything.

I intended to send you a tiny remark to finally thank you yet again with your lovely techniques you've shown above. This has been simply tremendously open-handed with you to supply unhampered what a few people would've distributed for an e-book to generate some money for themselves, mostly since you could have tried it if you considered necessary. Those strategies also worked as a fantastic way to be aware that other people online have similar interest just like my very own to understand a great deal more when it comes to this issue. I'm sure there are a lot more enjoyable periods in the future for those who go through your blog post.

I happen to be writing to make you understand what a excellent experience my wife's daughter gained going through your blog. She mastered several things, which include what it is like to have a wonderful giving spirit to have many more with no trouble grasp various impossible issues. You truly surpassed our desires. I appreciate you for presenting such important, trusted, explanatory as well as cool tips on this topic to Gloria.

I precisely had to thank you so much yet again. I do not know what I could possibly have sorted out without the aspects shown by you relating to that theme. It absolutely was a very challenging difficulty in my position, nevertheless taking note of this professional avenue you dealt with the issue took me to weep with happiness. I am happier for your support and thus wish you really know what an amazing job you're accomplishing educating people today through the use of your web site. I am sure you haven't encountered any of us.

I am writing to let you understand what a terrific discovery my cousin's princess went through reading your webblog. She discovered a wide variety of things, with the inclusion of what it's like to possess an ideal teaching style to make many people really easily grasp selected grueling subject matter. You truly surpassed visitors' desires. Many thanks for coming up with such priceless, trustworthy, edifying and in addition easy guidance on that topic to Ethel.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.