Advertisement
microrobotics

NEO M8N Mini GPS Module

Mar 31st, 2023
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The NEO-M8N GPS module communicates via UART. Here's an example of how to use the NEO-M8N GPS module with an Arduino to read and parse GPS data using the TinyGPS++ library. You can install the library using the Arduino Library Manager.
  3.  
  4. Connect the NEO-M8N GPS module to your Arduino as follows:
  5.  
  6. VCC to 5V or 3.3V (depending on your GPS module's voltage range)
  7. GND to GND
  8. TX to GPS_RX_PIN (4 in this example)
  9. RX to GPS_TX_PIN (3 in this example)
  10. Upload the complete code to your Arduino and open the Serial Monitor. The GPS module should start sending data. Once it gets a GPS fix, it will display the latitude and longitude values.
  11. */
  12.  
  13. #include <TinyGPS++.h>
  14. #include <SoftwareSerial.h>
  15.  
  16. // NEO-M8N TX and RX pins connected to Arduino
  17. #define GPS_RX_PIN 4
  18. #define GPS_TX_PIN 3
  19.  
  20. // Create a TinyGPS++ object and a SoftwareSerial object
  21. TinyGPSPlus gps;
  22. SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN);
  23.  
  24. void setup() {
  25.   // Initialize the Serial Monitor for debugging
  26.   Serial.begin(9600);
  27.   // Initialize the SoftwareSerial for the GPS module
  28.   ss.begin(9600);
  29.  
  30.   Serial.println(F("NEO-M8N Mini GPS Module"));
  31. }
  32.  
  33. void loop() {
  34.   // Read GPS data
  35.   while (ss.available() > 0) {
  36.     gps.encode(ss.read());
  37.   }
  38.  
  39.   // If new GPS data is available, print it
  40.   if (gps.location.isUpdated()) {
  41.     Serial.print(F("Latitude: "));
  42.     Serial.print(gps.location.lat(), 6);
  43.     Serial.print(F(", Longitude: "));
  44.     Serial.println(gps.location.lng(), 6);
  45.   }
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement