Introduction
GPS (Global Positioning System) technology has become an integral part of our daily lives, from navigating to tracking objects. In this modern era of technology, GPS modules are widely used in various applications such as tracking, navigation, and geocaching. Among the GPS modules, the NEO-6M GPS module is popular due to its compact size and low power consumption.
In this article, we will explore the process of interfacing a “NEO-6M GPS module with Arduino” and learn how to read GPS data using the Arduino board.
What is NEO-6M GPS Module?
The NEO-6M GPS module is a popular GPS (Global Positioning System) receiver module that provides accurate location and time information to electronic devices. It is a compact and low-power consumption module, manufactured by U-blox, that uses a Global Navigation Satellite System (GNSS) to determine the device’s location, speed, altitude, and time. The module communicates with the device over a serial interface and provides data in the form of NMEA (National Marine Electronics Association) sentences, which can be easily parsed and used by microcontrollers such as Arduino
Hardware Components
To interface the NEO-6M GPS module with Arduino, you’ll need the following hardware components to get started.
Components | Value | Qty |
---|---|---|
Arduino UNO | – | 1 |
USB Cable Type A to B | – | 1 |
DC Power for Arduino | – | 1 |
GPS module | NEO-6M | 1 |
Jumper Wires | – | 1 |
NEO-6M Module Pinout
Pin | Label | Function |
---|---|---|
1 | VCC | Input Power pin. Connect 5 V from Arduino to the VCC pin |
2 | RX | GPS Module’s UART Rx pin. Connect to the Arduino Tx pin |
3 | TX | GPS Module’s UART Tx pin. Connect to the Arduino Rx pin |
4 | GND | Ground Connection |
NEO-6M GPS Arduino Circuit
Make connections according to the circuit diagram given below.
Wiring / Connections
Arduino | GPS module |
---|---|
5V | VCC |
GND | GND |
D4 | RX |
D5 | TX |
Installing Arduino IDE
First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.
Installing Libraries
Before you start uploading a code, download and unzip the following libraries at /Program Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.
Code
Now copy the following code and upload it to Arduino IDE Software.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial GPS_SoftSerial(5, 4);/* (Rx, Tx) */
/* Create an object named gps of the class TinyGPSPlus */
TinyGPSPlus gps;
volatile float minutes, seconds;
volatile int degree, secs, mins;
void setup() {
Serial.begin(9600); /* Define baud rate for serial communication */
GPS_SoftSerial.begin(9600); /* Define baud rate for software serial communication */
}
void loop() {
smartDelay(1000); /* Generate precise delay of 1ms */
unsigned long start;
double lat_val, lng_val, alt_m_val;
uint8_t hr_val, min_val, sec_val;
bool loc_valid, alt_valid, time_valid;
lat_val = gps.location.lat(); /* Get latitude data */
loc_valid = gps.location.isValid(); /* Check if valid location data is available */
lng_val = gps.location.lng(); /* Get longtitude data */
alt_m_val = gps.altitude.meters(); /* Get altitude data in meters */
alt_valid = gps.altitude.isValid(); /* Check if valid altitude data is available */
hr_val = gps.time.hour(); /* Get hour */
min_val = gps.time.minute(); /* Get minutes */
sec_val = gps.time.second(); /* Get seconds */
time_valid = gps.time.isValid(); /* Check if valid time data is available */
if (!loc_valid)
{
Serial.print("Latitude : ");
Serial.println("*****");
Serial.print("Longitude : ");
Serial.println("*****");
}
else
{
DegMinSec(lat_val);
Serial.print("Latitude in Decimal Degrees : ");
Serial.println(lat_val, 6);
Serial.print("Latitude in Degrees Minutes Seconds : ");
Serial.print(degree);
Serial.print("\t");
Serial.print(mins);
Serial.print("\t");
Serial.println(secs);
DegMinSec(lng_val); /* Convert the decimal degree value into degrees minutes seconds form */
Serial.print("Longitude in Decimal Degrees : ");
Serial.println(lng_val, 6);
Serial.print("Longitude in Degrees Minutes Seconds : ");
Serial.print(degree);
Serial.print("\t");
Serial.print(mins);
Serial.print("\t");
Serial.println(secs);
}
if (!alt_valid)
{
Serial.print("Altitude : ");
Serial.println("*****");
}
else
{
Serial.print("Altitude : ");
Serial.println(alt_m_val, 6);
}
if (!time_valid)
{
Serial.print("Time : ");
Serial.println("*****");
}
else
{
char time_string[32];
sprintf(time_string, "Time : %02d/%02d/%02d \n", hr_val, min_val, sec_val);
Serial.print(time_string);
}
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (GPS_SoftSerial.available()) /* Encode data read from GPS while data is available on serial port */
gps.encode(GPS_SoftSerial.read());
/* Encode basically is used to parse the string received by the GPS and to store it in a buffer so that information can be extracted from it */
} while (millis() - start < ms);
}
void DegMinSec( double tot_val) /* Convert data in decimal degrees into degrees minutes seconds form */
{
degree = (int)tot_val;
minutes = tot_val - degree;
seconds = 60 * minutes;
minutes = (int)seconds;
mins = (int)minutes;
seconds = seconds - minutes;
seconds = 60 * seconds;
secs = (int)seconds;
}
Code Explanation
This Arduino code uses the TinyGPS++ library to interface with a NEO-6M GPS module via software serial communication. It starts by defining the SoftwareSerial object, which is used to read data from the GPS module. Then, in the loop function, it uses the smartDelay function to wait for data to be available on the serial port, and then encodes and parses the GPS data using the TinyGPS++ library.
The latitude, longitude, altitude, and time data are extracted from the GPS data using various TinyGPS++ functions and then printed to the serial monitor. The DegMinSec function is used to convert the latitude and longitude data from decimal degrees to degrees, minutes, and seconds format, which is more human-readable.
Overall, this code provides a simple and easy-to-use interface between the NEO-6M GPS module and an Arduino board, allowing for accurate location and time data to be obtained and used in various projects.
Applications
Here are some applications of the NEO-6M GPS Module:
- Vehicle tracking and navigation systems
- Drones and UAVs for flight path and location tracking
- Geocaching and treasure-hunting activities
- Asset tracking and management systems
- GPS-based clock synchronization for accurate timekeeping
- Sports and fitness tracking, such as running or cycling
- Marine navigation and tracking systems
- Agriculture and farming applications, such as crop monitoring and irrigation systems
- Disaster management and emergency response systems, such as tracking the location of emergency vehicles
- Surveying and mapping applications, such as creating 3D maps or measuring land areas.
Conclusion
The NEO-6M GPS module with Arduino is a simple and easy process that opens up a whole new world of possibilities for GPS-based projects. By following the steps outlined in this article, you can easily read GPS data and use it in your projects.