{"id":167096,"date":"2025-03-04T07:40:52","date_gmt":"2025-03-04T07:40:52","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=167096"},"modified":"2025-03-13T10:39:43","modified_gmt":"2025-03-13T10:39:43","slug":"arduino-neo-m8n-gps-module","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-neo-m8n-gps-module\/","title":{"rendered":"Arduino with NEO-M8N GPS Module: Get Latitude, Longitude, Altitude, Date and Time"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to interface the Arduino board with NEO-M8N GPS module. You&#8217;ll learn how to connect the module to the board and how to program it to get GPS data: latitude, longitude, altitude, UTC time, number of visible satellites, and more.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with NEO-M8N GPS Module\" class=\"wp-image-167107\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>This is what you&#8217;ll learn with this guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Wire the NEO-M8N GPS module to the Arduino via serial;<\/li>\n\n\n\n<li>Get raw GPS data;<\/li>\n\n\n\n<li>Parse raw data to obtain selected and readable GPS information using the <span class=\"rnthl rntliteral\">TinyGPSPlus<\/span> library.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Table of Contents<\/h2>\n\n\n\n<p>We&#8217;ll cover the following subjects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#intro-neom8n\" title=\"\">Introducing the NEO-M8N GPS Module<\/a><\/li>\n\n\n\n<li><a href=\"#arduino-neo-m8n-wiring\" title=\"\">Wiring the NEO-M8N GPS Module to the Arduino<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/test-neo-m8n-arduino-raw-data\" title=\"\">Getting Raw GPS Data &#8211; Testing the NEO-M8N GPS Module <\/a><a href=\"#test-neo-m8n-arduino-raw-data\" title=\"\">w<\/a><a href=\"http:\/\/test-neo-m8n-arduino-raw-data\" title=\"\">ith the Arduino<\/a><\/li>\n\n\n\n<li><a href=\"#parsing-nmea-sentences\" title=\"\">Parsing NMEA Sentences with TinyGPSPlus Library<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intro-neom8n\">Introducing the NEO-M8N GPS Module<\/h2>\n\n\n\n<p>The NEO-M8N GPS module is one of the most popular GPS receivers used with microcontrollers in navigation and tracking projects. It can get data about latitude, longitude, altitude, and time.<\/p>\n\n\n\n<p>It supports multiple satellite systems, including GPS, Galileo, GLONASS, and BeiDou. It offers better satellite tracking than the <a href=\"https:\/\/randomnerdtutorials.com\/guide-to-neo-6m-gps-module-with-arduino\/\" title=\"\">NEO-6M<\/a>, making it more reliable in challenging conditions.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/M8N-GPS-Module.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"NEO-M8N-GPS-Module\" class=\"wp-image-166757\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/M8N-GPS-Module.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/M8N-GPS-Module.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>According to the datasheet, it has a horizontal position accuracy of 2.5 to 4 meters and quick startup times (1 second for hot start, 26\u201357 seconds for cold start\u2014expect longer times if you&#8217;re close to buildings).<\/p>\n\n\n\n<p>The module includes a backup battery, built-in EEPROM, and an LED indicator that blinks when a position fix is achieved.<\/p>\n\n\n\n<p>This module typically comes with a ceramic GPS antenna. But, you can change it to any other compatible antenna that might suit your project better. For example, I like to use the one at the right in the picture below because it is waterproof, and the antenna comes with a long cable which allows for more flexibility.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/antennas-for-GPS-Modules.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"antennas for GPS modules\" class=\"wp-image-160852\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/antennas-for-GPS-Modules.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/antennas-for-GPS-Modules.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The NEO-M8N GPS Module communicates with a microcontroller using Serial communication protocol, and works with standard NMEA sentences. NMEA stands for National Marine Electronics Association, and in the world of GPS, it is a standard data format supported by GPS manufacturers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Where to buy?<\/h3>\n\n\n\n<p>You can check our Maker Advisor Tools page to compare the NEO-M8N GPS receiver module price in different stores:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/neo-m8n-gps-module\/\" target=\"_blank\" rel=\"noopener\" title=\"\">NEO-M8N GPS Receiver Module<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"arduino-neo-m8n-wiring\">Wiring the NEO-M8N GPS Module to the Arduino<\/h2>\n\n\n\n<p>To communicate with the NEO-6M GPS module, we\u2019ll use software serial, so you can use any available Pins. We\u2019ll use Pin5 (TX &#8211;&gt; connects to the module RX) and Pin6 (RX &#8211;&gt; connects to the module TX).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"512\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-neo-m8n-gps-module_bb.png?resize=900%2C512&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Wiring the NEO-M8N GPS Module to the Arduino\" class=\"wp-image-167129\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-neo-m8n-gps-module_bb.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-neo-m8n-gps-module_bb.png?resize=300%2C171&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-neo-m8n-gps-module_bb.png?resize=768%2C437&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>NEO-M8N GPS Module<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td>VCC<\/td><td><span class=\"rnthl rntcred\">5V<\/span><\/td><\/tr><tr><td>RX<\/td><td><span class=\"rnthl rntclgreen\">Pin 5<\/span><\/td><\/tr><tr><td>TX<\/td><td><span class=\"rnthl rntcyellow\">Pin 6<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"test-neo-m8n-arduino-raw-data\">Getting Raw GPS Data &#8211; Testing the NEO-M8N GPS Module with the Arduino<\/h2>\n\n\n\n<p>To get raw GPS data you need to start a serial communication with the GPS module and read the available data.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/ESP32-M8N-GPS-Module-Get-Raw-Data.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 with NEO-M8N GPS Module - Get Raw Data\" class=\"wp-image-166758\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/ESP32-M8N-GPS-Module-Get-Raw-Data.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/ESP32-M8N-GPS-Module-Get-Raw-Data.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The following code establishes a serial communication with the GPS module and reads the available data.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/arduino-neo-m8n-gps-module\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.  \n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\n#include &lt;SoftwareSerial.h&gt;\n\nstatic const int RXPin = 6, TXPin = 5;\nstatic const uint32_t GPSBaud = 9600;\n\n\/\/ The serial connection to the GPS module\nSoftwareSerial gpsSerial(RXPin, TXPin);\n\nvoid setup(){\n  Serial.begin(9600);\n  gpsSerial.begin(GPSBaud);\n}\n\nvoid loop(){\n  while (gpsSerial.available() &gt; 0){\n    \/\/ get the byte data from the GPS\n    byte gpsData = gpsSerial.read();\n    Serial.write(gpsData);\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/Arduino_NEO_M8N_GPS_Raw_Data.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>This sketch assumes you are using <span class=\"rnthl rntcyellow\">Pin 6<\/span> and <span class=\"rnthl rntclgreen\">Pin 5<\/span> as RX and TX serial pins to establish serial communication with the GPS module. If you&#8217;re using other pins you should edit that on the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>static const int RXPin = 6, TXPin = 5;<\/code><\/pre>\n\n\n\n<p>Also, if your module uses a different default baud rate than 9600 bps, you should modify the code on the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>static const uint32_t GPSBaud = 9600;<\/code><\/pre>\n\n\n\n<p>Then, we create an instance of the <span class=\"rnthl rntliteral\">SoftwareSerial<\/span> on the pins defined earlier called <span class=\"rnthl rntliteral\">gpsSerial<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ The serial connection to the GPS device\nSoftwareSerial gpsSerial(RXPin, TXPin);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, we initiate the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(9600);<\/code><\/pre>\n\n\n\n<p>Then, we initialize a serial communication with the GPS module.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>gpsSerial.begin(GPSBaud);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, the code listens to the GPS serial port, and when data is received from the module, it is printed in the serial monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void loop(){\n  while (gpsSerial.available() &gt; 0){\n    \/\/ get the byte data from the GPS\n    byte gpsData = gpsSerial.read();\n    Serial.write(gpsData);\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Code<\/h3>\n\n\n\n<p>Upload the code to your board. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"36\" height=\"39\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-ide-2-upload-button.png?resize=36%2C39&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino IDE 2 Upload Button\" class=\"wp-image-146269\"\/><\/figure><\/div>\n\n\n<p>Make sure the antenna is connected and that the module or antenna is placed outside or next to a window so that it can get data from the satellites.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/active-GPS-antenna-for-NEO-6M.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"active GPS antenna for NEO-6M\" class=\"wp-image-160850\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/active-GPS-antenna-for-NEO-6M.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/active-GPS-antenna-for-NEO-6M.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The module&#8217;s blue LED will start blinking when it finds a position fix.<\/p>\n\n\n\n<p>The Serial Monitor will display NMEA sentences with GPS data (make sure to select the Serial Monitor baud rate to 9600).<\/p>\n\n\n\n<p class=\"rntbox rntcred\"><strong>Important: <\/strong> If you&#8217;re running this sketch for the first time, it may take a few minutes until the module gets a position fix. You&#8217;ll start getting actual data when the blue LED starts blinking. If you&#8217;re inside a building, it is very unlikely that you can get GPS data. Go outside or place your antenna outside to maximize your chances of catching a satellite signal.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"757\" height=\"403\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Get-Raw-Data-Arduino-NEO-M8N-GPS-Module.png?resize=757%2C403&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Getting Raw GPS Data with Arduino and NEO-M8N\" class=\"wp-image-167098\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Get-Raw-Data-Arduino-NEO-M8N-GPS-Module.png?w=757&amp;quality=100&amp;strip=all&amp;ssl=1 757w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Get-Raw-Data-Arduino-NEO-M8N-GPS-Module.png?resize=300%2C160&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/figure><\/div>\n\n\n<p>You should get a bunch of information in the GPS standard language, NMEA. Each line you get in the serial monitor is an NMEA sentence.<\/p>\n\n\n\n<p>NMEA stands for National Marine Electronics Association, and in the world of GPS, it is a standard data format supported by GPS manufacturers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"NMEA-sentences\">NMEA Sentences<\/h3>\n\n\n\n<p>NMEA sentences start with the $ character, and each data field is separated by a comma.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>$GNRMC<\/strong>,115209.00,A,4114.5500,N,00861.4900,W,0.129,,160125,,,D*XX<br><strong>$GNVTG<\/strong>,,T,,M,0.129,N,0.239,K,D*XX<br><strong>$GNGGA<\/strong>,115209.00,4114.5500,N,00861.4900,W,2,10,0.93,130.6,M,50.1,M,,0000*XX<br><strong>$GNGSA<\/strong>,A,3,24,25,28,32,29,,,,,,,,1.65,0.93,1.37*XX<br><strong>$GNGSA<\/strong>,A,3,78,66,67,77,,86,26,083,20*XX<br><strong>$GLGSV<\/strong>,3,3,09,87,13,131,*XX<br><strong>$GNGLL<\/strong>,4114.5500,N,00861.4900,W,115209.00,A,D*XX<\/pre>\n\n\n\n<p>There are different types of NMEA sentences. The type of message is indicated by the characters before the first comma.<\/p>\n\n\n\n<p>The <strong>GN <\/strong>after the <strong>$<\/strong> indicates it is a GPS position.&nbsp;The <strong>$GNGGA<\/strong> is the basic GNSS NMEA message, that provides 3D location and accuracy data.<\/p>\n\n\n\n<p>In the following sentence:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>$GNGGA<\/strong>,110827.00,4114.32485,N,00831.79799,W,1,10,0.93,130.6,M,50.1,M,,*5F<\/pre>\n\n\n\n<p>Here\u2019s how the fields look for the M8N:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>$GNGGA: Global GNSS location data.<\/li>\n\n\n\n<li>110827.00: Time in UTC (11:08:27).<\/li>\n\n\n\n<li>4114.32485,N: Latitude.<\/li>\n\n\n\n<li>00831.79799,W: Longitude.<\/li>\n\n\n\n<li>1: Fix quality (1 = GPS fix, 2 = DGPS, etc.).<\/li>\n\n\n\n<li>10: Number of satellites tracked (higher for M8N compared to NEO-6M).<\/li>\n\n\n\n<li>0.93: Horizontal dilution of precision (lower is better).<\/li>\n\n\n\n<li>130.6,M: Altitude above mean sea level (in meters).<\/li>\n\n\n\n<li>50.1,M: Height of geoid above the WGS84 ellipsoid.<\/li>\n\n\n\n<li>*5F: Recalculated checksum for the NEO-M8N.<\/li>\n<\/ul>\n\n\n\n<p>The other NMEA sentences provide additional information:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>$GNRMC<\/strong> \u2013 Essential GNSS PVT (Position, Velocity, Time) data<\/li>\n\n\n\n<li><strong>$GNVTG<\/strong> \u2013 Velocity and track information<\/li>\n\n\n\n<li><strong>$GNGGA<\/strong> \u2013 GNSS Fix Information<\/li>\n\n\n\n<li><strong>$GNGSA <\/strong>\u2013 GNSS DOP and active satellites<\/li>\n\n\n\n<li><strong>$GLGSV<\/strong> \u2013 Detailed satellite information (GLONASS)<\/li>\n\n\n\n<li><strong>$GNGLL<\/strong> \u2013 Geographic Latitude and Longitude.<\/li>\n<\/ul>\n\n\n\n<p>For more information about NMEA sentences, I found <a href=\"https:\/\/campar.in.tum.de\/twiki\/pub\/Chair\/NaviGpsDemon\/nmea.html\" target=\"_blank\" rel=\"noopener\" title=\"\">this website with very detailed information<\/a>.<\/p>\n\n\n\n<p>You can use this <a href=\"https:\/\/swairlearn.bluecover.pt\/nmea_analyser\" target=\"_blank\" rel=\"noopener\" title=\"\">Online NME Analyser <\/a>and paste your sentences there to interpret the GPS data.<\/p>\n\n\n\n<p>However, the easiest way to get and interpret the GPS data you want is to parse your NMEA sentences directly in the code. For that, we can use the <a href=\"https:\/\/github.com\/mikalhart\/TinyGPSPlus\" target=\"_blank\" rel=\"noopener\" title=\"\">TinyGPSPlus <\/a>library that provides methods to extract data from the NMEA sentences easily.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"parsing-nmea-sentences\">Parsing NMEA Sentences with TinyGPSPlus Library<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-with-NEO-M8N-GPS-Module.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with NEO-M8N GPS Module Guide\" class=\"wp-image-167131\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-with-NEO-M8N-GPS-Module.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-with-NEO-M8N-GPS-Module.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The TinyGPSPlus library makes it simple to get GPS data in a format that is easy to understand.&nbsp;You can click&nbsp;<a href=\"http:\/\/arduiniana.org\/libraries\/tinygpsplus\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>&nbsp;for more information about the TinyGPSPlus Library.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the TinyGPSPlus Library<\/h3>\n\n\n\n<p>In the Arduino IDE, go to <strong>Sketch <\/strong>&gt; I<strong>nclude Library<\/strong> &gt; <strong>Manage Libraries<\/strong> or click on the Library Manager icon at the left sidebar.<\/p>\n\n\n\n<p>Search for <strong>TinyGPSPlus<\/strong> and install the library by Mikal Hart.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"497\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/install-tiny-gps-plus-library-arduino-ide.png?resize=750%2C497&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing TinyGPSPlus Library Arduino IDE\" class=\"wp-image-160832\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/install-tiny-gps-plus-library-arduino-ide.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/07\/install-tiny-gps-plus-library-arduino-ide.png?resize=300%2C199&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"get-gps-data\">Getting GPS Data Using the NEO-6M GPS Module and the TinyGPSPlus Library<\/h2>\n\n\n\n<p>The following code shows how to get GPS data using the <span class=\"rnthl rntliteral\">TinyGPSPlus<\/span> library. We&#8217;ll get date, time, speed, altitude, number of visible satellites, and HDOP (a measurement of how precise the signal is).<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/arduino-neo-m8n-gps-module\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.  \n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\n#include &lt;TinyGPS++.h&gt;\n#include &lt;SoftwareSerial.h&gt;\n\nstatic const int RXPin = 6, TXPin = 5;\nstatic const uint32_t GPSBaud = 9600;\n\n\/\/ The TinyGPS++ object\nTinyGPSPlus gps;\n\n\/\/ The serial connection to the GPS device\nSoftwareSerial gpsSerial(RXPin, TXPin);\n\nvoid setup() {\n  \/\/ Serial Monitor\n  Serial.begin(9600);\n  \n  \/\/ Start Serial for the GPS module\n  gpsSerial.begin(GPSBaud);\n  Serial.println(&quot;Software Serial started at 9600 baud rate&quot;);\n}\n\nvoid loop() {\n  \/\/ This sketch displays information every time a new sentence is correctly encoded.\n  unsigned long start = millis();\n\n  while (millis() - start &lt; 2000) {\n    while (gpsSerial.available() &gt; 0) {\n      gps.encode(gpsSerial.read());\n    }\n    if (gps.location.isUpdated()) {\n      Serial.print(&quot;LAT: &quot;);\n      Serial.println(gps.location.lat(), 6);\n      Serial.print(&quot;LONG: &quot;); \n      Serial.println(gps.location.lng(), 6);\n      Serial.print(&quot;SPEED (km\/h) = &quot;); \n      Serial.println(gps.speed.kmph()); \n      Serial.print(&quot;ALT (min)= &quot;); \n      Serial.println(gps.altitude.meters());\n      Serial.print(&quot;HDOP = &quot;); \n      Serial.println(gps.hdop.value() \/ 100.0); \n      Serial.print(&quot;Satellites = &quot;); \n      Serial.println(gps.satellites.value()); \n      Serial.print(&quot;Time in UTC: &quot;);\n      Serial.println(String(gps.date.year()) + &quot;\/&quot; + String(gps.date.month()) + &quot;\/&quot; + String(gps.date.day()) + &quot;,&quot; + String(gps.time.hour()) + &quot;:&quot; + String(gps.time.minute()) + &quot;:&quot; + String(gps.time.second()));\n      Serial.println(&quot;&quot;);\n    }\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/Arduino_NEO_M8N_GPS_TinyGPSPlus.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>You start by importing the <span class=\"rnthl rntliteral\">TinyGPSPlus<\/span> library.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;TinyGPS++.h&gt;\n#include &lt;SoftwareSerial.h&gt;<\/code><\/pre>\n\n\n\n<p>Then, you define the pins you want to use as RX and TX and the GPS baud rate.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>static const int RXPin = 6, TXPin = 5;\nstatic const uint32_t GPSBaud = 9600;<\/code><\/pre>\n\n\n\n<p>Then, you create a <span class=\"rnthl rntliteral\">TinyGPSPlus<\/span> object:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>TinyGPSPlus gps;<\/code><\/pre>\n\n\n\n<p>Create an instance of <span class=\"rnthl rntliteral\">SoftwareSerial<\/span> on the pins defined earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SoftwareSerial gpsSerial(RXPin, TXPin);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor and the serial communication with the GPS module.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void setup() {\n  \/\/ Serial Monitor\n  Serial.begin(9600);\n  \n  \/\/ Start Serial for the GPS module\n  gpsSerial.begin(GPSBaud);\n  Serial.println(\"Software Serial started at 9600 baud rate\");\n}<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span> is where you request the information. Parse the data from the GPS module into the <span class=\"rnthl rntliteral\">TinyGPSPlus<\/span> object using the <span class=\"rnthl rntliteral\">encode()<\/span> method as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>while (gpsSerial.available() &gt; 0) {\n  gps.encode(gpsSerial.read());\n}<\/code><\/pre>\n\n\n\n<p>Then, you can query the <span class=\"rnthl rntliteral\">gps<\/span> object to see if any data fields have been updated:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (gps.location.isUpdated()) {<\/code><\/pre>\n\n\n\n<p>If there is new data, we can get it as follows:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Latitude<\/td><td><span class=\"rnthl rntliteral\">gps.location.lat()<\/span><\/td><\/tr><tr><td>Longitude<\/td><td><span class=\"rnthl rntliteral\">gps.location.lng()<\/span><\/td><\/tr><tr><td>Speed (km\/h)<\/td><td><span class=\"rnthl rntliteral\">gps.speed.kmph()<\/span><\/td><\/tr><tr><td>Altitude (meters)<\/td><td><span class=\"rnthl rntliteral\">gps.altitude.meters()<\/span><\/td><\/tr><tr><td>HDOP<\/td><td><span class=\"rnthl rntliteral\">gps.hdop.value()<\/span><\/td><\/tr><tr><td>The number of visible satellites<\/td><td><span class=\"rnthl rntliteral\">gps.satellites.value()<\/span><\/td><\/tr><tr><td>Year<\/td><td><span class=\"rnthl rntliteral\">gps.date.year()<\/span><\/td><\/tr><tr><td>Month<\/td><td><span class=\"rnthl rntliteral\">gps.date.month()<\/span><\/td><\/tr><tr><td>Day<\/td><td><span class=\"rnthl rntliteral\">gps.date.day()<\/span><\/td><\/tr><tr><td>Hour<\/td><td><span class=\"rnthl rntliteral\">gps.time.hour()<\/span><\/td><\/tr><tr><td>Minutes<\/td><td><span class=\"rnthl rntliteral\">gps.time.minute()<\/span><\/td><\/tr><tr><td>Seconds<\/td><td><span class=\"rnthl rntliteral\">gps.time.second()<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In the code, we get the data and print all the information in the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"LAT: \");\nSerial.println(gps.location.lat(), 6);\nSerial.print(\"LONG: \"); \nSerial.println(gps.location.lng(), 6);\nSerial.print(\"SPEED (km\/h) = \"); \nSerial.println(gps.speed.kmph()); \nSerial.print(\"ALT (min)= \"); \nSerial.println(gps.altitude.meters());\nSerial.print(\"HDOP = \"); \nSerial.println(gps.hdop.value() \/ 100.0); \nSerial.print(\"Satellites = \"); \nSerial.println(gps.satellites.value()); \nSerial.print(\"Time in UTC: \");\nSerial.println(String(gps.date.year()) + \"\/\" + String(gps.date.month()) + \"\/\" + String(gps.date.day()) + \",\" + String(gps.time.hour()) + \":\" + String(gps.time.minute()) + \":\" + String(gps.time.second()));\nSerial.println(\"\");<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Code<\/h3>\n\n\n\n<p>Upload the code to your Arduino board. Open the Serial Monitor at a baud rate of 9600. Make sure your GPS module is placed outside or next to a window to get data from satellites.<\/p>\n\n\n\n<p class=\"rntbox rntrced\">Note: you may need to wait a few seconds or minutes until the module can get a position fix.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"376\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-gps-data-tinygpsplus-NEO-M8N.png?resize=666%2C376&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with NEO-M8N Get Parsed Data with TinyGPSPlus\" class=\"wp-image-167100\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-gps-data-tinygpsplus-NEO-M8N.png?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/arduino-gps-data-tinygpsplus-NEO-M8N.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n<p>You&#8217;ll get data on the Serial Monitor about your current location, speed, altitude, number of visible satellites HDOP, and time.<\/p>\n\n\n\n<p>HDOP stands for Horizontal Dilution of Precision. This is a measurement of position-fixing accuracy. The higher the HDOP value is, the less accurate the position fix will be. Ideally, you should get a value lower than 2. A lower value means a better accuracy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this guide, you learned how to use the NEO-M8N GPS module with the Arduino. It is quite similar to the <a href=\"https:\/\/randomnerdtutorials.com\/guide-to-neo-6m-gps-module-with-arduino\/\" title=\"\">NEO-6M<\/a> but supports multiple satellite systems, not only GPS. We covered how to get information about location, and time.<\/p>\n\n\n\n<p>We have more guides for Arduino sensors and modules that you may find useful:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-ultrasonic-sensor-hc-sr04\/\">Complete Guide for Ultrasonic Sensor HC-SR04 with Arduino<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-oled-display-with-arduino\/\">Guide for I2C OLED Display with Arduino<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-dht11dht22-humidity-and-temperature-sensor-with-arduino\/\">Complete Guide for DHT11\/DHT22 Humidity and Temperature Sensor With Arduino<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-to-neo-6m-gps-module-with-arduino\/\">Guide to NEO-6M GPS Module with Arduino<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-free-guides-sensors-modules\/\"><strong>Arduino: 39 Free Guides for Sensors and Modules<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the Arduino with our guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-arduino\/\" title=\"\"><strong>All our Arduino Projects and Guides<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\" title=\"\">Arduino Step-by-step Projects Build 25 Projects<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to interface the Arduino board with NEO-M8N GPS module. You&#8217;ll learn how to connect the module to the board and how to program it &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino with NEO-M8N GPS Module: Get Latitude, Longitude, Altitude, Date and Time\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-neo-m8n-gps-module\/#more-167096\" aria-label=\"Read more about Arduino with NEO-M8N GPS Module: Get Latitude, Longitude, Altitude, Date and Time\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":167107,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,267,2,302,245,264],"tags":[],"class_list":["post-167096","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-0-guide","category-arduino-ide","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/01\/Arduino-M8N-GPS-Module.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/167096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=167096"}],"version-history":[{"count":9,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/167096\/revisions"}],"predecessor-version":[{"id":167865,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/167096\/revisions\/167865"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/167107"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=167096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=167096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=167096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}