How To Connect GPS Module To Arduino
INTRODUCTION
There are like a ton of projects that can be made using GPS module with Arduino, to name some are GPS logger, Car Tracker, path tracker and many more. In this tutorial we will learn to interface Arduino with U-Blox Neo6M V2 GPS module( if you don’t have this particular module then no need to worry you can still follow this tutorial with any GPS module that have Serial Communication.)
Components Required:
-
Arduino Uno
-
GPS Module Neo6M V2 (or other)
-
Jumper Wires
If you look at your GPS module it have generally 4 pins: VCC, GND,TX and RX. These modules usually communicate over simple serial connection like RS232 that is the exact protocol which Arduino uses for serial communication, so we will simply use “Serial.being” to read the module data.The module is very simple and it just splits continuously NMEA (National Marine Electronics Association) data strings to the TX pin.
Here, we will first go through reading data from GPS module by just using serial communication and later on look at the dedicated libraries like TinyGPS++ and see how it breaks down the raw GPS data to the one needed for our projects like latitude, longitude, time, number of satellites and others.
Connection:
Code : Getting RAW data from GPS
Ublox NEO-6M GPS Module has build in EEPROM and comes with ceramic antenna. It use Rs232 TTL interface and operates on 3-5V supply with default Baudrate of 9600bps. So, while coding we need to take care of the baudrate of serial communication between the two.
#include <SoftwareSerial.h> static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 9600; //Baudrate of your GPS here // The serial connection to the GPS device SoftwareSerial ss(RXPin, TXPin); void setup() { Serial.begin(115200); // Beginning the serial monitor at Baudrate 115200 and make sure you select same in serial monitor ss.begin(GPSBaud); } void loop() { // Output raw GPS data to the serial monitor while (ss.available() > 0){ Serial.write(ss.read()); } }
After uploading the above code you will get something similar to this on your serial monitor:
Here, you can see that the data is not in the format we want that is it is a kind of mess. So, we will now use a dedicated library for this and the most popular and precise is TinyGPS++ (Get this library)
Using TinyGPS++ library :
Step 1: First we have to include the TinyGPS++ library in our Arduino IDE. Go to the GitHub link shared above and download it. It’s a zip file, now extract it and copy it and paste to directory of Arduino IDE under the libraries folder.
Step2: Open Arduino IDE and under File navigate to Examples—TinyGPSPlus and upload any of those sample code. Here we are uploading <DeviceExample> code. Once, the code is uploaded open the serial monitor and you will find the data are now more readable like Location: Latitude, Longitude along with Date/Time.
Some things to take care:
- It takes for about half a minute or one to read the data by the GPS module initially when you run it, so do not panic for this it’s very usual.
- It happens in some case that it is unable to detect the data that might be the issue with antenna, so unplug the antenna( if it is detachable) and attach it again.
- If, code says “Check Connection”, then you should definitely check it twice, before giving up. Also, sometimes interchanging the TX and RX pins is preferable and surprisingly works.
-
GPS Car tracker
-
GPS Data logger
-
IOT GPS tracker
Buy All The Parts Mentioned In This Tutorial From Tomson Electronics And Get More Exciting Offers
Hi i interfaced gps with node mcu to get gps values on moving vehicle but i did not get continuous values i write the code to push the data every 30 seconds but it sends the gps values only in stabled condition. i changed 3 modules but it was repeating same problem if any suggestions to over come this problem?? http://bigbelectronics.in/product.php?product=neo-6m-gps-module-eprom
How to interface a GPS module (NEO-6M) with Arduino Mega. The data for longitude and latitude is displayed on the serial monitor.
So good website