/ Programs / GPS_Test / GPS_Test.ino
GPS_Test.ino
 1  #include <SoftwareSerial.h>
 2  #include <TinyGPS++.h>
 3  
 4  // Define GPS RX/TX pins (Use software serial for communication)
 5  SoftwareSerial gpsSerial(4, 3); // (GPS TX to Arduino 4, GPS RX to Arduino 3)
 6  TinyGPSPlus gps; // Create TinyGPS++ object
 7  
 8  void setup() {
 9      Serial.begin(9600);  // Serial monitor
10      gpsSerial.begin(9600);  // GPS module baud rate
11  
12      Serial.println("Waiting for GPS signal...");
13  }
14  
15  void loop() {
16      while (gpsSerial.available()) {
17          gps.encode(gpsSerial.read()); // Feed GPS data to the parser
18  
19          if (gps.location.isUpdated()) { // Check if new data is available
20              Serial.print("Latitude: ");
21              Serial.print(gps.location.lat(), 6); // Print latitude with 6 decimal places
22              Serial.print(" Longitude: ");
23              Serial.println(gps.location.lng(), 6); // Print longitude with 6 decimal places
24          }
25      }
26  }