Finding The Location Status In Arduino Mega 2560

Introduction

In this article I will explain about the correct location of a place where GPS is fixed. After that it will display in the serial monitor and can be very useful for finding location status.

Parts Of List
  • Arduino Mega 2560
  • GPS
  • BreadBoard
  • Hook Up Wires
GPS



   Figure1:
GPS
  • The Global Positioning System (GPS) is a satellite-based navigation system made up of a network of 24 placed satellites.

  • GPS works in any weather conditions, anywhere in the world, 24 hours a day.

  • There are no subscription fees or setup charges to use GPS.
Connection:
  • Connect the Gnd and 2nd pin to the Gnd of the Arduino Mega 2560.
  • Connect the Vcc to the 5V of the Arduino Mega 2560.
  • Connect the 3rd pin to the Digital pin of 3 in the board.
  • Connect the 4th pin to the digital pin of 5 in the board.
Programming

  1. #include  
  2. // GPS Setup  
  3. # define rxGPS 3# define txGPS 5  
  4. SoftwareSerial serialGPS = SoftwareSerial(rxGPS, txGPS);  
  5. String stringGPS = "";  
  6. void setup() {  
  7.     pinMode(rxGPS, INPUT);  
  8.     pinMode(txGPS, OUTPUT);  
  9.     Serial.begin(9600);  
  10.     Serial.println("Started");  
  11.     // GPS Setup  
  12.     serialGPS.begin(4800);  
  13.     digitalWrite(txGPS, HIGH);  
  14.     // Cut first gibberish  
  15.     while (serialGPS.available())  
  16.         if (serialGPS.read() == '\r')  
  17.             break;  
  18. }  
  19. void loop()   
  20. {  
  21.         String s = checkGPS();  
  22.         if (s && s.substring(0, 6) == "$GPGGA")   
  23.         {  
  24.             Serial.println(s);  
  25.         }  
  26.     }  
  27.     // Check GPS and returns string if full line recorded, else false  
  28. String checkGPS()  
  29. {  
  30.     if (serialGPS.available())  
  31.     {  
  32.         char c = serialGPS.read();  
  33.         if (c != '\n' && c != '\r')   
  34.         {  
  35.             stringGPS = c;  
  36.         } else  
  37.         {  
  38.             if (stringGPS != "")  
  39.             {  
  40.                 String tmp = stringGPS;  
  41.                 stringGPS = "";  
  42.                 return tmp;  
  43.             }  
  44.         }  
  45.     }  
  46.     return false;  
  47. }  
Explanation:

In this I have explained the location where GPS is fixed and then you can get information in the serial monitor.

Output

                                             Figure2: Output
 
Read more articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all