IoT based Vehicle Tracking System using NodeMCU and Arduino IDE

IOT based Vehicle Tracking System using NodeMCU

Nowadays, security is the utmost concern for us, whether it is related to our assets like vehicles, homes or our children. In this case, GPS tracker devices are very useful. They can be easily used to track the real-time position of the vehicles or assets in case of any emergency like theft, accidents, etc. They can also be kept with children to track their location.

 

Here we are building the same GPS tracking device to monitor the real-time location of the vehicle from anywhere. Here ThingSpeak IoT cloud will be used to store the history of locations from where the vehicle has traversed. We previously interfaced with GPS with NodeMCU ESP8266 and displayed the location coordinates on a webpage. Here in this IoT Vehicle Tracking System, we will also display a link on the webpage which will take the user to Google map showing the vehicle location.

 

Components Required

  • ESP8266 NodeMCU - 1
  • NE06M GPS Receiver - 1
  • 16*2 LCD - 1
  • 16*2 LCD I2C module - 1
  • Breadboard
  • Connectors
  • Power supply

 

NEO6M GPS Module

NEO6M GPS Module

The NEO-6M GPS module is a popular GPS receiver with a built-in ceramic antenna, which provides a strong satellite search capability. This receiver has the ability to sense locations by tracking up to 22 satellites and identifies locations anywhere in the world. With the on-board signal indicator, we can monitor the network status of the module. It has a data backup battery so that the module can save the data when the main power is shut down accidentally.

 

The core heart inside the GPS receiver module is the NEO-6M GPS chip from u-blox. It can track up to 22 satellites on 50 channels and have a very impressive sensitivity level which is -161 dBm. This 50-channel u-blox 6 positioning engine boasts a Time-To-First-Fix (TTFF) of under 1 second. This module supports the baud rate from 4800-230400 bps and has the default baud of 9600.

 

Features: 

  • Operating voltage: (2.7-3.6)V DC
  • Operating Current: 67 mA
  • Baud rate: 4800-230400 bps (9600 Default)
  • Communication Protocol: NEMA
  • Interface: UART
  • External antenna and built-in EEPROM.

 

Pinout of GPS module: 

GPS Module Pinout

VCC: Input voltage pin of Module

GND: Ground pin

RX, TX: UART communication pins with Microcontroller

 

Vehicle Tracking System Circuit Diagram

Circuit diagram for this IOT based vehicle monitoring system is given below:

IoT based Vehicle Tracking System Circuit Diagram

Vehicle Tracking System using NodeMCU

 

Setup ThingSpeak Account for IoT Vehicle Tracking System

After successful completion of hardware as per the above circuit diagram, now its time to set up the IoT platform, where the GPS coordinates are stored. Here we are using ThingSpeak to store the latitude and longitude data on the cloud and graphically visualize the GPS data.

 

ThingSpeak is a very popular IoT based cloud platform and we built many IoT based projects using ThingSpeak previously. Below are the steps for setting up the ThingSpeak cloud.

 

Step 1: Sign up for ThingSpeak

First, go to https://thingspeak.com/ and create a new free Mathworks account if you don’t have a Mathworks account before.

 

Step 2: Sign in to ThingSpeak

Sign in to ThingSpeak using your credentials and click on “New Channel”. Now fill up the details of the project like Name, Field names, etc. Here we have to create two field names such as Latitude and Longitude. Then click on “Save channel”.

ThingSpeak Sign in

 

Step 3: Record the Credentials

Select the created channel and record the following credentials.

  • Channel ID, which is at the top of the channel view.
  • Write an API key, which can be found on the API Keys tab of your channel view.

ThingSpeak ID

 

Programming NodeMCU for Vehicle Tracking System

After the successful completion of the Hardware connections and ThingSpeak setup, now it’s time to program the ESP8266 NodeMCU. The stepwise explanation of the complete code is given below.

To upload code into NodeMCU using Arduino IDE, follow the steps below:

1. Open Arduino IDE, then go to File–>Preferences–>Settings.

Arduino IDE Settings

 

2. Type https://arduino.esp8266.com/stable/package_esp8266com_index.json in the ‘Additional Board Manager URL’ field and click ‘Ok’.

NodeMCU Programming

 

3. Now go to Tools > Board > Boards Manager. In the Boards Manager window, Type ESP8266 in the search box, select the latest version of the board and click on install.

Arduino IDE Programming

 

4. After installation is complete, go to Tools ->Board -> and select NodeMCU 1.0(ESP-12E Module). Now you can program NodeMCU with Arduino IDE.

 

After setting up NodeMCU in Arduino IDE, upload the code into NodeMCU. Complete code is given at the end of this tutorial; here we are explaining the code step by step.

 

Start the code by including all the required library files in the code like ESP8266WiFi.h for ESP8266 board, LiquidCrystal_I2C.h for LCD, Wire.h for I2C communication, etc.

 

Here, ThingSpeak.h library is added to use the ThingSpeak platform with NodeMCU and TinyGPS++.h The library is used to get the GPS coordinates using the GPS receiver module. This library can be downloaded from here.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include<LiquidCrystal_I2C.h>
#include<Wire.h>

 

For using the I2C module for 16x2 Alphanumeric LCD, configure it using the LiquidCrystal_I2C class. Here we have to pass the address, row, and column number which are 0x27, 16, and 2 respectively in our case.

LiquidCrystal_I2C lcd(0x27, 16, 2);

 

Now, declare the network credentials- i.e. SSID and password. It is required to connect the NodeMCU to the internet.

const char* ssid     = "admin";
const char* password = "12345678";

 

Now, declare the connection pins of the GPS module and it’s the default baud rate, which is 9600 in our case.

static const int RX= D6, TX= D7;
static const uint32_t GPSBaud = 9600;

 

Next, declare the ThingSpeak account credentials such as the channel number and write API which was recorded earlier.

unsigned long ch_no = 9XXXX;
const char * write_api = "ZWWWDXXXXXXXXX";

 

Then declare the objects for TinyGPSPlus and WiFiClient class. For using WiFiServer properties, the server object is defined with Port number 80.

TinyGPSPlus gps;
WiFiClient  client;
WiFiServer server(80);
SoftwareSerial soft(RX, TX);

 

Inside setup(), declare all the input pins and output pins. Then print a welcome message on the LCD which will be displayed during the initialization of the project.

  Wire.begin(D2, D1);
  lcd.begin(16, 2);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("   IOT BASED       ");
  lcd.setCursor(0, 1);
  lcd.print("VEHICLE TRACKING   ");
  delay(2000);
  lcd.clear();

 

To connect NodeMCU to the internet, call WiFi.begin and pass network SSID and password as its arguments. Check for the successful network connection using WiFi.status() and after a successful connection, print a message on LCD with IP address.

  WiFi.begin(ssid, password);
  server.begin();
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    lcd.setCursor(0, 0);
    lcd.print("WiFi connecting...          ");
  }
  lcd.setCursor(0, 0);
  lcd.print("WiFi connected          ");
  lcd.setCursor(0, 1);
  lcd.print(WiFi.localIP());

 

Then connect to the ThingSpeak platform, using saved credentials. For this ThingSpeak.begin is used.

ThingSpeak.begin(client);

 

Inside loop(), encode () is used to ensure a valid GPS sentence is received. When encode () returns “true”, a valid sentence has just changed the TinyGPS object’s internal state. Here two functions namely displaydata() and displaywebpage() are called, when encode() returns true.

while (soft.available() > 0)
    if (gps.encode(soft.read()))
    {
      displaydata();
      displaywebpage();
    }
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("GPS Connection Error!!"));
    while (true);
  }

 

Inside displaydata() function, isValid() method is used to ensure a valid latitude and longitude reception and they are stored in respective variables. Then to send these data to ThingSpeak, setField() method is used to set the fields and the writeFields() method is used to send these data to the cloud.

void displaydata()
{
  if (gps.location.isValid())
  {
    double latitude = (gps.location.lat());
    double longitude = (gps.location.lng());
    latitude_data= (String(latitude, 6));
    longitude_data= (String(longitude, 6));
    ThingSpeak.setField(1, latitude_data);
    ThingSpeak.setField(2, longitude_data);
    ThingSpeak.writeFields(ch_no, write_api);
    delay(20000);
  }
  else
  {
    Serial.println(F("Data error!!!"));
  }
}

 

Inside displaywebpage(), a HTML code is written which is sent to Client-side in string format using client.print(). This HTML code contains a hyperlink which on clicking, takes you to the Google maps pointing the location of a tracked vehicle.

{
    WiFiClient client = server.available();
    if (!client)
    {
      return;
    }
    String page = "<html><center><p><h1>Real Time Vehicle Tracking using IoT</h1><a style=""color:RED;font-size:125%;"" href=""http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
    page += latitude_data;
    page += "+";
    page += longitude_data;
    page += ">Click here For Live Location</a> </p></center></html>";
    client.print(page);
    delay(100);
}

IoT Vehicle Tracking System Map

 

Testing of Vehicle Monitoring System using IoT

After connecting the hardware and uploading the code, just power on the circuit and you will see some notifications messages on LCD. Now open the web browser and open type the IP address of the NodeMCU. There will be a link that will take you to the google map with the current location of the vehicle as shown in the above pictures. The IP address of NodeMCU is displayed on LCD after Wi-Fi is connected successfully. Complete working is demonstrated in the video given below.

 

At the same time ThingSpeak will also log the Latitude and Longitude of the vehicle and present them in the graphs as shown below:

IoT based Vehicle Tracking System Graph

Complete code and video for this Vehicle Tracking System using IoT are given below.

Code

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include<LiquidCrystal_I2C.h>
#include<Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
static const int RX= D6, TX= D7;
static const uint32_t GPSBaud = 9600;
const char* ssid     = "admin";//Replace with Network SSID
const char* password = "12345678";//Replace with Network Password
unsigned long ch_no = 12345;//Replace with Thingspeak Channel number
const char * write_api = "ZS6XXXXXXXXXXXX";//Replace with Thingspeak write API
TinyGPSPlus gps;
WiFiClient  client;
WiFiServer server(80);
SoftwareSerial soft(RX, TX);
String latitude_data;
String longitude_data;
void setup()
{
  Wire.begin(D2, D1);
  lcd.begin(16, 2);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("   IOT BASED       ");
  lcd.setCursor(0, 1);
  lcd.print("VEHICLE TRACKING   ");
  delay(2000);
  lcd.clear(); 
  Serial.begin(115200);
  soft.begin(GPSBaud);
  WiFi.begin(ssid, password);
  server.begin();
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    lcd.setCursor(0, 0);
    lcd.print("WiFi connecting...          ");
  }
  lcd.setCursor(0, 0);
  lcd.print("WiFi connected          ");
  lcd.setCursor(0, 1);
  lcd.print(WiFi.localIP());
  ThingSpeak.begin(client);
}
void loop()
{
  while (soft.available() > 0)
    if (gps.encode(soft.read()))
    {
      displaydata();
      displaywebpage();
    }
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("GPS Connection Error!!"));
    while (true);
  }
}
void displaydata()
{
  if (gps.location.isValid())
  {
    double latitude = (gps.location.lat());
    double longitude = (gps.location.lng());
    latitude_data= (String(latitude, 6));
    longitude_data= (String(longitude, 6));
    ThingSpeak.setField(1, latitude_data);
    ThingSpeak.setField(2, longitude_data);
    ThingSpeak.writeFields(ch_no, write_api);
    delay(20000);
  }
  else
  {
    Serial.println(F("Data error!!!"));
  }
}
void displaywebpage()
{
    WiFiClient client = server.available();
    if (!client)
    {
      return;
    }
    String page = "<html><center><p><h1>Real Time Vehicle Tracking using IoT</h1><a style=""color:RED;font-size:125%;"" href=""http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
    page += latitude_data;
    page += "+";
    page += longitude_data;
    page += ">Click here For Live Location</a> </p></center></html>";
    
    client.print(page);
    delay(100);
}

Video

28 Comments

Benefits of Using a Weight Vest –iamazonsurmountwayweightedvest_2021 What You're Missing Out On,When you’re wearing a weight vest it increases the intensity that helps to burn fat very fast. Although running or walking on a treadmill seems like it can burn calories, adding weight to your body is more effective to burn fat.As you can see, doing high intensity work outs that involves resistance is the fastest and most effective way in fat burning and muscle building.A study shows that doing a standing workout while wearing a weight vest can increase the burning of the calorie by 12 per cent.

I needed to compose you the bit of word to help thank you once again for your personal pleasing secrets you've provided on this website. It was quite incredibly generous with people like you to convey freely what exactly a number of us would've marketed for an e book to end up making some dough for their own end, most notably given that you might well have tried it if you ever decided. These things also served to provide a great way to understand that many people have the identical dreams similar to my very own to realize significantly more concerning this condition. I am sure there are numerous more pleasant opportunities ahead for individuals that look over your blog.

I intended to post you the very little observation to be able to say thanks the moment again on the stunning tactics you've documented at this time. It was shockingly open-handed of people like you to make extensively all most of us could possibly have supplied as an ebook to make some bucks for themselves, and in particular since you might have tried it in case you desired. Those concepts additionally worked to become a easy way to comprehend many people have similar eagerness the same as my very own to learn a little more when it comes to this issue. Certainly there are a lot more pleasant periods in the future for those who discover your site.

I simply desired to thank you very much once more. I do not know the things I might have taken care of without the actual information shared by you directly on such a problem. It seemed to be an absolute distressing matter in my circumstances, but taking note of the very well-written tactic you managed it forced me to jump over fulfillment. I am happy for your service as well as have high hopes you find out what a great job you are providing educating the others thru your web site. More than likely you have never encountered all of us.

I needed to post you one tiny note to help say thank you the moment again about the amazing concepts you've shared in this case. This is quite strangely open-handed with you to make unhampered all many people might have offered for sale for an ebook to earn some bucks for their own end, principally seeing that you could possibly have done it if you ever desired. The principles in addition acted like a great way to recognize that other people have the same dream just as mine to see somewhat more in regard to this matter. I'm sure there are numerous more pleasant times up front for individuals who scan through your site.

I am also commenting to let you know what a cool discovery my cousin's princess gained reading your site. She figured out too many things, with the inclusion of how it is like to have a very effective giving spirit to let other people effortlessly master a number of problematic topics. You really exceeded my desires. Many thanks for displaying such insightful, healthy, informative and in addition cool thoughts on your topic to Emily.

I wanted to post you the tiny remark in order to give thanks again relating to the awesome pointers you have shown in this case. It has been quite tremendously generous of people like you to offer unreservedly what a few individuals might have sold for an e book in order to make some profit on their own, especially since you could possibly have tried it in case you decided. These techniques likewise acted to be the good way to be sure that other people online have the identical passion the same as my personal own to find out many more in respect of this issue. I think there are thousands of more enjoyable opportunities up front for individuals who read your blog post.

I wanted to write a quick note in order to appreciate you for the pleasant facts you are giving out here. My considerable internet investigation has finally been compensated with sensible knowledge to exchange with my partners. I 'd assert that many of us website visitors actually are quite fortunate to be in a very good community with very many brilliant people with great opinions. I feel rather blessed to have encountered your website and look forward to many more exciting moments reading here. Thank you once more for a lot of things.

I and my pals have already been reading the great advice on your website while at once I got a horrible suspicion I never expressed respect to the site owner for those tips. All of the women had been certainly joyful to read through them and already have simply been loving these things. Many thanks for getting quite considerate and for obtaining certain smart subject matter millions of individuals are really desirous to be aware of. Our honest regret for not expressing gratitude to sooner.

I and also my friends came digesting the excellent information on your web site and then unexpectedly came up with a horrible suspicion I had not thanked the website owner for those tips. All the young boys were totally excited to read through them and have in effect certainly been enjoying them. Thanks for indeed being quite accommodating and for obtaining variety of decent useful guides millions of individuals are really desirous to be informed on. My honest apologies for not expressing gratitude to sooner.

Thanks so much for giving everyone an exceptionally breathtaking possiblity to read critical reviews from this site. It's always very pleasing and packed with a great time for me and my office mates to search your site a minimum of 3 times weekly to read the newest secrets you will have. And of course, I am actually astounded for the extraordinary tactics you serve. Some 4 facts on this page are rather the most efficient we have all had.

I actually wanted to construct a word so as to express gratitude to you for some of the lovely instructions you are posting on this website. My particularly long internet look up has finally been paid with useful suggestions to share with my pals. I would declare that many of us visitors are extremely blessed to dwell in a wonderful website with very many special individuals with very beneficial ideas. I feel truly lucky to have discovered your webpage and look forward to tons of more brilliant times reading here. Thanks once more for a lot of things.

A lot of thanks for all of the hard work on this blog. My niece really loves doing research and it is simple to grasp why. I hear all concerning the powerful means you offer very important ideas via this web blog and therefore encourage contribution from some other people about this content then our favorite princess has always been discovering a lot of things. Take advantage of the rest of the year. You're the one performing a first class job.

I must express some thanks to you for rescuing me from this circumstance. Just after surfing throughout the search engines and seeing advice that were not beneficial, I believed my entire life was well over. Living minus the strategies to the difficulties you have solved as a result of this guide is a crucial case, as well as the kind which may have adversely affected my entire career if I had not noticed your blog post. Your personal expertise and kindness in handling a lot of stuff was very useful. I'm not sure what I would've done if I had not come upon such a thing like this. It's possible to now relish my future. Thanks so much for this impressive and results-oriented guide. I won't be reluctant to propose your web site to anyone who requires support about this subject matter.

My wife and i ended up being quite relieved that Louis managed to complete his investigation via the ideas he was given from your own web pages. It is now and again perplexing just to happen to be releasing techniques many others could have been selling. So we already know we have the blog owner to thank for this. The entire illustrations you have made, the easy web site menu, the friendships your site help engender - it is mostly overwhelming, and it is assisting our son in addition to the family imagine that this matter is pleasurable, which is unbelievably vital. Thanks for the whole thing!

I wish to point out my appreciation for your generosity for those who really want help with your niche. Your real commitment to getting the message all through was particularly functional and have really enabled associates like me to reach their pursuits. Your entire warm and helpful hints and tips implies this much a person like me and especially to my fellow workers. Many thanks; from all of us.

I truly wanted to make a brief word to be able to say thanks to you for the lovely pointers you are posting on this website. My long internet research has at the end been rewarded with sensible strategies to exchange with my friends. I 'd declare that we site visitors actually are quite endowed to live in a useful place with very many special individuals with great suggestions. I feel pretty lucky to have come across your web pages and look forward to so many more exciting times reading here. Thank you again for everything.

Thank you so much for providing individuals with such a pleasant opportunity to read in detail from this blog. It really is so pleasant and also full of a great time for me and my office acquaintances to search your website at a minimum thrice per week to read through the latest guides you have got. And of course, we are actually satisfied with the wonderful creative concepts you serve. Some 2 ideas in this post are certainly the most effective I have ever had.

Thank you a lot for giving everyone an extraordinarily splendid chance to check tips from here. It can be very useful and as well , packed with a lot of fun for me and my office fellow workers to search your site at minimum thrice weekly to read through the fresh tips you have. And lastly, I'm usually contented concerning the magnificent methods you serve. Selected 4 areas in this posting are really the best we have had.

I am commenting to let you understand what a awesome experience my wife's princess went through browsing your webblog. She came to understand such a lot of issues, most notably what it's like to possess an incredible coaching mood to let certain people clearly gain knowledge of a variety of very confusing things. You really exceeded people's expected results. Thanks for offering those warm and friendly, trustworthy, revealing and also easy thoughts on that topic to Sandra.

My wife and i got quite relieved when Emmanuel managed to deal with his inquiry through your precious recommendations he came across while using the site. It is now and again perplexing to just happen to be offering instructions some people could have been trying to sell. And now we already know we've got the website owner to thank for this. Most of the explanations you made, the straightforward website navigation, the friendships you can aid to promote - it's everything spectacular, and it's facilitating our son in addition to us consider that this theme is interesting, and that is extraordinarily important. Thank you for all!

I definitely wanted to jot down a brief remark to be able to say thanks to you for these awesome ideas you are writing on this site. My time-consuming internet investigation has at the end been honored with extremely good information to talk about with my companions. I 'd suppose that most of us readers actually are undeniably fortunate to be in a fabulous site with so many wonderful individuals with great ideas. I feel extremely fortunate to have used your webpage and look forward to some more exciting moments reading here. Thanks once more for a lot of things.

My wife and i were fulfilled that Raymond managed to finish up his preliminary research via the ideas he had in your web page. It's not at all simplistic to simply find yourself giving for free tips and tricks which usually other people may have been trying to sell. We know we have the blog owner to thank for that. The most important illustrations you've made, the simple blog menu, the relationships you make it possible to create - it's most impressive, and it is letting our son in addition to our family reckon that that article is excellent, and that's very mandatory. Thanks for the whole thing!

I wanted to construct a word to say thanks to you for these fabulous tips and tricks you are giving out on this website. My prolonged internet look up has now been paid with brilliant details to talk about with my company. I would express that many of us site visitors actually are undoubtedly lucky to exist in a fabulous place with many special people with useful points. I feel quite blessed to have come across the weblog and look forward to tons of more thrilling moments reading here. Thanks a lot once more for all the details.

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.