microrobotics icon

NEO6MV2 GPS Module Interfaced with Arduino Uno

microrobotics | PRO | 03/11/25 10:00:13 AM UTC (Edited) | 0 ⭐ | 13903 👁️ | Never ⏰ | []
Arduino |

3.85 KB

|

None

|

0 👍

/

0 👎

/*
 * NEO-6M GPS Module Test Code
 * Author: Lucienne Swart
 * Date: 2025/03/11
 * 
 * Description:
 * This program reads data from a NEO-6M GPS module using an Arduino Uno and 
 * displays latitude, longitude, speed, number of satellites, and HDOP.
 * 
 * Wiring:
 * - GPS TX -> Arduino Pin 4 (RX)
 * - GPS RX -> Arduino Pin 3 (TX)
 * - GPS VCC -> 5V (or 3.3V depending on module)
 * - GPS GND -> GND
 *
 * Dependencies:
 * - TinyGPS++ Library (by Mikal Hart)
 * - SoftwareSerial Library (for UART communication with GPS)
 *
 * Notes:
 * - The GPS module requires some time (up to 10–15 minutes for a cold start)
 *   to acquire a satellite fix, especially when used for the first time.
 * - Ensure you are testing outdoors in an open space for the best signal reception.
 */
 
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
 
// Define pins for SoftwareSerial (adjust if needed)
static const int RXPin = 4; // Connect to TX of NEO-6M
static const int TXPin = 3; // Connect to RX of NEO-6M
static const uint32_t GPSBaud = 9600; // Default baud rate for the NEO-6M
 
// Create SoftwareSerial object for GPS communication
SoftwareSerial gpsSerial(RXPin, TXPin);
 
// Create a TinyGPS++ object
TinyGPSPlus gps;
 
void setup() {
  // Begin Serial communication for debugging output
  Serial.begin(115200);
  // Begin SoftwareSerial for the GPS module
  gpsSerial.begin(GPSBaud);
 
  Serial.println("NEO-6M GPS Comprehensive Stats");
  Serial.println("Waiting for GPS data...");
}
 
void loop() {
  // Process all available GPS data
  while (gpsSerial.available() > 0) {
    char c = gpsSerial.read();
    gps.encode(c);
  }
 
  // If new GPS location data is available, display the stats
  if (gps.location.isUpdated()) {
    Serial.println("================================");
 
    // Date Information
    Serial.print("Date: ");
    if (gps.date.isValid()) {
      Serial.print(gps.date.month());
      Serial.print("/");
      Serial.print(gps.date.day());
      Serial.print("/");
      Serial.println(gps.date.year());
    } else {
      Serial.println("INVALID");
    }
 
    // Time Information
    Serial.print("Time: ");
    if (gps.time.isValid()) {
      // Formatting to ensure two digits per field
      if (gps.time.hour() < 10) Serial.print("0");
      Serial.print(gps.time.hour());
      Serial.print(":");
      if (gps.time.minute() < 10) Serial.print("0");
      Serial.print(gps.time.minute());
      Serial.print(":");
      if (gps.time.second() < 10) Serial.print("0");
      Serial.println(gps.time.second());
    } else {
      Serial.println("INVALID");
    }
 
    // Location: Latitude and Longitude
    Serial.print("Latitude: ");
    if (gps.location.isValid()) {
      Serial.print(gps.location.lat(), 6);
    } else {
      Serial.print("INVALID");
    }
    Serial.print(" | Longitude: ");
    if (gps.location.isValid()) {
      Serial.println(gps.location.lng(), 6);
    } else {
      Serial.println("INVALID");
    }
 
    // Speed
    Serial.print("Speed: ");
    if (gps.speed.isValid()) {
      Serial.print(gps.speed.kmph());
      Serial.println(" km/h");
    } else {
      Serial.println("INVALID");
    }
 
    // Course
    Serial.print("Course: ");
    if (gps.course.isValid()) {
      Serial.print(gps.course.deg());
      Serial.println("°");
    } else {
      Serial.println("INVALID");
    }
 
    // HDOP (Horizontal Dilution of Precision)
    Serial.print("HDOP: ");
    // The HDOP value is provided in hundredths; convert it to a float value.
    if (gps.hdop.isValid()) {
      Serial.println(gps.hdop.value() / 100.0);
    } else {
      Serial.println("INVALID");
    }
 
    // Number of Satellites in view
    Serial.print("Satellites: ");
    Serial.println(gps.satellites.value());
   
    Serial.println("================================\n");
  }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎