// This is my first very simple GPS navigation tool, that
// was written for my Wiring board. It connects to a GPS
// module via port Serial1 (4800bps) and shows some very
// basic navigation information on a character-based LCD.
// The information shown is:
// - direction to destination, relative to own movement
// - distance to destination in meters (it is really
// easy to do kilometers, miles, etc.)
// - my current speed in kilometers per hour
// - GPS status identifier
//
// I tried it in my car, and it works perfectly, although
// it's quite useless. The code below uses the Wiring
// board diagnostic LED on pin 48, which does not exist
// on Arduino's -- be aware.
#include <math.h>
#include <nmea.h>
#include <LiquidCrystal.h>
#include <NewSoftSerial.h>
NewSoftSerial mygps(7, 8);
// create connection to GPRMC sentences from my GPS
NMEA myGPS(GPRMC);
// create LCD object (I use a 2x16 character display)
LiquidCrystal myLCD = LiquidCrystal(12, 11, 5, 4, 3, 2);
// my destination coordinates in signed degrees-decimal
float dest_latitude = 25.362023;
float dest_longitude = 68.355542;
//25.362023, 68.355542
void setup() {
myLCD.begin(16,2);
mygps.begin(4800);
pinMode(13, OUTPUT); // diagnostic led on Wiring-board
myLCD.clear();
myLCD.home();
myLCD.print("GPS-NAV By Eshu");
delay(1000);
}
void loop() {
// check if data from GPS available on Serial1 port
if (mygps.available() > 0 ) {
// check if full sentence recieved from GPS
if (myGPS.decode(mygps.read())) {
// if so, set status led on
digitalWrite(13, HIGH);
// calculate direction to destination, relative to my own direction of movement
float lat = myGPS.gprmc_latitude();
float longi = myGPS.gprmc_longitude();
myLCD.clear();
myLCD.home();
myLCD.setCursor(0, 0);
myLCD.print("lat:");
myLCD.print(lat);
myLCD.setCursor(0, 1);
myLCD.print("longi:");
myLCD.print(longi);
myLCD.setCursor(15, 1);
myLCD.print(myGPS.gprmc_status());
}
}
}
i am using the following code for the latitude and Longitude display on LCD
and the result is continuously varying and i am taking this code for my direction code that is
// This is my first very simple GPS navigation tool, that
// was written for my Wiring board. It connects to a GPS
// module via port Serial1 (4800bps) and shows some very
// basic navigation information on a character-based LCD.
// The information shown is:
// - direction to destination, relative to own movement
// - distance to destination in meters (it is really
// easy to do kilometers, miles, etc.)
// - my current speed in kilometers per hour
// - GPS status identifier
//
// I tried it in my car, and it works perfectly, although
// it's quite useless. The code below uses the Wiring
// board diagnostic LED on pin 48, which does not exist
// on Arduino's -- be aware.
#include <math.h>
#include <nmea.h>
#include <LiquidCrystal.h>
#include <NewSoftSerial.h>
NewSoftSerial mygps(7, 8);
// create connection to GPRMC sentences from my GPS
NMEA myGPS(GPRMC);
// create LCD object (I use a 2x16 character display)
LiquidCrystal myLCD = LiquidCrystal(12, 11, 5, 4, 3, 2);
// my destination coordinates in signed degrees-decimal
float dest_latitude = 25.362023;
float dest_longitude = 68.355542;
//25.362023, 68.355542
void setup() {
myLCD.begin(16,2);
mygps.begin(4800);
pinMode(13, OUTPUT); // diagnostic led on Wiring-board
myLCD.clear();
myLCD.home();
myLCD.print("GPS-NAV By Eshu");
delay(1000);
}
void loop() {
// check if data from GPS available on Serial1 port
if (mygps.available() > 0 ) {
// check if full sentence recieved from GPS
if (myGPS.decode(mygps.read())) {
// if so, set status led on
digitalWrite(13, HIGH);
// calculate direction to destination, relative to my own direction of movement
float dir = myGPS.gprmc_course_to(dest_latitude, dest_longitude) - myGPS.gprmc_course();
if (dir < 0) { dir += 360; }
if (dir > 180) { dir -= 360; }
// display relative direction to destination
myLCD.clear();
myLCD.home();
if (dir < 0) {
myLCD.print('<'); // destination is to your left
} else {
myLCD.print('>'); // destination is to your right
}
myLCD.print(abs(dir), DEC);
myLCD.print(223, BYTE); // print °-character
// display distance to destination in meters
myLCD.setCursor(0, 1);
myLCD.print("D:");
myLCD.print(round(myGPS.gprmc_distance_to(dest_latitude, dest_longitude, MTR)));
myLCD.print("m");
// display my speed in kilometers per hour
myLCD.setCursor(5, 0);
myLCD.print("S:");
myLCD.print(round(myGPS.gprmc_speed(KMPH)),DEC);
myLCD.print("Km/h");
// display GPS positioning status ('A'=active, 'V'=void)
myLCD.setCursor(15, 1);
myLCD.print(myGPS.gprmc_status());
// set status led off
digitalWrite(13, LOW);
}
}
}