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
- #include
-
- # define rxGPS 3# define txGPS 5
- SoftwareSerial serialGPS = SoftwareSerial(rxGPS, txGPS);
- String stringGPS = "";
- void setup() {
- pinMode(rxGPS, INPUT);
- pinMode(txGPS, OUTPUT);
- Serial.begin(9600);
- Serial.println("Started");
-
- serialGPS.begin(4800);
- digitalWrite(txGPS, HIGH);
-
- while (serialGPS.available())
- if (serialGPS.read() == '\r')
- break;
- }
- void loop()
- {
- String s = checkGPS();
- if (s && s.substring(0, 6) == "$GPGGA")
- {
- Serial.println(s);
- }
- }
-
- String checkGPS()
- {
- if (serialGPS.available())
- {
- char c = serialGPS.read();
- if (c != '\n' && c != '\r')
- {
- stringGPS = c;
- } else
- {
- if (stringGPS != "")
- {
- String tmp = stringGPS;
- stringGPS = "";
- return tmp;
- }
- }
- }
- return false;
- }
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: