IOT

GPS+GSM Based Vehicle Tracking System using Arduino

In this project, we’ll learn how to use Arduino to create a GPS and GSM-based vehicle tracking system. The majority of car monitoring systems on the market are prohibitively expensive. As a result, I chose to create my own tracking system. The vehicle tracking system will provide you with the location of the vehicle, as well as the Google map coordinates, to your mobile phone. You can request the position at any moment and view it on Google Maps if you have it loaded on your phone.

Proposed System

This is a less expensive alternative to a two-way GPS communication system, which communicates with GPS satellites in both directions. Only one GPS device is used in this project, and two-way communication is accomplished via a GSM modem. A GSM modem with a 2G SIM card is available.

GPS Vehicle Tracking System Arduino

I need to choose a low-power GSM and GPS module for this project. As a result, I chose the A9G GSM/GPRS/GPS Module. The device is extremely compact and portable, and it runs on a single 3.7V Lithium-Ion battery. The board features an Atmel 32-bit ATSAMD21 controller that can be programmed using the Arduino IDE. You can also construct this project with an Arduino UNO Board with a Neo-6M GPS Module and a SIM 800/900 GSM Module. However, this will increase the device’s size. This Arduino GPS & GSM Based Vehicle Tracking System will be discussed in depth. You can use the SIM7600 4G LTE modem to construct a GPS tracker with a 4G internet connection instead of a 2G connection.

Components Required

Because of its small size, low power consumption, and quick response, I prefer the first method.

  • Maduino Zero Board
  • 3.7V 1000 mah Lithium-Ion Battery

If you wish to create this GPS tracker with Arduino the second way, you can buy the components individually and put them together on a breadboard or PCB board. 

  • Arduino UNO R3/ Nano or Any other Arduino Board
  • 16X2 LCD Display
  • SIM800/900 GSM Module
  • Neo-6M GPS Module
  • Potentiometer-10K
  • Connecting wire
  • Breadboard

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.

Maduino Zero A9G GPRS/GPS Board

This is a low-power A9G GSM+GPS+GPRS Module integrated with 32-bit Atmel’s SAMD21 Microcontroller. Its front side and backside look something like this.

Maduino Zero A9G GSM/GPRS+GPS Module Board

Ai-Thinker. is the company behind the A9G GSM GPS Module. The module can be configured and powered via a micro USB port and a 3.7V Lithium-Ion battery. It features a switch that allows you to turn it on and off. There are digital input/output pins that can be utilized to link additional modules or sensors.

Arduino has an 8-bit controller but it has a 32-bit Atmel ATSAMD21G18 controller, which makes the device super fast. To manage the extra voltage, it has a voltage regulator IC. In the same way, there are two antennas: one for GSM and the other for GPS. Because of its superior design, the signal problem is not seen in this module. A micro sim can be inserted here. Remember that while this is a 2G modem, only 2G Sims may be used due to the frequency band. There’s also a Micro-SD slot. You can also save the data in text format on an SD Card.

A9G GPS GSM

There is no need for an external DC jack or a more powerful power supply for the board. A 3.7V, 100mah Lithium-Ion Battery can be used to power it. The module has two battery ports, one for charging and the other for powering the battery. To turn on the device, slide the switch once the battery is attached. There are two LEDs that show the status of the power.

Makerfabs, one of China’s greatest startup firms, constructed and built this board. The following link will take you directly to a page where you can buy this board.

https://makerfabs.com/maduino-zero-a9g.html

If you wish to understand the basics of interfacing and using AT commands with the A9G Module, check out the prior projects listed below. You can also learn about the GPS Tracker Project, as well as the SMS Project and Cellular IoT Connectivity.

1. Basic A9G GPRS/GSM Module Arduino Tutorial: Check Here

2. GPS Tracker using Arduino & A9G: Check Here

3. Cellular IoT using Arduino & A9G: Check Here

Now let us move towards our main project, i.e. GPS+GSM Based Vehicle Tracking System using Arduino.

GPS+GSM Based Vehicle Tracking System using Arduino

Except for connecting the battery, no further external gear is required. All of the documentation has already been covered. Let us now go to the Arduino IDE setup section.

There is no pre-installed support for the SAMD Board in the Arduino IDE. As a result, you must first add the Board to the Arduino IDE. So, in the board manager, look for Arduino Zero.

  • So, here’s the ARM Cortex 32-bit Board. This board can be installed.
  • Connect the micro USB cable to the Maduino Zero Board under the hardware section. Connect the other end to a USB port on your computer.
  • Go to the tools section and look for the Arduino SAMD Board. Select the Arduino Zero Native USB Port from the list. Select the com port from the list as well.

Source Code/Program

As a result, you can view the program here. It differs from other GSM GPS Modules and Arduino Boards in a few ways. The AT command AT+GPS=1 activates the board’s GPS. AT+LOCATION =2 will also return the GPS location as a Latitude and Longitude Code.

Copy and paste the entire code onto the Arduino Zero board.

#include<string.h>

#define DEBUG true

int PWR_KEY = 9;
int RST_KEY = 6;
int LOW_PWR_KEY = 5;

String msg = String(“”);
int SmsContentFlag = 0;
String mob;
String loct;
void setup()
{
pinMode(PWR_KEY, OUTPUT);
pinMode(RST_KEY, OUTPUT);
pinMode(LOW_PWR_KEY, OUTPUT);
digitalWrite(RST_KEY, LOW);
digitalWrite(LOW_PWR_KEY, HIGH);
digitalWrite(PWR_KEY, HIGH);

// String msg = String(“”);
// int SmsContentFlag = 0;

SerialUSB.begin(115200);
Serial1.begin(115200);
//modulePowerOn();
delay(2000);
SerialUSB.println(“Checking Module…”);
int i = 1;
String res;
while (i) {
Serial1.println(“AT”);
while (Serial1.available() > 0) {
if (Serial1.find(“OK”))
i = 0;
}
delay(500);
}
SerialUSB.println(“Module Connected”);
//GprsTextModeSMS();
SerialUSB.print(“Text Mode: “);
i = 1;
while (i) {
Serial1.println(“AT+CMGF=1\r”);
while (Serial1.available() > 0) {
if (Serial1.find(“OK”))
i = 0;
}
delay(500);
}
SerialUSB.println(“ON”);
Serial1.println(“AT+GPS=1”);
SerialUSB.println(“GPS Intializing…”);
delay(5000);
SerialUSB.println(“GPS Initialized”);
SerialUSB.flush();
i = 1;
String str;
while (i) {
Serial1.println(“AT+LOCATION=2”);
delay(100);
while (Serial1.available() <= 0);
if (Serial1.find(“AT+LOCATION=2”)) {
str = Serial1.readString();
//SerialUSB.println(str);
i = 0;
}
delay(500);
}
loct = str.substring(4, 23);
SerialUSB.print(“Location: “);
SerialUSB.println(loct);
//while(1);
SerialUSB.println(“Send sms to get the location”);
}


void loop()
{
char SerialInByte;

if (Serial1.available())
{
//char SerialInByte;
SerialInByte = (unsigned char)Serial1.read();
if ( SerialInByte == 13 ) //0x0D
{
ProcessGprsMsg();
}
if ( SerialInByte == 10 )
{
}
else
{
//EN: store the current character in the message string buffer
msg += String(SerialInByte);
}
}
if (SmsContentFlag == 1) {
int i;
SerialUSB.println(“Flag Cleared”);
SerialUSB.print(“Message: “);
SerialUSB.println(msg);
if (msg.indexOf(“Location”)) {
SerialUSB.println(“Message Received”);
i = msg.indexOf(“+91”);
//SerialUSB.print(“index: “);
//SerialUSB.println(i);
//SerialUSB.println(msg[i+1]);
i = i + 3;
for (int j = 0; j < 10; j++, i++) {
mob += msg[i];
}
SerialUSB.print(“Mobile: “);
SerialUSB.println(mob);
String cmd = “AT+CMGS=\””;
cmd += mob;
cmd += “\””;
cmd += “\r”;
Serial1.println(cmd);
delay(100);

Serial1.print(“Your Vehicle Current Location “);
Serial1.print(loct);
Serial1.print(“\n”);
Serial1.print(“Check Map: \n”);
Serial1.print(” https://www.google.com/maps/@”);
Serial1.println(loct);
Serial1.println((char)26);
delay(1000);
}
ClearGprsMsg();
SmsContentFlag = 0;
msg.remove(0);
mob.remove(0);
}
delay(100);
}


// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS()
{
Serial1.println( “AT+CMGF=1” );
}

void GprsReadSmsStore( String SmsStorePos )
{
// Serial.print( “GprsReadSmsStore for storePos ” );
// Serial.println( SmsStorePos );
Serial1.print( “AT+CMGR=” );
Serial1.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg()
{
msg = “”;
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg()
{
SerialUSB.println(“”);
// Serial.print( “GPRS Message: [” );
SerialUSB.print( msg );
// Serial.println( “]” );
if ( msg.indexOf( “Call Ready” ) >= 0 )
{
SerialUSB.println( “*** GPRS Shield registered on Mobile Network ***” );
GprsTextModeSMS();
}

//EN: unsolicited message received when getting a SMS message
if ( msg.indexOf( “+CIEV” ) >= 0 )
{
SerialUSB.println( “*** SMS Received ***” );
}

//EN: SMS store readed through UART (result of GprsReadSmsStore request)
if ( msg.indexOf( “+CMT:” ) >= 0 )
{
// EN: Next message will contains the BODY of SMS
SmsContentFlag = 1;
// EN: Following lines are essentiel to not clear the flag!
//ClearGprsMsg();
return;
}

// EN: +CMGR message just before indicate that the following GRPS Shield message
// (this message) will contains the SMS body
if ( SmsContentFlag == 1 )
{
SerialUSB.println( “*** SMS MESSAGE CONTENT ***” );
SerialUSB.println( msg );
SerialUSB.println( “*** END OF SMS MESSAGE ***” );
//ProcessSms( msg );
}

/*ClearGprsMsg();
//EN: Always clear the flag
SmsContentFlag = 0; */
}

Working of the Arduino GPS+GSM Vehicle Tracking

Open the Serial Monitor after you’ve uploaded the code. The initialization message will be displayed on the Serial Monitor. Serial Monitor will display the Latitude and Longitude if the location is fixed. The Serial Monitor will still show Checking Module if the location is not found.

You can now send an SMS to obtain the location. So, on your phone, launch the messaging app and type in the phone number of the Arduino Zero board’s SIM card. After that, simply input the word “Location” and email it.

The Serial Monitor will display the message received status as well as the date, time, and cellphone number after a short while. Similarly, you will receive an SMS with the Latitude Longitude coordinate on your cell phone. You will receive a link to Google Maps along with the coordinates. You can open it using Google Maps or the Chrome browser by clicking the link.

arduino based gps tracker

As you can see, it’s pointing to the exact spot where I’m currently standing. This is a fantastic project that you can use in your automobiles as part of a vehicle tracking project. It can be used to keep a car from being stolen. Or it can be used in finding the location of someone who is using your vehicle.

Arduino-based GPS Tracker Project using SIM800/900 & NEO-6M GPS Module

The Arduino UNO Board, SIM900 or SIM800 GSM Module, and NEO-6M GPS Tracker Module can all be used in the same project. The circuit additionally has an additional LCD for displaying the status.

GSM GPS Based Vehicle Tracking System Arduino

Source Code/Program

The source code for the above circuit, which is based on a SIM800/900 GSM module and a NEO-6M GPS module, may be found here. This code is a little shorter and requires a minor change, such as the replacement of a mobile phone number. As a result, it is simple to test a GPS-based vehicle tracking system using Arduino.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
int temp=0,i;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
String stringVal = “”;
void setup(){
Serial.begin(9600);
ss.begin(GPSBaud);
lcd.begin(16,2);
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
lcd.print(“Vehicle Tracking”);
lcd.setCursor(0,1);
lcd.print(” System “);
delay(2000);
gsm_init();
lcd.clear();
Serial.println(“AT+CNMI=2,2,0,0,0”);
lcd.print(“GPS Initializing”);
lcd.setCursor(0,1);
lcd.print(” No GPS Range “);
delay(2000);
lcd.clear();
lcd.print(“GPS Range Found”);
lcd.setCursor(0,1);
lcd.print(“GPS is Ready”);
delay(2000);
lcd.clear();
lcd.print(“System Ready”);
temp=0;
}

void loop()
{
serialEvent();

while(temp)
{
while (ss.available() > 0)
{
gps.encode(ss.read());
if (gps.location.isUpdated())
{
temp=0;
digitalWrite(13,HIGH);
tracking();
}
if(!temp)
break;
}
}
digitalWrite(13,LOW);
}
void serialEvent()
{
while(Serial.available()>0)
{
if(Serial.find(“Track Vehicle”))
{
temp=1;
break;
}
else
{
temp=0;
}
}
}
void gsm_init()
{
lcd.clear();
lcd.print(“Finding Module..”);
boolean at_flag=1;
while(at_flag)
{
Serial.println(“AT”);
delay(1);
while(Serial.available()>0)
{
if(Serial.find(“OK”))
at_flag=0;
}

delay(1000);
}
lcd.clear();
lcd.print(“Module Connected..”);
delay(1000);
lcd.clear();
lcd.print(“Disabling ECHO”);
boolean echo_flag=1;
while(echo_flag)
{
Serial.println(“ATE0”);
while(Serial.available()>0)
{
if(Serial.find(“OK”))
echo_flag=0;
}
delay(1000);
}
lcd.clear();
lcd.print(“Echo OFF”);
delay(1000);
lcd.clear();
lcd.print(“Finding Network..”);
boolean net_flag=1;
while(net_flag)
{
Serial.println(“AT+CPIN?”);
while(Serial.available()>0)
{
if(Serial.find(“+CPIN: READY”))
net_flag=0;
}
delay(1000);
}
lcd.clear();
lcd.print(“Network Found..”);

delay(1000);
lcd.clear();
}
void init_sms()
{
Serial.println(“AT+CMGF=1”);
delay(400);
Serial.println(“AT+CMGS=\”850xxxxxxx\””); // use your 10 digit cell no. here
delay(400);
}
void send_data(String message)
{
Serial.print(message);
delay(200);
}
void send_sms()
{
Serial.write(26);
}
void lcd_status()
{
lcd.clear();
lcd.print(“Message Sent”);
delay(2000);
lcd.clear();
lcd.print(“System Ready”);
return;
}
void tracking()
{
init_sms();
send_data(“Vehicle Tracking Alert:”);
Serial.println(” “);
send_data(“Your Vehicle Current Location is:”);
Serial.println(” “);
Serial.print(“Latitude: “);
Serial.print(gps.location.lat(), 6);
Serial.print(“\n Longitude: “);
Serial.println(gps.location.lng(), 6);

// https://www.google.com/maps/@8.2630696,77.3022699,14z
Serial.print(“https://www.google.com/maps/@”);
Serial.print(gps.location.lat(), 6);
Serial.print(‘,’);
Serial.print(gps.location.lng(), 6);
Serial.print(“,14z”);
send_sms();
delay(2000);
lcd_status();
}

Conclusion:

I hope all of you understand how to design GPS+GSM Based Vehicle Tracking System using Arduino. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.