Vehicle Tracking System

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Vehicle Tracking System

Presented by
Azhar Muhammed, Ahmed Azawi, and Iyad Basem
2nd Stage (Evening Study)

n Dr. Omar Youssef


Table of Contents:

Introduction 2-4

Hardware explained 4-10

Hardware Components 10-11

GPRS+GPS shield diagram 11-13

System assembly 14

Final assembly 15-16

Software Component 16-18

Identification &Application diagram 19-20

Display of Result 20-21

CODE 22-29

1
Vehicle Tracking System

Introduction:

Arduino offers both a hardware and a software platform and has


rich documentation available online. Arduino can sense the
environment by receiving input from a variety of sensors and can
affect its surroundings by controlling lights, motors, and other
actuators. Thousands of people have chosen Arduino as their main
tool to create all kinds of projects, from blinking lights to space
exploration. Creating simple projects is a good start to become
familiar with the tools, codes and components but when starting a
more advanced project it is necessary to establish ground rules.
Without rules and steps a project can become difficult and might be
abandoned due to the lack of preparation. Planning is the key and
will help during the whole process. Testing will help finding the
problems and improve the features of the project. Producing one or
more copy is also possible and will affect costs. This thesis focuses on
a simple step-by-step process used to create a GPS tracker from
scratch. It is divided in two main parts: hardware and software. The
hardware part is the board with the electronic components and the
software part is the interface used to display the data from the
tracker. The purpose is not to explain in detail the electronics

2
components and software code but to give a general idea of the
steps from designing to testing and producing. tracking system is a
total security and fleet management solution. It is the technology
used to determine the location of a vehicle using different methods
like GPS and other navigation system operating via satellite and
ground based stations. Modern vehicle tracking system use GPS
technology to monitor and locate our vehicle anywhere on earth,
but sometimes different types of automatic vehicle location
technology are also used. The vehicle tracking system is fitted inside
the car that provides effective real time location and the data can
even be stored and downloaded to a computer which can be
used for analysis in future. This system is an essential device for
tracking car any time the owner wants to monitor it and today it is
extremely popular among people having expensive cars, used as
theft prevention and recovery of the stolen car. The data collected
can be viewed on electronic maps via internet and software. The
vehicle unit incorporates the hardware part that is the Arduino, GPS
and GSM modem kept inside the vehicle that is to be tracked. The
unit is mainly based on a modem that receives signals from the
satellite with the help of GPS antenna. This modem then converts the
data and sends the vehicle location information via SMS as well as a
mobile application named “VTS‟ which is synchronized with the web
page and to a server which can be displayed on digital mapping.

The tracking hardware is installed inside the vehicle in such a manner


that it is not visible from outside the vehicle. Hence, it works as a
3
secret unit which continuously sends the coordinates to the
monitoring center. Monitoring center Software helps the vehicle
owner with a view of the vehicle location on an electronic
map. The user can use any browser to connect to the server and
monitor thetargeted vehicle on Google Map. Thus it saves the user
from the hassle of calling the driver to know the vehicle‟s location as
it is now possible to track vehicle online.The vehicle tracking system
is one of the biggest technological advancements for security
purpose. It enables the owner to virtually keep an eye on his vehicle
any time and from anywhere in the world.A vehicle tracking system
combines the installation of an electronic device in a vehicle
with purpose-designed software to allow the owner to monitor
the vehicle, collecting data in the process from the field and
deliver it to the base of operation. Urban public transportation
companies are an increasingly common user of tracking systems,
particularly in large cities.

HARDWARE:

Modules

4
A module is a part of a project whose goal is to execute a specific
task. By dividing the project into several functional modules, it is easy
to try, analyze and improve each functionality separately.

Arduino

Arduino is an electronic open-source platform based on a simple


microcontroller (hardware) and a development environment
(software) used to write, compile, and transfer the program to the
microcontroller. Arduino can be used to develop interactive objects.
It can use inputs from a wide range of switches or sensors and can
control several items such as lights, motors or any other kind of
hardware. Arduino projects can be autonomous or they can
communicate with software running on your computer. The platform
can be built manually or can be bought pre-assembled. The
development software can be downloaded for free. The Arduino
programming language is an implementation of Wiring, a
development platform based on the programming multimedia
environment Processing.

Why Arduino?

There are a lot of microcontrollers and platforms based on


microcontrollers available for embedded electronics. Parallax Basic
Stamp, Phidgets, Netmedia’s BX-24, MIT’s Handyboard and several
others offer the same capabilities. All these tools help microcontrollers
programming by proposing an easy way to use them. Arduino

5
simplifies the way to work with microcontrollers and offer several
advantages for teachers, students and hobbyists:

 Cheap: Arduino boards are relatively cheap compared to other


platforms. The cheapest version of Arduino can be assembled by
hand and the preassembled versions are usually under 35$.

 Multi-platform: The Arduino software, written in Java, runs on


Windows, Macintosh and Linux. Most of the microcontrollers systems
are limited to Windows.

 A simple and clear programming environment: Arduino’s


programming environment is easy to use for beginners but is flexible
enough for advanced users. For teachers, it is based on Processing
environment and students who are used to working with that
environment will be familiar with the Arduino software.

 Open-Source software and extensible: Arduino software and


Arduino language are published under the open-source license and
are available for advanced programmers to work with. The language
can also be extended thanks to C++ libraries and people who want
to know more about technical details can use C language for AVR
microcontroller on which it is based. One can also add the AVR-C
language directly in Arduino programs if required.

 Open-source hardware and extensible: Arduino boards are based


on Atmel ATMEGA8, ATMEGA168, ATMEGA328, and similar.
Schematics are published under the Creative Commons license so

6
advanced electronics designers can create their own version of the
Arduino board. Even less advanced users can build the breadboard
version in order to understand how it works and save money.

Arduino boards

There are several types of Arduino boards. The common basic version,
Uno uses the Atmel ATmega328 microcontroller. A more advanced
version (i.e., more capabilities and more powerful) named Mega is
based on the ATmega1280.

7
Figure 1 Arduino UNO

Arduino uno

board is a microcontroller board based on the ATmega168 for the first


versions or the Atmega328 for the recent versions. Its features:

 14 digital I/O (Input/Output) whose 6 can be used as PWM (Pulse-


Width Modulation) outputs,

 6 analog inputs which can be used as digital I/O,

 a 16 MHz crystal,  a USB connector,

 a power supply connector,

 ICSP connector (In-Circuit Serial Programming),

 a reset button.

It has everything needed to work with the microcontroller. To use it, it


is necessary to connect it to a computer with a USB cable or a
separate power supply such as a battery or a transformer.

Arduino Software

The Arduino software main functions are:

 write and compile programs to the Arduino board

8
 connect to the Arduino board to transfer programs

 communicate with the Arduino board

The Arduino software also has a serial terminal that is used to display
text messages received from the Arduino and send characters to the
Arduino. This functionality is really useful to display the state of
variables or results of calculations. It is an essential element to improve,
test, and correct programs loaded in the microcontroller.

9
Figure 2 Arduino IDE

GPS

Global Positioning System is a space-based satellite navigation


system providing position information on Earth. It helps users to
determine their position, speed and time of the day on land, sea
and in the air 24 hours a day, everywhere in the world. GPS signals
are accessible to an unlimited number of people simultaneously.

Each satellite transmits signals to devices on earth. The receptors


receive passively the signals from the satellites but they do not emit
any signal. They require a clear view of the sky to work properly and
are mainly used outside. Their performance can be affected in
woods areas or near high buildings. The GPS system works with a
network of satellites used to determine accurately the position
anywhere on the planet.

Hardware Components:

Ingredients:

10
GPRS +GPS:

 1 x Arduino Uno

 1 x Geolocation Tracker (GPRS + GPS) with SIM908

 1 x 2300mA/h Rechargeable Battery

 1 x External GPRS-GSM Antenna

 1 x External GPS Antenna

 1 x 9V Alkaline Battery

 1 x 9V to Barrel Jack Adapter or 9V Battery Holder

Figure 3 components

11
GPRS+GPS shield diagram:

Figure 4 GPS shield

12
Figure 5 gps Shield
he LED of the shield shows the status of the GPRS+GPS module. The
table below shows the meaning of the blink of the LED.

Status SIM908 behavior

Off SIM908 is not running

64ms On/ 800ms Off SIM908 not registered the network

64ms On/ 3000ms Off SIM908 registered to the network

SIM908 registered to the network PPP GPRS communication is established

13
System assembly:

Connect the antennas to the shield:

Figure 6 antennas to the shield

Connect the shield to the Arduino:

Important Issues:

 Handle with care the internal

14
antenna. It's fragile.
 The GPS antenna must
be in horizontal position.
 For improving the satellites signal,
the antenna has to be in a place with a clear
sky view (no trees, no buildings...).
Figure 7 assembling

Final assembly:

You can fix the batteries to the module with flanges so the whole
system will need less room and you will be able to place it better in
your car

15
Figure 8 final assembly

Installation is very simple, you can place it wherever you want


maybe in your trunk, in the glove compartment or under your spare
tire. GPS antenna position is very important! For external GPS
antenna, arrow printed in it must be pointing directly to the sky and
internal GPS antenna ceramic side must be upwards too.

Software Component:

In this step we use an Arduino UNO with the GPRS+GPS(SIM908)


shield to send GPS coordinates to a mobile with a SMS and through
HTTP when you call to the module and your number is correct.

in this project, we built a vehicle tracking device


which will be imbedded into a vehicle and monitoring that
vehicle in real time. In tracking device, GPS receiver receives
the data or information mainly latitude and longitude of the
particular vehicle from the satellite which information is
transferred over mobile phone via Short Message Service (SMS)
by using GSM modem. GSM modem is connected with Arduino
Uno. he positional information is also transferred to a remote
server, server stores the acquiring positional data in the database.
For the GPS tracker, the only data provided was latitude, longitude
and date/time. There might not be any software able to create

16
something explicit from those data but if it is used with an
application designed properly, it can work with them and create
custom features. This helps to focus the hardware part on providing
the bare minimum (raw) data and focus on performance where the
software will analyse the data and work with them using high power
calculations. When designing an application, one has to list the top
priorities. The main requirement for the application was to make it
available on any platform. This already scopes down the possibilities
and Java comes in mind when talking about cross platform
compatibility. Java was indeed the first solution but, in my opinion,
has a really bad user interface so further researches were necessary.
I decided to go for a web application, using Bootstrap with jQuery as
a front end and PHP as a back end. I had little knowledge of
bootstrap and jQuery and that could be a way to improve my skills in
this area.

Algorithm

At first, we did the experiment of our work with the GPSmodule


which is connected to the Arduino Uno microcontroller to get
latitude and longitude of a vehicle. For doing that, we had
used Arduino IDE software to program the code. In the coding
we had included two libraries softwareSerial.h and TinyGPS.h. The
flowchart of GPS coding is given below.

17
Figure 9 code flowchart

18
Identify your phone number and send GPS coordinates

When you call to the module and your phone number is correct, the
GPS obtains longitude and latitude, send you a SMS with the position
and send the GPS data through the Internet to the php script in your
computer.

First step. Load the next sketch into your arduino and then assemble
the GPRS+GPS shield with the antennas and the simcard installed.
Remember, you must configure your APN, login and password. If you
don't do this, the GPRS+GPS cannot connect to the GPRS network.
Also, you must set the URL with the IP address of your computer
(external IP, not the LAN IP address) or your server's domain. To use
the php script you need an Apache server with php active. You can
run the script in a PC installing Apache with php.

Application digram:

19

Figure 10 app diagram


The diagram of vehicle tracking system shows how our system
actually works. The vehicle tracking unit is installed inside the
vehicle that is to be tracked. The GPS receiver receives the
coordinate from the satellite which is then send to the GSM
tower by the GSM modem. The coordinate is then sent to a
computer via internet where it is stored in the database for
displaying the location on Google map. The user can also see the
location of the vehicle in a mobile phone, when the user sends an
SMS to the GSM modem in the vehicle, the GSM modem
sendanother SMS back to the user with the coordinates of the
location of the vehicle along with a Google map link.

Display of Result:
Google Map:
With the Google Maps API, we add maps based on Google
Maps data to the web application. The API automatically
handles access to Google Maps servers. We also use API calls
to add markers. We set the center location of map by using
google.maps.LatLng (). As Google Maps API providesdifferent kind
of maps view, we used ROADMAP for this web application. For
fetching the data into the Google Map, we have used
getElementByID () method.

20
SMS:
For monitoring the vehicle location, we have also included the
feature which will send SMS to the user according to user request.
SMS will be included the value of latitude and longitude of the
vehicle. A link is also attached with the SMS, so that the user can see
the location by using Googlemap. View of location on website
through Google map.

Figure 12 google maps

Figure 11 SMS

21
Code:
#include “softwareSerial.h” mynumber[7]='7';

#include “TinyGPS.h” char url[] = mynumber[8]='8';


"pruebas.libelium.com";
int8_t answer;

int onModulePin= 2;
char frame[200];
char aux_string[30]; pinMode(onModulePin,
OUTPUT);
int flag = 0;
char latitude[15]; Serial.begin(115200);
char number [20];
char longitude[15];
char realnumber[9];
power_on();
char mynumber[9];
char altitude[6]; power_onGPS();
int a=0;
char date[16]; power_onSMS();
int b=0;
char time[7];
int c=0;
char satellites[3]; delay(5000);
//Your phone number
char speedOTG[10];
Char
phone_number[]="0123456 char course[10];
78"; sendATcommand("AT+CPI
N=****", "OK", 2000);
void setup(){
char data[100];
mynumber[0]='0'; delay(3000);
int data_size;
mynumber[1]='1';

mynumber[2]='2'; while(
char aux_str[30]; (sendATcommand("AT+CR
mynumber[3]='3';
char aux; EG?", "+CREG: 0,1", 1000)
mynumber[4]='4'; ||
int x = 0; sendATcommand("AT+CRE
mynumber[5]='5'; G?", "+CREG: 0,5", 1000))
char N_S,W_E; == 0 );
mynumber[6]='6';

22
delay(1000); Serial.flush();
while(Serial.available() flag = 1;
!= 0)
}
sendATcommand("AT+CLIP {
=1", "OK", 1000); //Stores phone
Serial.read(); calling number

} for (int i=0; i<=14;


while ( start_GPS() == 0); i++){
}
if(number[i]== '"'){
void loop(){
while i++;
(sendATcommand("AT+CR
EG?", "+CREG: 0,1", 2000) answer =
== 0); realnumber[0]=number[i];
sendATcommand("",
"+CLIP", 1000); i++;

// sets APN , user name //Detect incomming call


and password realnumber[1]=number[i];
if (answer == 1)
i++;
{
sendATcommand("AT+SAP
BR=3,1,\"Contype\",\"GPR realnumber[2]=number[i];
S\"", "OK", 2000); Serial.println("Incoming
call"); i++;

sendATcommand("AT+SAP
BR=3,1,\"APN\",\"*******\"", realnumber[3]=number[i];
"OK", 2000); if ( flag == 0){
i++;

sendATcommand("AT+SAP for (int i=0; i<19;


BR=3,1,\"USER\",\"*******\"" realnumber[4]=number[i];
i++){
, "OK", 2000); i++;
// read the
incoming byte:
sendATcommand("AT+SAP realnumber[5]=number[i];
BR=3,1,\"PWD\",\"*******\"" while
, "OK", 2000); (Serial.available() == 0) i++;

{
realnumber[6]=number[i];
// gets the GPRS bearer delay (50);
i++;
while }
(sendATcommand("AT+SA
//Stores phone realnumber[7]=number[i];
PBR=1,1", "OK", 20000) == 0)
number
{ i++;
number[i] =
delay(5000); Serial.read();
realnumber[8]=number[i];
}
break;
}

23
} if (b==1){ ATcommand, char*
expected_answer,
} get_GPS(); unsigned int timeout){
//Check phone number send_HTTP();

for (int i=0;i<9;i++){ delay(500); uint8_t x=0, answer=0;


if (realnumber[i] == if (c==1){ char response[100];
mynumber[i]){
sendSMS(); unsigned long previous;
a++;
delay(100);
if( a==9){
c=0; memset(response, '\0',
} 100); // Initialice the string
Serial.println("Correct
number"); }

} delay(100);
sendATcommand("ATH",
"OK", 1000);

if(b==1){ void power_on(){ while( Serial.available()


> 0) Serial.read(); //
b=0; Clean the input buffer

}else{ uint8_t answer=0;

b=1; if (ATcommand[0] !=
'\0')
c=1;
digitalWrite(onModulePin,H {
} IGH);
break; delay(3000); Serial.println(ATcommand);
} // Send the AT command

}else{ digitalWrite(onModulePin,L }
OW);

Serial.println("Wrong
number"); while(answer == 0){ //
Send AT every two x = 0;
break;
seconds and wait for the previous = millis();
} answer

} answer =
sendATcommand("AT", // this loop waits for the
a=0; "OK", 2000); answer
answer=0; } do{
flag = 0; } if(Serial.available() !=
} 0){ // if there are data in
the UART input buffer,
//Send SMS once and int8_t reads it and checks for the
position to HTTP sendATcommand(char* asnwer

24
response[x] = delay(3000);
Serial.read(); sendATcommand("AT+CG
PSSTATUS?", "3D Fix", 5000))
digitalWrite(onModulePin,L == 0 ) &&
//Serial.print(response[x]); OW);
((millis() - previous) <
x++; 90000));
if (strstr(response, // waits for an answer
expected_answer) != from the module
NULL) // check if the if ((millis() - previous) <
desired answer (OK) is in while(answer == 0){ 90000)
the response of the // Send AT every
module {
two seconds and wait for
{ the answer return 1;

answer = 1; answer = }
sendATcommand("AT",
} "OK", 2000); else

} } {

}while((answer == 0) && } return 0;


((millis() - previous) < }
timeout)); // Waits for the
asnwer with time out } }

return answer; int8_t start_GPS(){ int8_t get_GPS(){

unsigned long previous; int8_t counter, answer;

void power_onGPS(){ long previous;

previous = millis();
uint8_t answer=0; // starts the GPS // First get the NMEA
string

sendATcommand("AT+CG // Clean the input buffer


// checks if the module
is started PSPWR=1", "OK", 2000); while( Serial.available()
> 0) Serial.read();
answer =
sendATcommand("AT", sendATcommand("AT+CG // request Basic string
"OK", 2000); PSRST=0", "OK", 2000);

if (answer == 0) sendATcommand("AT+CG
// waits for fix GPS PSINF=0",
{ "AT+CGPSINF=0\r\n\r\n",
// power on pulse while(( 2000);
(sendATcommand("AT+CG
PSSTATUS?", "2D Fix", 5000)
digitalWrite(onModulePin,H || counter = 0;
IGH);

25
answer = 0; * Sign '+' is set for positive
strcpy(latitude,strtok(NULL, latitudes/longitudes (North,
memset(frame, '\0', ",")); // Gets latitude East)
100); // Initialize the string
* Sign '-' is set for negative
previous = millis(); strcpy(altitude,strtok(NULL, latitudes/longitudes (South,
// this loop waits for the ".")); // Gets altitude West)
NMEA string strtok(NULL, ","); *
do{ strcpy(date,strtok(NULL, */
".")); // Gets date
int8_t
if(Serial.available() != strtok(NULL, ","); convert2Degrees(char*
0){ input){
strtok(NULL, ",");
frame[counter] =
Serial.read(); strcpy(satellites,strtok(NULL, float deg;
counter++; ",")); // Gets satellites
float minutes;
// check if the boolean neg = false;
desired answer is in the strcpy(speedOTG,strtok(NU
response of the module LL, ",")); // Gets speed over
ground. Unit is knots.
if (strstr(frame, "OK") //auxiliar variable
!= NULL)
strcpy(course,strtok(NULL, char aux[10];
{ "\r")); // Gets course
answer = 1;
if (input[0] == '-')
}
convert2Degrees(latitude); {
}
neg = true;
// Waits for the asnwer convert2Degrees(longitud
with time out strcpy(aux,
e); strtok(input+1, "."));
}

while((answer == 0) && return answer;


((millis() - previous) < }
2000)); } else
{
frame[counter-3] = '\0'; /* convert2Degrees ( input strcpy(aux,
) - performs the conversion strtok(input, "."));
from input
// Parses the string }
* parameters in
strtok(frame, ","); DD°MM.mmm’ notation to
DD.dddddd° notation.
// convert string to
strcpy(longitude,strtok(NUL * integer and add it to final
L, ",")); // Gets longitude float variable

deg = atof(aux);

26
index++;
strcpy(aux, strtok(NULL, float numberFloat=deg;
'\0'));
int intPart[10];
minutes=atof(aux); numberFloat=(numberFloa
int digit; t-(int)numberFloat);
minutes/=1000000;
long for (int i=1; i<=6 ; i++)
if (deg < 100) newNumber=(long)numbe
rFloat; {
{
int size=0;
minutes += deg; numberFloat=numberFloat
deg = 0; *10;
while(1){ digit=
}
size=size+1; (long)numberFloat;
else
digit=newNumber%10;
{ numberFloat=numberFloat
-digit;
minutes += int(deg) % newNumber=newNumber/
100; 10;
input[index]=char(digit)+48
deg = int(deg) / 100; intPart[size-1]=digit; ;
} if (newNumber==0){ index++;
break; }
// add minutes to } input[index]='\0';
degrees
}
deg=deg+minutes/60;

int index=0; }
if( neg ){
if (neg == true)
index++; void send_HTTP(){
{
input[0]='-';
deg*=-1.0;
} uint8_t answer=0;
}
for (int i=size-1; i >= 0; i--) // Initializes HTTP service
{ answer =
neg = false; sendATcommand("AT+HTT
PINIT", "OK", 10000);
input[index]=intPart[i]+'0';
if( deg < 0 ){ if (answer == 1)
index++;
neg = true; {
}
deg*=-1; // Sets CID parameter

} answer =
input[index]='.'; sendATcommand("AT+HTT

27
PPARA=\"CID\",1", "OK", // checks if the module
5000); Serial.println(F("Error getting is started
url"));
if (answer == 1) answer =
} sendATcommand("AT",
{ "OK", 2000);
// Sets url if (answer == 0)
}
sprintf(aux_str, {
"AT+HTTPPARA=\"URL\",\"ht else
tp://%s/demo_sim908.php // power on pulse
?", url); {

Serial.print(aux_str); digitalWrite(onModulePin,H
Serial.println(F("Error setting IGH);
sprintf(frame, the url"));
"visor=false&latitude=%s&lo delay(3000);
ngitude=%s&altitude=%s&ti }
me=%s&satellites=%s&spee }
dOTG=%s&course=%s", digitalWrite(onModulePin,L
else OW);
latitude, longitude,
altitude, date, satellites, {
speedOTG, course); // waits for an answer
Serial.println(F("Error
Serial.print(frame); setting the CID")); from the module

answer = } while(answer == 0){


sendATcommand("\"", // Send AT every two
"OK", 5000); } seconds and wait for the
answer
if (answer == 1) else
answer =
{ { sendATcommand("AT",
Serial.println(F("Error "OK", 2000);
// Starts GET
action initializating")); }

answer = } }
sendATcommand("AT+HTT
PACTION=0",
"+HTTPACTION:0,200", }
30000); sendATcommand("AT+HTT
PTERM", "OK", 5000);
if (answer == 1)
void sendSMS(){
{
}
sendATcommand("AT+CPI
N=****", "OK", 2000);
Serial.println(F("Done!")); void power_onSMS(){

} delay(3000);
else uint8_t answer=0;

28
}
Serial.println("Connecting
to the network..."); Serial.print(" /
Longitude: ");

i = 0;
while(
(sendATcommand("AT+CR
EG?", "+CREG: 0,1", 500) || while(longitude[i]!=0){

sendATcommand("AT+CRE Serial.print(longitude[i]);
G?", "+CREG: 0,5", 500)) == i++;
0 );
}

Serial.write(0x1A);
Serial.print("Setting SMS
mode..."); answer =
sendATcommand("", "OK",
20000);
sendATcommand("AT+CM
GF=1", "OK", 1000); // sets if (answer == 1)
the SMS mode to text
{
Serial.println("Sending
SMS"); Serial.print("Sent ");

else
sprintf(aux_string,"AT+CMG {
S=\"%s\"", phone_number);
Serial.print("error ");
answer =
sendATcommand(aux_strin }
g, ">", 2000); // send the
}
SMS number
else
if (answer == 1)
{
{
Serial.print("error ");
Serial.print("Help me!
I've been stolen. Find me Serial.println(answer,
in:"); DEC);
Serial.print("Latitude: }
");

int i = 0;
}

while(latitude[i]!=0){

Serial.print(latitude[i]);

i++;

29

You might also like