Arduino Gps Project1 PDF
Arduino Gps Project1 PDF
Arduino Gps Project1 PDF
Presented by
Azhar Muhammed, Ahmed Azawi, and Iyad Basem
2nd Stage (Evening Study)
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
Arduino
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$.
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.
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:
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 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.
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
10
Figure 4 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.
System assembly:
12
Figure 6 antennas to the shield
Important Issues:
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.
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);
void setup(){ {
mynumber[0]='0'; Serial.read();
sendATcommand("AT+CLIP=1
mynumber[1]='1'; ", "OK", 1000); }
mynumber[2]='2'; }
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");
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, ",");
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++;
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