0% found this document useful (0 votes)
15 views9 pages

Vehicle Tracking System Code

The document describes an Arduino project to track a vehicle's location using a GPS module and send SMS alerts with the coordinates. It initializes an LCD display and GPS/GSM modules, gets location data from the GPS, and sends SMS messages with the latitude and longitude if instructed to track the vehicle.

Uploaded by

yasin Mohmed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

Vehicle Tracking System Code

The document describes an Arduino project to track a vehicle's location using a GPS module and send SMS alerts with the coordinates. It initializes an LCD display and GPS/GSM modules, gets location data from the GPS, and sends SMS messages with the latitude and longitude if instructed to track the vehicle.

Uploaded by

yasin Mohmed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#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()

[Link](16,2);

[Link](9600);

[Link](9600);

[Link]("Vehicle Tracking");

[Link](0,1);

[Link](" System ");

delay(2000);

gsm_init();

[Link]();

[Link]("AT+CNMI=2,2,0,0,0");

[Link]("GPS Initializing");

[Link](0,1);
[Link](" No GPS Range ");

get_gps();

delay(2000);

[Link]();

[Link]("GPS Range Found");

[Link](0,1);

[Link]("GPS is Ready");

delay(2000);

[Link]();

[Link]("System Ready");

temp=0;

void loop()

serialEvent();

if(temp)

get_gps();

tracking();

void serialEvent()

while([Link]())

if([Link]("Track Vehicle"))
{

temp=1;

break;

else

temp=0;

void gpsEvent()

gpsString="";

while(1)

while ([Link]()>0) //checking serial data from GPS

char inChar = (char)[Link]();

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()

[Link]();

[Link]("Finding Module..");

boolean at_flag=1;

while(at_flag)

[Link]("AT");

while([Link]()>0)
{

if([Link]("OK"))

at_flag=0;

delay(1000);

[Link]();

[Link]("Module Connected..");

delay(1000);

[Link]();

[Link]("Disabling ECHO");

boolean echo_flag=1;

while(echo_flag)

[Link]("ATE0");

while([Link]()>0)

if([Link]("OK"))

echo_flag=0;

delay(1000);

[Link]();

[Link]("Echo OFF");

delay(1000);
[Link]();

[Link]("Finding Network..");

boolean net_flag=1;

while(net_flag)

[Link]("AT+CPIN?");

while([Link]()>0)

if([Link]("+CPIN: READY"))

net_flag=0;

delay(1000);

[Link]();

[Link]("Network Found..");

delay(1000);

[Link]();

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=[Link]();

latitude[l1-1]=' ';

l1=[Link]();

longitude[l1-1]=' ';

[Link]();

[Link]("Lat:");

[Link](latitude);

[Link](0,1);

[Link]("Long:");

[Link](longitude);

i=0;x=0;

str_lenth=0;

delay(2000);
}

void init_sms()

[Link]("AT+CMGF=1");

delay(400);

[Link]("AT+CMGS=\"+91**********\""); // use your 10 digit cell no.


here

delay(400);

void send_data(String message)

[Link](message);

delay(200);

void send_sms()

[Link](26);

void lcd_status()

[Link]();

[Link]("Message Sent");

delay(2000);

[Link]();

[Link]("System Ready");

return;

}
void tracking()

init_sms();

send_data("Vehicle Tracking Alert:");

send_data("Your Vehicle Current Location is:");

[Link]("Latitude:");

send_data(latitude);

[Link]("Longitude:");

send_data(longitude);

send_data("Please take some action soon..\nThankyou");

send_sms();

delay(2000);

lcd_status();

You might also like