GPS distance and bearing to a waypoint with a NEO-6M on Arduino: design worksheet and code

A ₹1,670 design worksheet for a handheld GPS that shows distance and bearing to a saved waypoint using the haversine formula, with worked degree-to-metre figures at 28° north and an honest note on GPS accuracy.

About the author · Editorial & verification standards

  • Parts₹1,670
  • Bench time5–7 h
  • LevelIntermediate
  • ReviewedNov 2026

A ₹1,670 handheld that points you back to a saved spot. A NEO-6M GPS module gives latitude and longitude, a button saves the current position as the waypoint, and the sketch shows the distance and compass bearing to it. The page works the haversine formula through so the numbers on screen are not magic.

Scope: intermediate. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The distance table was computed by script at 28° north (roughly northern India), assuming a sphere of radius 6,371 km. GPS accuracy is a few metres at best in open sky and far worse near buildings or indoors, and the module can take a long time to get a first fix, so test outdoors. This is a learning tool, not a navigation aid for anywhere that matters.

How it works

One degree of latitude is about 111.2 km anywhere on Earth, so 0.0001° of latitude is about 11 m. A degree of longitude shrinks with the cosine of the latitude, so at 28° north 0.0001° of longitude is about 9.8 m.

The haversine formula gives the great-circle distance: a = sin²(Δlat/2) + cos(lat1)·cos(lat2)·sin²(Δlon/2), then d = 2R·asin(√a). The bearing comes from atan2(sin(Δlon)·cos(lat2), cos(lat1)·sin(lat2) − sin(lat1)·cos(lat2)·cos(Δlon)), converted to 0–360 degrees. TinyGPS++ reads and parses the NMEA text for you, and can also compute these two values itself, but writing them out shows the maths.

Bill of materials

PartQtyUnitTotal
Arduino Uno R3 (or compatible)1₹550₹550
NEO-6M GPS module with antenna1₹500₹500
16×2 LCD with I2C backpack1₹250₹250
Push button1₹10₹10
Power bank or 9 V battery with clip1₹250₹250
Breadboard1₹60₹60
Jumper wires1₹50₹50
Parts total₹1,670

Scroll the table sideways to see every column.

Prices checked Nov 2026. Shipping and tools are not included.

Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.

The numbers

Offset from 28° N, 77° EDistance
0.0001° lat, 0° lon11.1 m
0° lat, 0.0001° lon9.8 m
0.001° lat, 0° lon111.2 m
0° lat, 0.001° lon98.2 m
0.01° lat, 0.01° lon1483.3 m
Haversine with R = 6,371 km. Longitude offsets cover less ground than the same latitude offset at 28° N.

Because consumer GPS wanders by metres from reading to reading, a waypoint saved right now will show a distance of several metres when you stand on it a minute later. Show the distance only to the nearest metre and add a “you have arrived” radius of about 10 m so the display does not flicker.

Power and wiring

PartConnects toNote
NEO-6M VCC and GND5V and GNDCheck the module’s input range
NEO-6M TXD4SoftwareSerial RX
NEO-6M RXD3SoftwareSerial TX; divide to 3.3 V if the module is not 5 V tolerant
ButtonD2 to GNDInternal pull-up
LCD SDA / SCLA4 / A5Address 0x27 or 0x3F
Give the antenna a clear view of the sky; indoors the module may never lock.

The sketch

// GPS waypoint: Uno + NEO-6M + LCD + button
// Design worksheet: libraries are TinyGPSPlus, SoftwareSerial, LiquidCrystal_I2C.

#include <SoftwareSerial.h>
#include <TinyGPSPlus.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

SoftwareSerial gpsSerial(4, 3);               // RX, TX
TinyGPSPlus gps;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int BTN = 2;
const double R = 6371000.0;
const double ARRIVE_M = 10.0;

double wpLat = 0, wpLon = 0;
bool haveWp = false;

double rad(double d) { return d * PI / 180.0; }

double distanceM(double a, double b, double c, double d) {
  double dl = rad(c - a), dn = rad(d - b);
  double x = sin(dl / 2) * sin(dl / 2) + cos(rad(a)) * cos(rad(c)) * sin(dn / 2) * sin(dn / 2);
  return 2 * R * asin(sqrt(x));
}

double bearingDeg(double a, double b, double c, double d) {
  double dn = rad(d - b);
  double y = sin(dn) * cos(rad(c));
  double x = cos(rad(a)) * sin(rad(c)) - sin(rad(a)) * cos(rad(c)) * cos(dn);
  double t = atan2(y, x) * 180.0 / PI;
  return fmod(t + 360.0, 360.0);
}

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  gpsSerial.begin(9600);
  lcd.init(); lcd.backlight();
  lcd.print("Waiting for fix");
}

void loop() {
  while (gpsSerial.available()) gps.encode(gpsSerial.read());
  if (!gps.location.isValid()) return;

  if (digitalRead(BTN) == LOW) {
    delay(30);
    if (digitalRead(BTN) == LOW) {
      wpLat = gps.location.lat(); wpLon = gps.location.lng(); haveWp = true;
      while (digitalRead(BTN) == LOW) {}
    }
  }

  static unsigned long last = 0;
  if (millis() - last < 1000) return;
  last = millis();
  lcd.clear();
  if (!haveWp) { lcd.print("Press to save"); return; }
  double d = distanceM(gps.location.lat(), gps.location.lng(), wpLat, wpLon);
  double b = bearingDeg(gps.location.lat(), gps.location.lng(), wpLat, wpLon);
  if (d < ARRIVE_M) { lcd.print("Arrived"); return; }
  lcd.print((long)d); lcd.print(" m");
  lcd.setCursor(0, 1); lcd.print("Bearing "); lcd.print((int)b);
}

Bearing is relative to true north, not to where you are facing, because the module has no compass; walk a few steps and use the GPS course to tell which way you are moving. TinyGPSPlus has built-in distanceBetween and courseTo functions that give similar results. SoftwareSerial at 9600 baud is fine for this module. The sketch has been proofread but not compiled on this site.

Test plan

  1. Fix test: take it outdoors and time how long the first fix takes; it can be several minutes.
  2. Save and walk: save a waypoint, walk 50 m away and compare the distance with a measuring tape or map app.
  3. Return walk: follow the bearing back and note how close you get.
  4. Stationary drift: leave it still for 10 minutes and note how much the distance wanders.
  5. Maths check: enter two coordinates by hand and compare with an online distance calculator.
  6. Obstructed test: try under a tree or beside a wall and note the loss of accuracy.

What usually goes wrong

SymptomLikely causeFix
Never gets a fixIndoors or antenna blockedGo outdoors with open sky and wait
No text from the moduleBaud rate or wires swappedCheck 9600 baud and TX to RX crossing
Distance jumps aroundGPS errorAverage readings and widen the arrive radius
Bearing seems wrongBearing is to north, not headingUse the GPS course while walking
LCD garbledWrong I2C addressTry 0x3F

Upgrades

  • Compass: add a magnetometer so the arrow works when standing still.
  • Multiple waypoints: store several in EEPROM.
  • Logging: write a track to an SD card.
  • Rover navigation: steer a robot toward the waypoint, outdoors only.

Cost and parts notes

The ₹1,670 total is an illustration and does not include shipping. Use the cost calculator to compare sellers.

Common questions

Listings commonly quote a couple of metres in open sky, and real results vary with sky view and conditions.

It gives the distance over a curved Earth without the problems of flat-plane maths.

The module has to find satellites and download their data; it is quicker after a recent fix.

No. Satellite signals barely reach inside buildings.

Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.

More builds

Next builds to try

Free: the final-year project pack

A shortlist with BOMs, a report outline that matches the usual chapter scheme, a costing sheet and 40 viva questions. Built for the February–April submission season.

The Build Note

One short email when something is worth your bench time.

A new build sheet, a part price that moved, or a mistake worth avoiding. No daily drip, no recycled news.

One short email when a build or a price is worth your time. Unsubscribe in one click.