If you want to safeguard your belongings like your motorbike or your car then this GPS tracker might help you with tracking your device and getting live location as well as directions to reach out there. You can install it anywhere by just adding a Li-po battery. The smaller size makes it flexible and easy to hide. GPS stands for Global Positioning System. This will use the internet to get the location hence you will require an internet connection that is connected to NodeMCU interfaced with the NE0-6MV2 GPS module.
What is NodeMCU ESP8266?
NodeMCU is an open-source firmware and also a development board specially made for IoT-based usage and applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems, flexible usage, and works on 5volt. NodeMCU has 128 KB RAM and 4MB of Flash memory to store data. This board supports RTOS and operation at 80MHz to 160 MHz adjustable clock frequency. Its high processing power with in-built Wi-Fi / Bluetooth makes it ideal for IoT applications.
ESP8266 Datasheet
Pin |
Name |
Description |
Power |
Micro-USB, 3.3V, GND, Vin |
Micro-USB port: NodeMCU is powered through the USB port
3.3V: 3.3V can be supplied to this pin to power the NodeMCU
GND: Ground pin
Vin: External Power Supply |
Control Pins |
EN, RST |
The pin and the button resets the board |
Analog Pin |
A0 |
Used to measure analog voltage in the range of 0-3.3V |
GPIO Pins |
GPIO1 to GPIO16 |
NodeMCU has 16 general purpose input-output pins. |
SPI Pins |
SD1, CMD, SD0, CLK |
NodeMCU has 4 pins available for SPI communication. |
UART Pins |
TXD0, RXD0, TXD2, RXD2 |
NodeMCU has two UART interfaces, UART0 (RXD0 & TXD0) and UART1 (RXD1 & TXD1). UART1 is used to upload the firmware or program. |
I2C Pins |
|
NodeMCU has I2C functionality support but due to the internal functionality of these pins, you have to find which pin is I2C. |
What is NEO-6MV2 GPS module?
The NEO-6MV2 is a GPS (Global Positioning System) module that is used for navigation and fetching the current location. This module provides its location on earth and gives its output which is the longitude and latitude of its current position. This position can be seen over the web using the IP address or via a mobile application.
The module has four output pins which are given below.
Pin Name |
Description |
VCC |
Positive power pin (3.3V to 3.6V) |
RX |
UART receiver pin |
TX |
UART transmitting pin |
GND |
Connected to Ground |
Components Required
- Node MCU ESP8266
- NE06MV2 GPS module
- Connecting wires/jumpers
Circuit diagram for GPS Tracker
In the above circuit diagram, Vcc is connected to the 3v3 pin of the NodeMCU board. The GND pin is connected to GND. The D1 pin of the NodeMCU board is connected to the RX pin of the GPS module. Similarly, the D2 pin of the NodeMCU board is connected to the TX pin of the GPS module.
Arduino Code
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
TinyGPSPlus gps; // The TinyGPS++ object
SoftwareSerial ss(4, 5); // The serial connection to the GPS device
const char* ssid = "your wifi name";
const char* password = "your wifi password";
float latitude , longitude;
int year , month , date, hour , minute , second;
String date_str , time_str , lat_str , lng_str;
int pm;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
ss.begin(9600);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
while (ss.available() > 0)
if (gps.encode(ss.read())) {
if (gps.location.isValid()) {
latitude = gps.location.lat();
lat_str = String(latitude , 6);
longitude = gps.location.lng();
lng_str = String(longitude , 6);
}
if (gps.date.isValid()) {
date_str = "";
date = gps.date.day();
month = gps.date.month();
year = gps.date.year();
if (date < 10)
date_str = '0';
date_str += String(date);
date_str += " / ";
if (month < 10)
date_str += '0';
date_str += String(month);
date_str += " / ";
if (year < 10)
date_str += '0';
date_str += String(year);
}
if (gps.time.isValid()) {
time_str = "";
hour = gps.time.hour();
minute = gps.time.minute();
second = gps.time.second();
minute = (minute + 30);
if (minute > 59) {
minute = minute - 60;
hour = hour + 1;
}
hour = (hour + 5) ;
if (hour > 23)
hour = hour - 24;
if (hour >= 12)
pm = 1;
else
pm = 0;
hour = hour % 12;
if (hour < 10)
time_str = '0';
time_str += String(hour);
time_str += " : ";
if (minute < 10)
time_str += '0';
time_str += String(minute);
time_str += " : ";
if (second < 10)
time_str += '0';
time_str += String(second);
if (pm == 1)
time_str += " PM ";
else
time_str += " AM ";
}
}
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n <!DOCTYPE html> <html> <head> <title>GPS Interfacing with NodeMCU</title> <style>";
s += "a:link {background-color: YELLOW;text-decoration: none;}";
s += "table, th, td {border: 1px solid black;} </style> </head> <body> <h1 style=";
s += "font-size:300%;";
s += " ALIGN=CENTER> GPS Interfacing with NodeMCU</h1>";
s += "<p ALIGN=CENTER style=""font-size:150%;""";
s += "> <b>Location Details</b></p> <table ALIGN=CENTER style=";
s += "width:50%";
s += "> <tr> <th>Latitude</th>";
s += "<td ALIGN=CENTER >";
s += lat_str;
s += "</td> </tr> <tr> <th>Longitude</th> <td ALIGN=CENTER >";
s += lng_str;
s += "</td> </tr> <tr> <th>Date</th> <td ALIGN=CENTER >";
s += date_str;
s += "</td></tr> <tr> <th>Time</th> <td ALIGN=CENTER >";
s += time_str;
s += "</td> </tr> </table> ";
if (gps.location.isValid()) {
s += "<p align=center><a style=""color:RED;font-size:125%;"" href=""http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=";
s += lat_str;
s += "+";
s += lng_str;
s += """ target=""_top"">Click here!</a> To check the location in Google maps.</p>";
}
s += "</body> </html> \n";
client.print(s);
delay(100);
}
Points to Remember
const char* ssid = "your wifi name";
const char* password = "your wifi password";
Find the above lines from the code and replace your wifi name and password credentials. This is just because Node MCU needs to connect to the internet.
#include <TinyGPS++.h>
The above one is header file. You have to install library of TinyGPS+ libraries.
#include <ESP8266WiFi.h>
The above one is also a header file. You have to install the library of ESP8266 into the library folder.
The Above code will have the following output when you will enter your IP address in the address bar which is shown below. You can find your IP address in the serial monitor of Arduino IDE software when you will upload your code.
On clicking the link you will also get the current location on google map.
Troubleshooting
Circuit not working?Ensure that all the connections you have made should be according to the circuit diagram. Check for short circuits.
Not getting Longitude and latitude values?If so, then take your GPS module near a window or outside as it will have to connect with the satellite. So it needs some open environment to fetch data and communication.
Code not uploading?If so, then remove the TX and RX pins from the module and then again try uploading the code. It will get uploaded.
Showing error of TinyGPS++ library not installed?You have to install the tinyGPS++ library into the library folder of your Arduino IDE. You can find these libraries on the GitHub website. Also, you have to include ESP8266 libraries.