Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arduino Gps Project1 PDF

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

Vehicle Tracking System

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

n Dr. Omar Youssef

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

2
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 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.

3
HARDWARE:

Modules

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?

4
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 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 advanced electronics designers can create

5
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.

Figure 1 Arduino UNO

6
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

 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

7
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.

Figure 2 Arduino IDE

GPS
8
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:

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

9
Figure 3 components

GPRS+GPS shield diagram:

10
Figure 4 GPS shield

Figure 5 gps Shield

Figure 5 GPS shield

11
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

System assembly:

Connect the antennas to the shield:

12
Figure 6 antennas to the shield

Connect the shield to the Arduino:

Important Issues:

 Handle with care the internal


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

13
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
something explicit from those data but if it is used with an application designed
14
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.

15
Figure 9 code flowchart

16
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:

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
Figure 10 app diagram
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

17
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.

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.

18
Figure 12 google maps

Figure 11 SMS

Code:
#include “softwareSerial.h” int flag = 0; int b=0;
#include “TinyGPS.h” char number [20]; int c=0;
int8_t answer; char realnumber[9]; //Your phone number
int onModulePin= 2; char mynumber[9]; Char
phone_number[]="012345678";
char aux_string[30]; int a=0;

19
mynumber[8]='8'; // sets APN , user name and
password
char data[100];
int data_size;
sendATcommand("AT+SAPBR
pinMode(onModulePin, =3,1,\"Contype\",\"GPRS\"",
OUTPUT); "OK", 2000);
char aux_str[30];
Serial.begin(115200);
char aux; sendATcommand("AT+SAPBR
=3,1,\"APN\",\"*******\"",
int x = 0;
"OK", 2000);
power_on();
char N_S,W_E;
power_onGPS();
sendATcommand("AT+SAPBR
power_onSMS(); =3,1,\"USER\",\"*******\"",
char url[] = "OK", 2000);
"pruebas.libelium.com";

delay(5000); sendATcommand("AT+SAPBR
char frame[200]; =3,1,\"PWD\",\"*******\"",
"OK", 2000);

char latitude[15]; sendATcommand("AT+CPIN=*


***", "OK", 2000); // gets the GPRS bearer
char longitude[15];
while
(sendATcommand("AT+SAPB
delay(3000); R=1,1", "OK", 20000) == 0)
char altitude[6];
{
char date[16];
delay(5000);
char time[7];
while( (sendATcommand("AT+
}
char satellites[3]; CREG?", "+CREG: 0,1", 1000)
||
char speedOTG[10]; sendATcommand("AT+CREG?
", "+CREG: 0,5", 1000)) == 0 ); delay(1000);
char course[10];
while(Serial.available() != 0)

void setup(){ {

mynumber[0]='0'; Serial.read();
sendATcommand("AT+CLIP=1
mynumber[1]='1'; ", "OK", 1000); }

mynumber[2]='2'; }

mynumber[3]='3'; void loop(){


while ( start_GPS() == 0);
mynumber[4]='4';
mynumber[5]='5'; while answer =
(sendATcommand("AT+CREG? sendATcommand("", "+CLIP",
mynumber[6]='6'; 1000);
", "+CREG: 0,1", 2000) == 0);
mynumber[7]='7'; //Detect incomming call

20
if (answer == 1) i++; c=1;
{ }
realnumber[3]=number[i];
Serial.println("Incoming break;
call"); i++;
}
}else{
realnumber[4]=number[i];
if ( flag == 0){
i++;
Serial.println("Wrong number");

for (int i=0; i<19; i++){ break;


realnumber[5]=number[i];
// read the incoming }
i++;
byte:
}
while
realnumber[6]=number[i]; a=0;
(Serial.available() == 0)
i++; answer=0;
{
flag = 0;
delay (50);
realnumber[7]=number[i]; }
}
i++; //Send SMS once and position to
//Stores phone number
HTTP
number[i] = realnumber[8]=number[i]; if (b==1){
Serial.read();
break; get_GPS();
} send_HTTP();
}
} delay(500);
Serial.flush();
//Check phone number if (c==1){
flag = 1;
for (int i=0;i<9;i++){ sendSMS();
}
if (realnumber[i] == delay(100);
//Stores phone calling mynumber[i]){
number c=0;
a++;
for (int i=0; i<=14; i++){ }
if( a==9){
if(number[i]== '"'){ }
Serial.println("Correct
i++; number"); }

realnumber[0]=number[i]; sendATcommand("ATH",
void power_on(){
"OK", 1000);
i++;
if(b==1){
uint8_t answer=0;
realnumber[1]=number[i]; b=0;

i++; }else{
b=1;
realnumber[2]=number[i];

21
digitalWrite(onModulePin,HIG Serial.println(ATcommand); //
uint8_t answer=0;
H); Send the AT command
delay(3000); }
// checks if the module is
started
digitalWrite(onModulePin,LOW
); answer =
x = 0; sendATcommand("AT", "OK",
2000);
previous = millis();
while(answer == 0){ // if (answer == 0)
Send AT every two seconds and
wait for the answer {
// this loop waits for the
answer = answer // power on pulse
sendATcommand("AT", "OK",
2000); do{
digitalWrite(onModulePin,HIG
} if(Serial.available() != 0){ H);
// if there are data in the UART
} input buffer, reads it and checks delay(3000);
for the asnwer
response[x] = digitalWrite(onModulePin,LOW
int8_t sendATcommand(char*
Serial.read(); );
ATcommand, char*
expected_answer, unsigned int
timeout){ //Serial.print(response[x]);
// waits for an answer from
x++; the module
uint8_t x=0, answer=0; if (strstr(response, while(answer == 0){
char response[100]; expected_answer) != NULL) //
check if the desired answer // Send AT every two
unsigned long previous; (OK) is in the response of the seconds and wait for the answer
module answer =
{ sendATcommand("AT", "OK",
memset(response, '\0', 2000);
100); // Initialice the string answer = 1;
}
}
}
delay(100); }
}while((answer == 0) &&
((millis() - previous) < }
while( Serial.available() > 0) timeout)); // Waits for the
Serial.read(); // Clean the input asnwer with time out
buffer int8_t start_GPS(){

return answer;
if (ATcommand[0] != '\0') unsigned long previous;
}
{
previous = millis();
void power_onGPS(){

22
// starts the GPS while( Serial.available() > 0)
Serial.read();
// Parses the string
sendATcommand("AT+CGPSP // request Basic string
WR=1", "OK", 2000); strtok(frame, ",");

sendATcommand("AT+CGPSI
sendATcommand("AT+CGPSR NF=0", strcpy(longitude,strtok(NULL,
ST=0", "OK", 2000); "AT+CGPSINF=0\r\n\r\n", ",")); // Gets longitude
2000);
strcpy(latitude,strtok(NULL,
",")); // Gets latitude
// waits for fix GPS
counter = 0; strcpy(altitude,strtok(NULL,
".")); // Gets altitude
while(( (sendATcommand("AT answer = 0;
strtok(NULL, ",");
+CGPSSTATUS?", "2D Fix", memset(frame, '\0', 100); //
5000) || Initialize the string strcpy(date,strtok(NULL,
".")); // Gets date
previous = millis();
sendATcommand("AT+CGPSS strtok(NULL, ",");
TATUS?", "3D Fix", 5000)) == // this loop waits for the
0 ) && NMEA string strtok(NULL, ",");

((millis() - previous) < do{ strcpy(satellites,strtok(NULL,


90000)); ",")); // Gets satellites

if(Serial.available() != 0){ strcpy(speedOTG,strtok(NULL,


if ((millis() - previous) < ",")); // Gets speed over ground.
90000) frame[counter] =
Serial.read(); Unit is knots.
{ strcpy(course,strtok(NULL,
counter++;
"\r")); // Gets course
return 1;
// check if the desired
} answer is in the response of the
module convert2Degrees(latitude);
else
if (strstr(frame, "OK") != convert2Degrees(longitude);
{ NULL)
return 0; {
} return answer;
answer = 1;
} }
}
}
int8_t get_GPS(){ /* convert2Degrees ( input ) -
// Waits for the asnwer with
performs the conversion from
time out
input
}
int8_t counter, answer; * parameters in
while((answer == 0) && DD°MM.mmm’ notation to
long previous; DD.dddddd° notation.
((millis() - previous) < 2000));
*
// First get the NMEA string
frame[counter-3] = '\0';
// Clean the input buffer

23
* Sign '+' is set for positive minutes=atof(aux); long
latitudes/longitudes (North, newNumber=(long)numberFloat
East) minutes/=1000000; ;
* Sign '-' is set for negative if (deg < 100) int size=0;
latitudes/longitudes (South, {
West)
minutes += deg;
* while(1){
deg = 0;
*/ size=size+1;
}
int8_t convert2Degrees(char* digit=newNumber%10;
input){ else
{ newNumber=newNumber/10;
float deg; minutes += int(deg) % 100; intPart[size-1]=digit;
float minutes; deg = int(deg) / 100; if (newNumber==0){
boolean neg = false; } break;
}
//auxiliar variable // add minutes to degrees }
char aux[10]; deg=deg+minutes/60;

int index=0;
if (input[0] == '-') if( neg ){
{ if (neg == true) index++;
neg = true; { input[0]='-';
strcpy(aux, strtok(input+1, deg*=-1.0; }
"."));
} for (int i=size-1; i >= 0; i--)
{
}
neg = false; input[index]=intPart[i]+'0';
else
index++;
{
if( deg < 0 ){ }
strcpy(aux, strtok(input,
".")); neg = true;

} deg*=-1; input[index]='.';
} index++;

// convert string to integer and


add it to final float variable
float numberFloat=deg; numberFloat=(numberFloat-
deg = atof(aux); (int)numberFloat);
int intPart[10];
for (int i=1; i<=6 ; i++)
int digit;
strcpy(aux, strtok(NULL, {
'\0'));

24
%s&time=%s&satellites= {
numberFloat=numberFloat*10; %s&speedOTG=%s&course=
%s", Serial.println(F("Error
digit= (long)numberFloat; setting the CID"));
latitude, longitude,
numberFloat=numberFloat- altitude, date, satellites, }
digit; speedOTG, course); }
input[index]=char(digit) Serial.print(frame); else
+48;
answer = {
index++; sendATcommand("\"", "OK",
5000); Serial.println(F("Error
}
initializating"));
if (answer == 1)
input[index]='\0';
}
{
// Starts GET action
answer =
} sendATcommand("AT+HTTPT
sendATcommand("AT+HTTPA
ERM", "OK", 5000);
CTION=0",
"+HTTPACTION:0,200",
void send_HTTP(){ 30000);
}
if (answer == 1)

uint8_t answer=0; {
void power_onSMS(){
// Initializes HTTP service
answer =
sendATcommand("AT+HTTPI Serial.println(F("Done!")); uint8_t answer=0;
NIT", "OK", 10000);
}
if (answer == 1)
else // checks if the module is
{ started
{
// Sets CID parameter answer =
sendATcommand("AT", "OK",
answer = Serial.println(F("Error getting 2000);
sendATcommand("AT+HTTPP url"));
ARA=\"CID\",1", "OK", 5000); if (answer == 0)
}
if (answer == 1) {
{ // power on pulse
}
// Sets url
else digitalWrite(onModulePin,HIG
sprintf(aux_str,
"AT+HTTPPARA=\"URL\",\"ht { H);
tp://%s/demo_sim908.php?", delay(3000);
url); Serial.println(F("Error
setting the url"));
Serial.print(aux_str);
} digitalWrite(onModulePin,LOW
sprintf(frame, );
"visor=false&latitude= }
%s&longitude=%s&altitude= else

25
// waits for an answer from }
the module sprintf(aux_string,"AT+CMGS=
else
\"%s\"", phone_number);
while(answer == 0){ //
Send AT every two seconds and {
answer =
wait for the answer sendATcommand(aux_string, Serial.print("error ");
">", 2000); // send the SMS
answer = Serial.println(answer,
number
sendATcommand("AT", "OK", DEC);
2000); if (answer == 1)
}
} {
} Serial.print("Help me! I've
been stolen. Find me in:"); }

Serial.print("Latitude: ");
}
int i = 0;
while(latitude[i]!=0){
void sendSMS(){
Serial.print(latitude[i]);

sendATcommand("AT+CPIN=* i++;
***", "OK", 2000);
}
Serial.print(" /
delay(3000); Longitude: ");
i = 0;
while(longitude[i]!=0){
Serial.println("Connecting to
the network...");
Serial.print(longitude[i]);
i++;
while( (sendATcommand("AT+ }
CREG?", "+CREG: 0,1", 500) ||
Serial.write(0x1A);

sendATcommand("AT+CREG? answer =
", "+CREG: 0,5", 500)) == 0 ); sendATcommand("", "OK",
20000);
if (answer == 1)
Serial.print("Setting SMS
mode..."); {
Serial.print("Sent ");
sendATcommand("AT+CMGF= }
1", "OK", 1000); // sets the
SMS mode to text else

Serial.println("Sending {
SMS");
Serial.print("error ");
}

26

You might also like