-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPS_V2.ino
113 lines (96 loc) · 2.98 KB
/
GPS_V2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//GPSTRACKER.v2
//ABIGAIL COULSON
//1827159
//GROUP 01
//Software serial is the library used to allow serial communication from digital pins on the arduino,
//TinyGPS is the library we are using to format the data collected from the tracker.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
//Establishing the SoftwareSerial pins
int RX = 3;
int TX = 4;
//Variable to set the baud rate, baud rate is the rate at which information is transferred (9600 bits per second)
int BR = 9600;
//Creating the GPS object
TinyGPSPlus gps;
//Declaring the software serial object
SoftwareSerial SoftSer(RX, TX);
void setup()
{
//Start the arduino up
Serial.begin(9600);
// Start up the software serial port
SoftSer.begin(BR);
}
//*****************************************************************************************************************************************
void loop()
{
//While there is information available through the software serial.
while (SoftSer.available() > 0)
//Read the information... THEN GO TO THE FORMATTING LOOP TO PROCESS THE INFORMATION INTO DATA
if (gps.encode(SoftSer.read()))
//FIND THIS FORMAT LOOP BELOW
format();
// If 5000 milliseconds pass and there are no characters coming in
// over the software serial port, show a "No GPS detected" error
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println("No GPS detected");
//while(true);
delay(30000);
}
}
void format()
{
//IF A LOCATION IS FOUND FORMAT THE LONGITUDE AND LATITUDE TO 6 DECIMAL PLACES
if (gps.location.isValid())
{
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
}
else
//IF IT IS NOT FOUND JUST PRINT A MESSAGE
{
Serial.println("N/A");
}
Serial.print("Date: ");
//IF A DATE IS FOUND FORMAT IT SO THE DAY, MONTH AND YEAR ARE SEPERATED BY A /
if (gps.date.isValid())
{
Serial.print(gps.date.day());
Serial.print("/");
Serial.print(gps.date.month());
Serial.print("/");
Serial.println(gps.date.year());
}
else
//IF IT IS NOT FOUND JUST PRINT A MESSAGE
{
Serial.println("N/A");
}
//MAY USE THIS TO FIND THE TIME DEPENGING ON WHAT IS REQUIRED BY THE DATABASE
//FORMATTING THE TIME THE LOCATION WAS FOUND
Serial.print("Time: ");
//IF THE TIME IS FOUND, FORMAT IT SO THE HOUR, MINUTE AND SECOND ARE SERPERATED BY A :
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(":");
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(":");
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
}
//IF IT IS NOT FOUND JUST PRINT A MESSAGE
else
{
Serial.println("N/A");
}*/
Serial.println();
Serial.println();
delay(1000);
}