GYNEO6MV2 GPS Module With Arduino PDF
GYNEO6MV2 GPS Module With Arduino PDF
This guide shows how to use the NEO-6M GPS module with the Arduino to get GPS data.
GPS stands for Global Positioning System and can be used to determine position, time, and speed if you’re travelling .
The NEO-6M GPS module is also compatible with other microcontroller boards.
Use the NEO-6M GPS module with the Raspberry Pi.
Pin Wiring
The NEO-6M GPS module has four pins: VCC, RX, TX, and GND.
The module communicates with the Arduino via serial communication using the TX and RX pins, so the wiring couldn’t be simpler:
NEO-6M GPS Module Wiring to Arduino UNO
VCC 5V
GND GND
To get raw GPS data you just need to start a serial communication with the GPS module using Software Serial. Continue reading to
see how to do that.
Parts Required
Schematics
Wire the NEO-6M GPS module to your Arduino by following the schematic below.
Code
Copy the following code to your Arduino IDE and upload it to your Arduino board.
#include <SoftwareSerial.h>
// The serial connection to the GPS module
SoftwareSerial ss(4, 3);
void setup(){
Serial.begin(9600);
ss.begin(9600);
}
void loop(){
while (ss.available() > 0){
// get the byte data from the GPS
byte gpsData = ss.read();
Serial.write(gpsData);
}
}
This sketch assumes you are using pins 4 and 3 as RX and TX serial pins to establish serial communication with the GPS module.
If you’re using other pins you should edit that on the following line:
Also, if your module uses a different default baud rate than 9600 bps, you should modify the code on the following line:
ss.begin(9600);
This sketch listen to the GPS serial port, and when data is received from the module, it is sent to the serial monitor.
You should get a bunch of information in the GPS standard language, NMEA.
Each line you get int the serial monitor is an NMEA sentence.
NMEA stands for National Marine Electronics Association, and in the world of GPS, it is a standard data format supported by GPS
manufacturers.
NMEA sentences start with the $ character, and each data field is separated by a comma.
$GPGGA,110617.00,41XX.XXXXX,N,00831.54761,W,1,05,2.68,129.0,M,50.1,M,,*42$GPGSA,A,3,06,09,30,07,23,,,,,,,,4.43,2.68,3.
53*02$GPGSV,3,1,11,02,48,298,24,03,05,101,24,05,17,292,20,06,71,227,30*7C$GPGSV,3,2,11,07,47,138,33,09,64,044,28,17,
01,199,,19,13,214,*7C$GPGSV,3,3,11,23,29,054,29,29,01,335,,30,29,167,33*4E$GPGLL,41XX.XXXXX,N,00831.54761,W,11061
7.00,A,A*70$GPRMC,110618.00,A,41XX.XXXXX,N,00831.54753,W,0.078,,030118,,,A*6A $GPVTG,,T,,M,0.043,N,0.080,K,A*2C
There are different types of NMEA sentences. The type of message is indicated by the characters before the first comma.
The GP after the $ indicates it is a GPS position. The $GPGGA is the basic GPS NMEA message, that provides 3D location and
accuracy data. In the following sentence:
$GPGGA,110617.00,41XX.XXXXX,N,00831.54761,W,1,05,2.68,129.0,M,50.1,M,,*42
110617 – represents the time at which the fix location was taken, 11:06:17 UTC
41XX.XXXXX,N – latitude 41 deg XX.XXXXX’ N
00831.54761,W – Longitude 008 deg 31.54761′ W
1 – fix quality (0 = invalid; 1= GPS fix; 2 = DGPS fix; 3 = PPS fix; 4 = Real Time Kinematic; 5 = Float RTK; 6 = estimated
(dead reckoning); 7 = Manual input mode; 8 = Simulation mode)
To know what each data field means in each of these sentences, you can consult NMEA data here.
You can work with the raw data from the GPS, or you can convert those NMEA messages into a readable and useful format, by
saving the characters sequences into variables. To do that, we’re going to use the TinyGPS++ library.
This library makes it simple to get information on location in a format that is useful and easy to understand. You can click here for
more information about the TinyGPS++ Library.
Installing the TinyGPS++ Library
Follow the next steps to install the TinyGPS++ library in your Arduino IDE:
1. Click here to download the TinyGPSPlus library. You should have a .zip folder in your Downloads folder
2. Unzip the .zip folder and you should get TinyGPSPlus-master folder
4. Move the TinyGPSPlus folder to your Arduino IDE installation libraries folder
The library provides several examples on how to use it. In your Arduino IDE, you just need to go to File > Examples > TinyGPS++,
and choose from the examples provided.
Note: the examples provided in the library assume a baud rate of 4800 for the GPS module.
You need to change that to 9600 if you’re using the NEO-6M GPS module.
Getting Location Using the NEO-6M GPS Module and the TinyGPS++ Library
You can get the location in a format that is convenient and useful by using the TinyGPS++ library.
Below, we provide a code to get the location from the GPS.
This is a simplified version of one of the library examples.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup(){
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop(){
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
}
}
}
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
Then, you define the software serial RX and TX pins, as well as the GPS baud rate. If you are using other pins for software serial you
need to change that here. Also, if your GPS module uses a different default baud rate, you should also modify that.
TinyGPSPlus gps;
In the setup(), you initialize serial communication, both to see the readings on the serial monitor and to communicate with the GPS
module.
void setup() {
Serial.begin(9600);
ss.begin(GPSBaud);
}
In the loop is where you request the information. To get TinyGPS++ to work, you have to repeatedly funnel the characters to it from
the GPS module using the encode() method.
Then, you can query the gps object to see if any data fields have been updated:
if (gps.location.isUpdated()){
Serial.print("Latitude="); Serial.print(gps.location.lat(), 6);
Serial.print("Longitude="); Serial.println(gps.location.lng(), 6);
}
Getting the latitude and longitude is has simple has using gps.location.lat(), and gps.location.lng(), respectively.
Upload the code to your Arduino, and you should see the location displayed on the serial monitor.
After uploading the code, wait a few minutes while the module adjusts the position to get a more accurate data.
Getting More GPS Information Using the TinyGPS++ Library
The TinyGPS++ library allows you to get way more information than just the location, and in a simple way. Besides the location, you
can get:
date
time
speed
course
altitude
satellites
hdop
The code below exemplifies how you can get all that information in a simple way.
/*
*
* Based on the example TinyGPS++ from arduiniana.org
*
*/
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
void setup(){
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop(){
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
// Latitude in degrees (double)
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
// Longitude in degrees (double)
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
Note: the TinyGPS++ library is well commented on how to use all its functionalities .
Wrapping Up
To make a GPS data logger with the NEO-6M GPS module and the SD card module.