0

I want to extract the latitude and longitude values of my location but my gps led is not blinking. Also result appearing on the serial monitor is wrong.

This is my Arduino code:

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

SoftwareSerial gpsSerial(3, 4);
TinyGPSPlus gps;
float latitude,longitude;
void setup() {
  // put your setup code here, to run once:
  gpsSerial.begin(9600);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
while(gpsSerial.available())
  {
    int data=gpsSerial.read();
    if(gps.encode(data))
       {
          latitude = (gps.location.lat());
          longitude = (gps.location.lng());
          Serial.print("Latitude");
          Serial.println(latitude);
          Serial.print("Longitude ");
          Serial.println(longitude);
       }
   }
}

Please tell me what is wrong in the code?

  • 1
    The first thing you are doing wrong is not indenting your code. That makes anything else that's wrong with your code all but impossible to figure out. – Duncan C Mar 9 at 20:11
  • 1
    Sounds like you're not getting a lock on the satellites. You do know that it can take a LONG time to get your first lock, don't you? And also that GPS doesn't work well indoors - unless you have a high gain antenna, or lots of open windows around you. – Majenko Mar 9 at 22:50
  • if you are going to say something like my gps led is not blinking, then you also need to explain what that means – jsotola Mar 9 at 23:47
  • at a guess, if the GPS led should be blinking but it isn't, then the second problem of wrong position is irrelevant, since, if GPS isn't working, how do you expect correct GPS data – Jaromanda X Mar 10 at 2:18
  • There could be multiple problems here. Firstly, try doing near an open Window. GPS signals need LOS. Then, check your connections. If these are good, then what is the variable type you have initialized for Lat and Long? Are they long or long double? Start over from an example like this – Irfanuddin Mar 10 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.