Arduino based Vehicle Tracker using GPS and GSM

Published  March 3, 2016   207
S Saddam
Author
Vehicle Tracking System using GPS and Arduino

Vehicle Tracking systems are very commonly used in fleet management and asset tracking applications. Today these systems can not only track the location of the vehicle but can also report the speed and even control it remotely. In general, tracking of vehicles is a process in which we track the vehicle location in form of Latitude and Longitude (GPS coordinates). GPS Coordinates are the value of a location. This system is very efficient for outdoor application purposes. This kind of Vehicle Tracking System Project is widely in tracking Cabs/Taxis, stolen vehicles, school/college buses, etc.In this project, we are going one step ahead with GPS building a GSM and GPS based vehicle tracking system using Arduino. This Vehicle Tracking System can also be used to  track a vehicle using GPS and GSM and can also be used as Accident Detection Alert System, Soldier Tracking System and many more, by just making few changes in hardware and software.

We have also build many other types of vehicle tracking systems previously, you can check them out if interested

 

Components Required for Arduino based Vehicle Tracking system:

To build a simple vehicle tracking system suing Arduino we will need the following components. 

  • Arduino UNO
  • GSM Module
  • GPS Module
  • 16x2 LCD
  • Power Supply
  • Connecting Wires
  • 10 K POT

 

How can  GSM Module be used to track location:

GPS stands for Global Positioning System and used to detect the Latitude and Longitude of any location on the Earth, with exact UTC time (Universal Time Coordinated). GPS module is the main component in our vehicle tracking system project. This device receives the coordinates from the satellite for each and every second, with time and date.

GPS module SKG13BL

GPS module sends the data related to tracking position in real time, and it sends so many data in NMEA format (see the screenshot below). NMEA format consist several sentences, in which we only need one sentence. This sentence starts from $GPGGA and contains the coordinates, time and other useful information. This GPGGA is referred to Global Positioning System Fix Data. Know more about Reading GPS data and its strings here.

We can extract coordinate from $GPGGA string by counting the commas in the string. Suppose you find $GPGGA string and stores it in an array, then Latitude can be found after two commas and Longitude can be found after four commas. Now these latitude and longitude can be put in other arrays.

GPS-module data in arduino serial monitor

 

Below is the $GPGGA String, along with its description:

$GPGGA,104534.000,7791.0381,N,06727.4434,E,1,08,0.9,510.4,M,43.9,M,,*47

$GPGGA,HHMMSS.SSS,latitude,N,longitude,E,FQ,NOS,HDP,altitude,M,height,M,,checksum data

 

Identifier

Description

$GPGGA

Global Positioning system fix data

HHMMSS.SSS

Time in hour minute seconds and milliseconds format.

Latitude

Latitude (Coordinate)

N

Direction N=North, S=South

Longitude

Longitude(Coordinate)

E

Direction E= East, W=West

FQ

Fix Quality Data

NOS

No. of Satellites being Used

HPD

Horizontal Dilution of Precision

Altitude

Altitude from sea level

M

Meter

Height

Height

Checksum

Checksum Data

 

Circuit Explanation for Interfacing GSM and GPS with Arduino:

Circuit Connections of this Vehicle Tracking System Project is simple and is shown in the image belwo. Here Tx pin of GPS module is directly connected to digital pin number 10 of Arduino. By using Software Serial Library here, we have allowed serial communication on pin 10 and 11, and made them Rx and Tx respectively and left the Rx pin of GPS Module open. By default Pin 0 and 1 of Arduino are used for serial communication but by using SoftwareSerial library, we can allow serial communication on other digital pins of the Arduino. 12 Volt supply is used to power the GPS Module.

Arduino based Vehicle Tracker using GPS and GSM circuit diagram

GSM module’s Tx and Rx pins of are directly connected to pin Rx and Tx of Arduino. GSM module is also powered by 12v supply. An optional LCD’s data pins D4, D5, D6 and D7 are connected to pin number 5, 4, 3, and 2 of Arduino. Command pin RS and EN of LCD are connected with pin number 2 and 3 of Arduino and RW pin is directly connected with ground. A Potentiometer is also used for setting contrast or brightness of LCD.

 

GSM and GPS based Vehicle Tracking system using Arduino - Working 

In this project, Arduino is used for controlling whole the process with a GPS Receiver and GSM module. GPS Receiver is used for detecting coordinates of the vehicle, GSM module is used for sending the coordinates to user by SMS. And an optional 16x2 LCD is also used for displaying status messages or coordinates. We have used GPS Module SKG13BL and GSM Module SIM900A.

GPS and GSM based Vehicle Tracking System Block Diagram

When we ready with our hardware after programming, we can install it in our vehicle and power it up. Then we just need to send a SMS, “Track Vehicle”, to the system that is placed in our vehicle. We can also use some prefix (#) or suffix (*) like #Track Vehicle*, to properly identify the starting and ending of the string, like we did in these projects: GSM Based Home Automation and Wireless Notice Board

 

Sent message is received by GSM module which is connected to the system and sends message data to Arduino. Arduino reads it and extract main message from the whole message. And then compare it with predefined message in Arduino. If any match occurs then Arduino reads coordinates by extracting $GPGGA String from GPS module data (GPS working explained above) and send it to user by using GSM module. This message contains the coordinates of vehicle location.

 

GAM and GPS Interfacing with Arduino Code  to Track Vehicle Location 

In programming part first we include libraries and define pins for LCD & software serial communication. Also define some variable with arrays for storing data. Software Serial Library is used to allow serial communication on pin 10 and 11.

#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

#include <SoftwareSerial.h>
SoftwareSerial gps(10,11); // RX, TX
char str[70];
String gpsString="";
... ....
.... ....

Here array str[70] is used for storing received message from GSM module and gpsString is used for storing GPS string. char *test=”$GPGGA” is used to compare the right string that we need for coordinates.

After it we have initialized serial communication, LCD, GSM & GPS module in setup function and showed a welcome message on LCD.

void setup() 
{
  lcd.begin(16,2);
  Serial.begin(9600);
  gps.begin(9600);

  lcd.print("Vehicle Tracking");
  lcd.setCursor(0,1);
  ... ....
  .... ....

In loop function we receive message and GPS string.

void loop()
{
  serialEvent();
  if(temp)
  {
    get_gps();
    tracking();
  }
}

Functions void init_sms and void send_sms() are used to initialising and sending message. Use proper 10 digit Cell phone no, in init_sms function.  

Function void get_gps() has been used to extract the coordinates from the received string.

Function void gpsEvent() is used for receiving GPS data into the Arduino.

Function void serialEvent() is used for receiving message from GSM and comparing the received message with predefined message (Track Vehicle).

void serialEvent()
{
  while(Serial.available())
  {
    if(Serial.find("Track Vehicle"))
    {
      temp=1;
      break;
    }
    ... ....
    .... ...

Initialization function ‘gsm_init() is used for initialising and configuring the GSM Module, where firstly, GSM module is checked whether it is connected or not by sending ‘AT’ command to GSM module. If response OK is received, means it is ready. System keeps checking for the module until it becomes ready or until ‘OK’ is received. Then ECHO is turned off by sending the ATE0 command, otherwise GSM module will echo all the commands. Then finally Network availability is checked through the ‘AT+CPIN?’ command, if inserted card is SIM card and PIN is present, it gives the response +CPIN: READY. This is also check repeatedly until the network is found. This can be clearly understood by the Video below.

Check all the above functions in Code Section below.

Code

#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

#include <SoftwareSerial.h>
SoftwareSerial gps(10,11); // RX, TX

//String str="";
char str[70];
String gpsString="";

char *test="$GPGGA";

String latitude="No Range      ";
String longitude="No Range     ";

int temp=0,i;
boolean gps_status=0;

void setup() 
{
  lcd.begin(16,2);
  Serial.begin(9600);
  gps.begin(9600);

  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  ");
  get_gps();
  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();
  if(temp)
  {
    get_gps();
    tracking();
  }
}

void serialEvent()
{
  while(Serial.available())
  {
    if(Serial.find("Track Vehicle"))
    {
      temp=1;
      break;
    }
    else
    temp=0;
  }
}

void gpsEvent()
{
  gpsString="";
  while(1)
  {
   while (gps.available()>0)            //checking serial data from GPS
   {
    char inChar = (char)gps.read();
     gpsString+= inChar;                    //store data from GPS into gpsString
     i++;
     if (i < 7)                      
     {
      if(gpsString[i-1] != test[i-1])         //checking for $GPGGA sentence
      {
        i=0;
        gpsString="";
      }
     }
    if(inChar=='\r')
    {
     if(i>65)
     {
       gps_status=1;
       break;
     }
     else
     {
       i=0;
     }
    }
  }
   if(gps_status)
    break;
  }
}

void gsm_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag=1;
  while(at_flag)
  {
    Serial.println("AT");
    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 get_gps()
{
   gps_status=0;
   int x=0;
   while(gps_status==0)
   {
    gpsEvent();
    int str_lenth=i;
    latitude="";
    longitude="";
    int comma=0;
    while(x<str_lenth)
    {
      if(gpsString[x]==',')
      comma++;
      if(comma==2)        //extract latitude from string
      latitude+=gpsString[x+1];     
      else if(comma==4)        //extract longitude from string
      longitude+=gpsString[x+1];
      x++;
    }
    int l1=latitude.length();
    latitude[l1-1]=' ';
    l1=longitude.length();
    longitude[l1-1]=' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0,1);
    lcd.print("Long:");
    lcd.print(longitude);
    i=0;x=0;
    str_lenth=0;
    delay(2000);
   }
}

void init_sms()
{
  Serial.println("AT+CMGF=1");
  delay(400);
  Serial.println("AT+CMGS=\"+91**********\"");   // use your 10 digit cell no. here
  delay(400);
}

void send_data(String message)
{
  Serial.println(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:");
    send_data("Your Vehicle Current Location is:");
    Serial.print("Latitude:");
    send_data(latitude);
    Serial.print("Longitude:");
    send_data(longitude);
    send_data("Please take some action soon..\nThankyou");
    send_sms();
    delay(2000);
    lcd_status();
}

Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Submitted by gourav on Fri, 03/18/2016 - 19:41

Permalink

what is microcontroller use in tracking system

Submitted by adil on Thu, 03/31/2016 - 17:09

Permalink

Hi!
Thank you for this post. I have make it . Everything is going well except one thing. The massage "NO GPS range" is stuck on the lcd. I am using Ublox neo 7m GPS module with compass.

Submitted by saddam khan on Mon, 04/04/2016 - 13:04

Permalink

No GPS Range Means your GPS is not in getting signal from satellite.
you have to place your GPS receiver or GPS antenna outdoor(on the roof, window)..

I wanted to extract only latitude and longitude and display them on lcd so i used this part of the code posted

#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

#include <SoftwareSerial.h>
SoftwareSerial gps(10,11); // RX, TX
//String str="";
//char str[70];

String gpsString="";
char *test="$GPGGA";
String latitude="No Range ";
String longitude="No Range ";
int temp=0,i;
boolean gps_status=0;

void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
gps.begin(9600);
lcd.print("GPS 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 ");

get_gps();
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();
if(temp)
{
get_gps();
//tracking();
}
}

void gpsEvent()
{
gpsString="";
while(1)
{
while (gps.available()>0) //checking serial data from GPS
{
char inChar = (char)gps.read();
gpsString+= inChar; //store data from GPS into gpsString
i++;
if (i < 7)
{
if(gpsString[i-1] != test[i-1]) //checking for $GPGGA sentence
{
i=0;
gpsString="";
}
}
if(inChar=='\r')
{
if(i>65)
{
gps_status=1;
break;
}
else
{
i=0;
}
}
}
if(gps_status)
break;
}
}

void get_gps()
{
gps_status=0;
int x=0;
while(gps_status==0)
{
gpsEvent();
int str_lenth=i;
latitude="";
longitude="";
int comma=0;
while(x<str_lenth)
{
if(gpsString[x]==',')
comma++;
if(comma==2) //extract latitude from string
latitude+=gpsString[x+1];
else if(comma==4) //extract longitude from string
longitude+=gpsString[x+1];
x++;
}
int l1=latitude.length();
latitude[l1-1]=' ';
l1=longitude.length();
longitude[l1-1]=' ';
lcd.clear();
lcd.print("Lat:");
lcd.print(latitude);
lcd.setCursor(0,1);
lcd.print("Long:");
lcd.print(longitude);
i=0;x=0;
str_lenth=0;
delay(2000);
}
}

Submitted by Jithu Moncy George on Tue, 04/05/2016 - 09:46

Permalink

Is it necessary that we use the same gps module specified by you?or can we use any other gps available in the market?

Submitted by Akash Singh on Tue, 04/05/2016 - 16:57

Permalink

I know but I connected gps module in gateway mode and it worked
it displayed the desired output as discussed in other post
but when i tried to do the same thing displaying it on lcd it is just stuck i mean how is it possible that one time same place is in range and other time it is not.....
Code worked previously but now it is not working...
Please help

Submitted by Eduardo camacho on Mon, 04/18/2016 - 13:27

Permalink

Hi, im in school project, and i need to get de gps cordenates and send it to a cellphone, im useing, de arduino uno and the SIM808 module, and my question is, how to use this module, is too hard to found examples of code with this module. thanks!

Submitted by amit kar on Wed, 04/27/2016 - 18:01

Permalink

i using sim 300 but do nothing why caN YOU HELP

Submitted by Darshan Thakker on Sat, 05/07/2016 - 20:25

Permalink

Is. The project working properly because i have to make this for final year project
Which is the. Gps and gsm model pls reply as early as possible

Thanks for Ur Support , en another thing is that my GSM module is SIM900 is it oky to use them with the codes above ?, I hv tried but it seems the execution of method gsm_init() isn't working .........
How should I make it work ?
Plz I need Ur help.........

Submitted by elvin on Mon, 05/30/2016 - 03:01

Permalink

Hi. I have tried out this project with sim800l. The lcd works properly and displays that 'network has been found' plus the 'longitude' and 'latitude'.
But when I send the text Track Vehicle, I get no reply.
Can you please help me to solve this???

IF you have Joined together the by putting a GSM Module ontop of Arduino Possible cause may be that the GSM Module has failed to send the message due to lower current since transmission requires much current , try using external power adaptor of 12V and connect it directly to the GSM.........,
In the initial codes try to replace the serialevent() method with this one
void serialEvent()
{
while(Serial.available())
{

if(Serial.find("Track"))
{
lcd.clear();
lcd.println("Message Received");
temp=1;
break;
}
else
temp=0;
}
}
if the "Track Vehicle" is received and read You will see the LCD , and it will prove that its a transmission problem (sendind of the SMS)

Submitted by Amir, Saidi on Wed, 06/01/2016 - 18:08

Permalink

My LCD keeps displaying Finding Module............. and doesn't go beyond that , what is the Problem actually ?

Submitted by Amir, Saidi on Thu, 06/02/2016 - 15:04

Permalink

I have come to notice that after the configuartion of the circuit is compete and I uploaded the codes,
My GSM Module doesn't Give the response to the AT commands sent so I keep seeing ATATATATATATATA....... on my Serial monitor so I was asking whats wrong ?, is it the codes or the connection that has a problem ?
Help me Plz its my Final Year project and the days are numbered.......

Submitted by Amir, Saidi on Thu, 06/02/2016 - 15:17

Permalink

From Your Video it shows Your codes and connection works just fine.....how do I configure my Modem using Hardware Serial and how my codes should be to work fine like Yours ? because its like the Response that GSM module is required to provide are not available , when I open the Serial Monitor I keep seeing ATATATATAT.......
when I try to write OK it goes to the next execution ........,
I don't knw whats wrong en I hv stayed For days troubleshooting any one with the knowledge will You Please help me.........
Even if its by sending the working Codes I will greatly appreciate it

Submitted by Amir, Saidi on Sun, 06/05/2016 - 16:40

Permalink

PROBLEM SOLVED.........!!!!!!!!!!!!!!!!! For all the People who has the same Problem as mine Just make Sure that your Hardware serial Communication is Configured Properly(Connection between GSM Module and ARDUINO)
i.e The serial monitor repeatedly dispays ATATATATATAT............. Because the GSM Module doesn't Respond meaning that thehardware Serial connection has failed ....
Man thanx 4 the codes .It realy Helped me...........

Initailly even I got the same message on serial monitor i.e ATATATA....
later the code isn't uploading to the ardino board!(avrdude..error relating to port 0)...Could you please tell the changes to be made in the code and the circuit connections.
Thanks in advance

Submitted by Elvin on Tue, 06/07/2016 - 13:36

Permalink

@Amir Saidi..
I have replaced the serial event method with
this one
void serialEvent()
{
while(Serial.available())
{
if(Serial.find("Track"))
{
lcd.clear();
lcd.println("Message Received");
temp=1;
break;
}
else
temp=0;
}
}

But the lcd stil does not display Message Received nor gsm sending any text to my phone. What else can I try? Anybody who can help me solve this problem???

Submitted by Elvin on Fri, 06/10/2016 - 23:32

Permalink

Guys does anyone know how to change the code so as to receive the longitude and latitude data in degrees format alone without the minutes?

Submitted by Sundari Ravi on Mon, 06/27/2016 - 16:34

Permalink

in the same project i dont want LCD display . i want the latitude and longitude once in 5minutes periodically ,please help me to finish my project.

Submitted by vizy on Tue, 07/05/2016 - 08:12

Permalink

Hi,
I have these errors, can you please resolve them. I have used the same code as define by the author.

sketch\test.cpp:8:12: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

char *test="$GPGGA";

^

test.cpp:12: error: 'boolean' does not name a type

boolean gps_status=0;

^

sketch\test.cpp: In function 'void setup()':

test.cpp:16: error: 'Serial' was not declared in this scope

Serial.begin(9600);

^

test.cpp:21: error: 'delay' was not declared in this scope

delay(2000);

^

test.cpp:22: error: 'gsm_init' was not declared in this scope

gsm_init();

^

test.cpp:28: error: 'get_gps' was not declared in this scope

get_gps();

^

sketch\test.cpp: In function 'void loop()':

test.cpp:41: error: 'serialEvent' was not declared in this scope

serialEvent();

^

test.cpp:44: error: 'get_gps' was not declared in this scope

get_gps();

^

test.cpp:45: error: 'tracking' was not declared in this scope

tracking();

^

sketch\test.cpp: In function 'void serialEvent()':

test.cpp:50: error: 'Serial' was not declared in this scope

while(Serial.available())

^

sketch\test.cpp: In function 'void gpsEvent()':

test.cpp:83: error: 'gps_status' was not declared in this scope

gps_status=1;

^

test.cpp:92: error: 'gps_status' was not declared in this scope

if(gps_status)

^

sketch\test.cpp: In function 'void gsm_init()':

test.cpp:100: error: 'boolean' was not declared in this scope

boolean at_flag=1;

^

test.cpp:100: error: expected ';' before 'at_flag'

boolean at_flag=1;

^

test.cpp:101: error: 'at_flag' was not declared in this scope

while(at_flag)

^

test.cpp:103: error: 'Serial' was not declared in this scope

Serial.println("AT");

^

test.cpp:110: error: 'delay' was not declared in this scope

delay(1000);

^

test.cpp:114: error: 'delay' was not declared in this scope

delay(1000);

^

test.cpp:117: error: expected ';' before 'echo_flag'

boolean echo_flag=1;

^

test.cpp:118: error: 'echo_flag' was not declared in this scope

while(echo_flag)

^

test.cpp:120: error: 'Serial' was not declared in this scope

Serial.println("ATE0");

^

test.cpp:133: error: expected ';' before 'net_flag'

boolean net_flag=1;

^

test.cpp:134: error: 'net_flag' was not declared in this scope

while(net_flag)

^

test.cpp:136: error: 'Serial' was not declared in this scope

Serial.println("AT+CPIN?");

^

sketch\test.cpp: In function 'void get_gps()':

test.cpp:151: error: 'gps_status' was not declared in this scope

gps_status=0;

^

test.cpp:182: error: 'delay' was not declared in this scope

delay(2000);

^

sketch\test.cpp: In function 'void init_sms()':

test.cpp:187: error: 'Serial' was not declared in this scope

Serial.println("AT+CMGF=1");

^

test.cpp:188: error: 'delay' was not declared in this scope

delay(400);

^

sketch\test.cpp: In function 'void send_data(String)':

test.cpp:194: error: 'Serial' was not declared in this scope

Serial.println(message);

^

test.cpp:195: error: 'delay' was not declared in this scope

delay(200);

^

sketch\test.cpp: In function 'void send_sms()':

test.cpp:199: error: 'Serial' was not declared in this scope

Serial.write(26);

^

sketch\test.cpp: In function 'void lcd_status()':

test.cpp:205: error: 'delay' was not declared in this scope

delay(2000);

^

sketch\test.cpp: In function 'void tracking()':

test.cpp:215: error: 'Serial' was not declared in this scope

Serial.print("Latitude:");

^

test.cpp:221: error: 'delay' was not declared in this scope

delay(2000);

^

exit status 1
'boolean' does not name a type

Invalid library found in C:\Program Files (x86)\Arduino\libraries\test: C:\Program Files (x86)\Arduino\libraries\test
Invalid library found in C:\Program Files (x86)\Arduino\libraries\test: C:\Program Files (x86)\Arduino\libraries\test

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Submitted by Shashank Kimothi on Mon, 07/18/2016 - 11:53

Permalink

can you please tell me what does this part of the code do:
while(Serial.available()>0)
{
if(Serial.find("OK"))
at_flag=0;
}

Submitted by saddam khan on Mon, 07/25/2016 - 17:44

In reply to by Shashank Kimothi

Permalink

this will read gsm output string and find OK substring or word comming from GSM response. and if matched with OK then set at_flag

SLAAM Saddam Brother; i have sim900 and NEO-6M GY-GPS6MV2 gps it is working well for, just printing longitude and latitude plz guide me for the tracking by sim card like this project THANKFULL 2 u :)

Submitted by rodrique on Mon, 07/18/2016 - 15:52

Permalink

hello guys i wish to know how to do this using proteus and arduino
what are the libraries to included in proteus and arduino and incorporating the gsm mudule and the pgrs/gps mudules

please help i power my sim 800l with arduino uno 5volt on board using a usb port of my laptop,everything went fine but when i send track vehicle, i got no respond.i read sim800l datasheet which says it draw up to 2A of current.my sim800l works with all AT command. but doesnt respond to sms command.please what kind of power should i use to power my sim800l? thanks in advance

please admin,please power a 12volt battery charger with auto cut off of with lcd display...no post of power supply,regulator and battery charger or solar...please see into that

after powering the sim800l with 3.7volt lithium battery,i was able to dial the number in the module and its rings.but when i send message(Track Vehicle) to the module,it only receive the message but nothing was sent back to the number i put in the programming...pls how to i test if a sim800l is working with sms recieving and sending sms using arduino...please urgent feedback is needed.. 

hardware: gps:NEO-6m-0-001 (Gps), and arduino(any type)....make sure your the gps TX is connected to pin10 of the arduino and the RX is left unconnected.... gsm sim800l...i power my sim800l with a full charger power bank battery......Lithium Ion 18600 3.7v Battery... since the sim800l data sheet says it need power of 3.7v-4.2volt and draw current of up to 2A.. after all connection are done.here is the code i used..

#include<LiquidCrystal.h>
#include <SoftwareSerial.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
SoftwareSerial gps(10, 11); // RX, Tx
int led = 13;

int l = 0, x = 0, k = 0;
char str1[100], msg[32];

//String str="";
char str[70];
String gpsString = "";

char *test = "$GPGGA";

String latitude = "No Range      ";
String longitude = "No Range     ";

int temp = 0, i;
boolean gps_status = 0;
void setup()
{

  lcd.begin(16, 2);
  Serial.begin(9600);
  gps.begin(9600);

  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");
  delay(500);
  Serial.println("AT+CMGF=1");
  lcd.print("GPS Initializing");
  lcd.setCursor(0, 1);
  lcd.print("  No GPS Range  ");
  get_gps();
  delay(500);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0, 1);
  lcd.print("GPS is Ready");
  delay(500);
  lcd.clear();
  lcd.print("System Ready");
  digitalWrite(led, LOW);
}
void loop()
{
  for (unsigned int t = 0; t < 60000; t++)
  {
    serialEvent();
    if (temp == 1)
    {
      x = 0, k = 0, temp = 0;
      while (x < l)
      {
        while (str1[x] == '#')
        {
          x++;
          while (str1[x] != '*')
          {
            msg[k++] = str1[x++];
          }
        }
        x++;
      }
      get_gps();
      tracking();
      msg[k] = '\0';
      lcd.clear();
      lcd.print(msg);
      delay(1000);
      temp = 0;
      l = 0;
      x = 0;
      k = 0;
    }
  }
  lcd.scrollDisplayLeft();
  Serial.println("AT+CMGD=1,4"); // delete all SMS
}

void serialEvent()
{
  while (Serial.available())
  {
    char ch = (char)Serial.read();
    str1[l++] = ch;
    if (ch == '*')
    {
      temp = 1;
      lcd.clear();
      lcd.print("Message Received");
      delay(1000);
    }
  }
}

void gsm_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag = 1;
  while (at_flag)
  {
    Serial.println("AT");
    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 gpsEvent()
{
  gpsString = "";
  while (1)
  {
    while (gps.available() > 0)          //checking serial data from GPS
    {
      char inChar = (char)gps.read();
      gpsString += inChar;                   //store data from GPS into gpsString
      i++;
      if (i < 7)
      {
        if (gpsString[i - 1] != test[i - 1])    //checking for $GPGGA sentence
        {
          i = 0;
          gpsString = "";
        }
      }
      if (inChar == '\r')
      {
        if (i > 65)
        {
          gps_status = 1;
          break;
        }
        else
        {
          i = 0;
        }
      }
    }
    if (gps_status)
      break;
  }
}

void get_gps()
{
  gps_status = 0;
  int x = 0;
  while (gps_status == 0)
  {
    gpsEvent();
    int str_lenth = i;
    latitude = "";
    longitude = "";
    int comma = 0;
    while (x < str_lenth)
    {
      if (gpsString[x] == ',')
        comma++;
      if (comma == 2)     //extract latitude from string
        latitude += gpsString[x + 1];
      else if (comma == 4)     //extract longitude from string
        longitude += gpsString[x + 1];
      x++;
    }
    int l1 = latitude.length();
    latitude[l1 - 1] = ' ';
    l1 = longitude.length();
    longitude[l1 - 1] = ' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0, 1);
    lcd.print("Long:");
    lcd.print(longitude);
    i = 0; x = 0;
    str_lenth = 0;
    delay(10000);
  }
}

void tracking()
{
  Serial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Serial.println("AT+CMGS=\"+2349051146346\""); // Replace x with mobile number
  delay(100);
  delay(1000);
  Serial.println("Vehicle Tracking Alert:");
  Serial.print("Your Vehicle Current Location is:");
  Serial.print("Latitude:");
  Serial.print(latitude);
  Serial.print("Longitude:");
  Serial.print(longitude);
  Serial.print("Please take some action soon..\nThankyou");
  delay(100);
  Serial.write(26);// ASCII code of CTRL+Z
  delay(1000);
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  //return;
}

Arduino: 1.8.1 (Windows XP), Board: "Arduino/Genuino Uno"

C:\Documents and Settings\sys\My Documents\Arduino\sketch_feb20c\sketch_feb20c.ino:11:14: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

char *test = "$GPGGA";

^

C:\Documents and Settings\sys\My Documents\Arduino\sketch_feb20c\sketch_feb20c.ino: In function 'void gsm_init()':

C:\Documents and Settings\sys\My Documents\Arduino\sketch_feb20c\sketch_feb20c.ino:104:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if (Serial.find("OK"))

^

C:\Documents and Settings\sys\My Documents\Arduino\sketch_feb20c\sketch_feb20c.ino:120:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if (Serial.find("OK"))

^

C:\Documents and Settings\sys\My Documents\Arduino\sketch_feb20c\sketch_feb20c.ino:136:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

if (Serial.find("+CPIN: READY"))

^

Sketch uses 8162 bytes (25%) of program storage space. Maximum is 32256 bytes.
Global variables use 1003 bytes (48%) of dynamic memory, leaving 1045 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't set com-state for "\\.\COM3"
An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

during my study of the gsm module i use, i found that my sim800l shutdown when i use serial.find(''Track Vehicle''); so i use the wireless notices board code in the other post and it work fine, so i just have to swap and do some modification to the existing code and it work..command to send is 

#anything u like*    example;
#track* 
#track vehicle* 

Submitted by Eromosele on Fri, 08/26/2016 - 07:14

Permalink

hi everyone. please is it possible to make the reply message to your phone a link to google maps showing the location of the car? if possible please how? thanks a lot.

Submitted by vivek on Sat, 09/03/2016 - 10:31

Permalink

Hi everyone , I m sending message from mobile ....... but not getting response on the mobile from the GSM module i.e the value of " lat" . and "long"....please help me out

Submitted by stepehen on Thu, 09/08/2016 - 22:48

Permalink

Friends after executing the entire code available in this webpage.. its shows error in the following code

char *test="$GPGGA";

if(Serial.find("Track Vehicle"))

if(Serial.find("OK"))

please resolve this as soon as possible friends....

Submitted by mark on Mon, 09/12/2016 - 18:58

Permalink

hi .... everyone I have GPS-GSM Module (SARA-G350) i used the first code but it doesnt work thé module give not a réponse please can you help me

Submitted by Vicente on Fri, 09/16/2016 - 20:24

Permalink

hi i am from Ecuador use the GPS module neo Neo 6 - m and 900 sim Hield but I made ​​the connection and load the code but it does not work me out on serial port only the command AT

Submitted by Hassan on Sat, 09/17/2016 - 23:52

Permalink

sir i have a problem with it . it does'nt work its stuck in (system ready) and can't get any thing out of it . when i send (Track Vehicle ) nothing happen could u pls help me with it iam using the same code , sim900 and also what does echo mean ?

Submitted by Brana Rajah on Sat, 09/24/2016 - 21:58

Permalink

Sir, this is my final year project, I have got the Arduino UNO R3, GPRS/GSM Shield SIM900 Ver 2.0
I am little confused with my components, My following doubts are,
1. In my GPRS Shield SIM900 there is a in built antenna, what's the purpose of the antenna?
2. is it nesessary to add a GPS module for this project?, if so please recommend a suitable one?
3. But in my Shield i don't have no idea where to plug the GPS module?

Your help would be highly appreciated!

Thank you.

for those that still encounter problem in setting up this circuit to work, double check your connection very well and if its failed to work check the previous page and use the modified code i use for my own circuit

nurul this project can be use for final year project but use just have to make sure you are not having any issue with the connection between the hardware. also make sure you check your hardware datasheet expecially the gsm and the gps for proper power connection 

the issue i had then was that my sim800l doesnt work with ''serial.find''

while(Serial.available()) 
  {
    if(Serial.find("#A."))
    {
      digitalWrite(led, HIGH);
      delay(1000);
      digitalWrite(led, LOW);
      while (Serial.available()) 
      {
      char inChar=Serial.read();
      str[i++]=inChar;
      if(inChar=='*')
      {
        temp=1;
        return;
      } so i tried use other method like the while loop

 

 serialEvent();
    if (temp == 1)
    {
      x = 0, k = 0, temp = 0;
      while (x < l)
      {
        while (str1[x] == '#')
        {
          x++;
          while (str1[x] != '*')
          {
            msg[k++] = str1[x++];
          }
        }
        x++;
      }

 

so check whether your gsm works with the serial.find or the while loop 

#include<LiquidCrystal.h>
#include <SoftwareSerial.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
SoftwareSerial gps(10, 11); // RX, Tx    connect the gps tx to pin10 and leave the gps RX unconnected 
int led = 13;

int l = 0, x = 0, k = 0;
char str1[100], msg[32];

//String str="";
char str[70];
String gpsString = "";

char *test = "$GPGGA";

String latitude = "No Range      ";
String longitude = "No Range     ";

int temp = 0, i;
boolean gps_status = 0;
void setup()
{

  lcd.begin(16, 2);
  Serial.begin(9600);
  gps.begin(9600);

  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");
  delay(500);
  Serial.println("AT+CMGF=1");
  lcd.print("GPS Initializing");
  lcd.setCursor(0, 1);
  lcd.print("  No GPS Range  ");
  get_gps();
  delay(500);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0, 1);
  lcd.print("GPS is Ready");
  delay(500);
  lcd.clear();
  lcd.print("System Ready");
  digitalWrite(led, LOW);
}
void loop()
{
  for (unsigned int t = 0; t < 60000; t++)
  {
    serialEvent();
    if (temp == 1)
    {
      x = 0, k = 0, temp = 0;
      while (x < l)
      {
        while (str1[x] == '#')
        {
          x++;
          while (str1[x] != '*')
          {
            msg[k++] = str1[x++];
          }
        }
        x++;
      }
      get_gps();
      tracking();
      msg[k] = '\0';
      lcd.clear();
      lcd.print(msg);
      delay(1000);
      temp = 0;
      l = 0;
      x = 0;
      k = 0;
    }
  }
 // lcd.scrollDisplayLeft();
  Serial.println("AT+CMGD=1,4"); // delete all SMS
}

void serialEvent()
{
  while (Serial.available())
  {
    char ch = (char)Serial.read();
    str1[l++] = ch;
    if (ch == '*')
    {
      temp = 1;
      lcd.clear();
      lcd.print("Message Received");
      delay(1000);
    }
  }
}

void gsm_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag = 1;
  while (at_flag)
  {
    Serial.println("AT");
    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 gpsEvent()
{
  gpsString = "";
  while (1)
  {
    while (gps.available() > 0)          //checking serial data from GPS
    {
      char inChar = (char)gps.read();
      gpsString += inChar;                   //store data from GPS into gpsString
      i++;
      if (i < 7)
      {
        if (gpsString[i - 1] != test[i - 1])    //checking for $GPGGA sentence
        {
          i = 0;
          gpsString = "";
        }
      }
      if (inChar == '\r')
      {
        if (i > 65)
        {
          gps_status = 1;
          break;
        }
        else
        {
          i = 0;
        }
      }
    }
    if (gps_status)
      break;
  }
}

void get_gps()
{
  gps_status = 0;
  int x = 0;
  while (gps_status == 0)
  {
    gpsEvent();
    int str_lenth = i;
    latitude = "";
    longitude = "";
    int comma = 0;
    while (x < str_lenth)
    {
      if (gpsString[x] == ',')
        comma++;
      if (comma == 2)     //extract latitude from string
        latitude += gpsString[x + 1];
      else if (comma == 4)     //extract longitude from string
        longitude += gpsString[x + 1];
      x++;
    }
    int l1 = latitude.length();
    latitude[l1 - 1] = ' ';
    l1 = longitude.length();
    longitude[l1 - 1] = ' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0, 1);
    lcd.print("Long:");
    lcd.print(longitude);
    i = 0; x = 0;
    str_lenth = 0;
    delay(10000);
  }
}

void tracking()
{
  Serial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Serial.println("AT+CMGS=\"+xxxxxxxxxxxxxx\""); // Replace x with  your country mobile number
  delay(100);
  delay(1000);
  Serial.println("Vehicle Tracking Alert:");
  Serial.print("Your Vehicle Current Location is:");
  Serial.print("Latitude:");
  Serial.print(latitude);
  Serial.print("Longitude:");
  Serial.print(longitude);
  Serial.print("Please take some action soon..\nThankyou");
  delay(100);
  Serial.write(26);// ASCII code of CTRL+Z
  delay(1000);
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  //return;
}