#include "SoftwareSerial.h" #include "nmea.h" #include #include "math.h" Servo myservo; // create servo object to control a servo Servo myservo2; NMEA gps(GPRMC); //remember to download and include NMEA libry SoftwareSerial Serial2(5, 3); int prev_lat; int prev_lon; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo2.attach(6); Serial.begin(9600); Serial.println("Initializing..."); Serial2.begin(9600); // GPS devices frequently operate at 4800 baud } void loop() { drive(); delay(10); if (Serial2.available() > 0 ) { // read incoming character from GPS char c = Serial2.read(); //Serial.print(gps.gprmc_status()); //to get gps status //Serial.print(gps.gprmc_speed(MPS));//to get GPS speed // check if the character completes a valid GPS sentence if (gps.decode(c)) { // check if GPS positioning was active if (gps.gprmc_status() == 'A') { Serial.println("latitude : "); float lat = gps.gprmc_latitude() Serial.println(lat,5);//to 5 decimal places (acuracy of 1.1m) Serial.print("longitude : "); float lon = gps.gprmc_longitude(); Serial.println(lon,5); } } } //gprmc_course() //Returns direction of movement } void drive() { myservo.write(40); // rotate counterclockwise full speed myservo2.write(120); } void turn_right() //90 degrees { myservo.write(120); // rotate counterclockwise full speed myservo2.write(120); } void turn_left()//90 degrees { myservo.write(40); // rotate counterclockwise full speed myservo2.write(40); } void motor_stop() { myservo.write(90); // rotate counterclockwise full speed myservo2.write(90); }