I am using Adafruit Ulitimate Breakout GPS module and NeoGPS and NeoSWSerial Library. Now I want the GPS to update in 30seconds once (1time in 30seconds).After it is updated I want to check the location if new location is equal to old location then it should be updated in 60seconds once(1time in 60seconds).If not the location should be new location. It should display the location every 60seconds. I tried this flow on Adafruit GPS Library, which works but I want to use NeoGPS library and do the same. Below is my adafruit library code:

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(11, 10);
Adafruit_GPS GPS(&mySerial);

#define GPSECHO  true
uint32_t timer = millis();
float old_lat,old_lon,new_lat,new_lon;

void setup()

  Serial.println("Adafruit GPS library basic test!");

void loop()                     // run over and over again
  char c = GPS.read();
  if (GPS.newNMEAreceived()) {
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another

if (GPS.fix) {

      old_lat = GPS.latitudeDegrees;
      old_lon = GPS.longitudeDegrees;
      if (timer > millis())  timer = millis();
      if (millis() - timer > 60000) {  
        timer = millis();
          Serial.println("Location 1 minute:");
          new_lat = GPS.latitudeDegrees;
          new_lon = GPS.longitudeDegrees;

          if (new_lat == old_lat){
            new_lat = old_lat;
            new_lat = GPS.latitudeDegrees;
          Serial.print("Final Latitude: ");

          if (new_lon == old_lon){
            new_lon = old_lon;
            new_lon = GPS.longitudeDegrees;
          Serial.print("Final Longitude: ");


void displaytime(){
    Serial.print("\nTime: ");
    if (GPS.hour < 10) { Serial.print('0'); }
    Serial.print(GPS.hour, DEC); Serial.print(':');
    if (GPS.minute < 10) { Serial.print('0'); }
    Serial.print(GPS.minute, DEC); Serial.print(':');
    if (GPS.seconds < 10) { Serial.print('0'); }
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    if (GPS.milliseconds < 10) {
    } else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {

This is my NeoGPS Library code in which I am using NeoSWSerial:

#include <NMEAGPS.h>
#include <NeoSWSerial.h>// import the serial library

NeoSWSerial gpsPort(11, 10); // RX is 11 (to GPS tx), TX is 10 (to GPS rx)
NMEAGPS gps; // the parser
gps_fix fix; // the struct with all the parsed values

void setup() {

  Serial.println("GPS Start");

void loop() {

  if (gps.available( gpsPort)) {
      fix = gps.read();  
      Serial.println( fix.latitude(), 6);
      Serial.println( fix.longitude(), 6);

  • you gave an incomplete description of how the program should behave .... what should happen if the location readings do not match?
    – jsotola
    Dec 10, 2019 at 8:31
  • I have made the changes if the location doesn't match then it should take the new location. But I want firstly how to update the GPS. Dec 11, 2019 at 0:20
  • @jsotola Its ok about the location but initially I want to change the update rate. Dec 11, 2019 at 5:32

1 Answer 1


It seems like using the distance feature in NeoGPS would be a good solution for this problem and it should allow you to create a buffer around the original location to filter some of the noise from the GPS readings.

Here's a page with an overview of using Distance in NeoGPS https://github.com/SlashDevin/NeoGPS/blob/master/examples/NMEAdistance/NMEAdistance.ino

  • Please edit this answer and add more information from the link into your answer. If the link goes down for whatever reason, the rest of the text as you have it does not answer the question.
    – sa_leinad
    Dec 30, 2020 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.