Gps giving error after compiling code discussed below

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

// Define pins for SoftwareSerial
#define RXPin 1 // GPS TX → Arduino RX
#define TXPin 0 // GPS RX → Arduino TX (optional)

// Create TinyGPS++ object
TinyGPSPlus gps;

// Create SoftwareSerial object
SoftwareSerial gpsSerial(RXPin, TXPin);

void setup() {
Serial.begin(9600); // Begin Serial Monitor communication
gpsSerial.begin(9600); // Begin GPS communication
Serial.println("Initializing GPS... Please wait for satellite lock.");
}

void loop() {
// Check if there is data available from the GPS module
while (gpsSerial.available() > 0) {
char c = gpsSerial.read(); // Read each character from GPS
gps.encode(c); // Feed character to TinyGPS++ for parsing

// If GPS has valid location data, print latitude and longitude
if (gps.location.isUpdated()) {
  Serial.print("Latitude: ");
  Serial.println(gps.location.lat(), 6); // Latitude with 6 decimal places
  Serial.print("Longitude: ");
  Serial.println(gps.location.lng(), 6); // Longitude with 6 decimal places
  Serial.println("----------------------");
}

}

// Provide feedback if no satellite data is available
if (millis() % 5000 == 0 && !gps.location.isValid()) {
Serial.println("Waiting for satellite signal...");
}
}
AFTER COMPILING THE ABOVE WITH GPS SENSOR(GY-GPS6MV2/L80-M39), NOT RECEVING ANY GPS LOCATION IN ARDUINO SERIAL MONITOR . PLEASE SUGGEST SOLUTION

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

You haven't told us which Arduino you are using.

Most Arduinos use pins 0 and 1 for the serial connection to the PC.

You need to choose other pins if you are using software serial.

The good news is that your code works if you choose different pins for software serial.

Tested on a Uno R3, with latitude and longitude set to 2 decimal places for anonymisation:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.