-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPS.ino
28 lines (23 loc) · 913 Bytes
/
GPS.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
// S.Selvabharathi B.Tech IT Rajalakshmi Engineering College
//code to connect with the gps module to microcontroller
//note: make sure that your gps module have good antenna
#include <SoftwareSerial.h>
#include <TinyGPS.h>
long lat,lon; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(13,12); // create gps sensor connection(rx,tx)
TinyGPS gps; // create gps object
void setup(){
Serial.begin(9600); // connect serial
gpsSerial.begin(74880); // connect gps sensor
}
void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
// display position
Serial.print("Position: ");
Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
Serial.print("lon: ");Serial.println(lon); // print longitude
}
}
}