Arduino Neo6M GPS Tracking
Author : Dinesh Kumar Wickramasinghe
Introduction
Hello friends. In this project let’s see how to add GPS capabilities to your Arduino. I will use the small and low cost Neo 6M GPS module. You can buy this module from eBay or any other online electronic stores for around 5 USD.
Here is a picture of the module I purchased.
Problem with the Antenna
It cost me 4.5 USD. But I had an issue with the antenna. I could not get any GPS signal. Then I searched more and I found that the tiny antenna that comes with this module is not capable of detecting GPS signals accurately. I tried even placing my setup in an outdoor location and there was no luck.
Then I purchased a GPS antenna separately to get good GPS signals. Below image shows the GPS antenna that I purchased. With this antenna, I could get GPS signals even in indoor locations.
A Good Module
So I recommend you to buy a GPS module with a big antenna (like in the below picture). It's obvious that a big antenna can get good GPS signals. (Please note that there are some other modules like Neo7M and Neo8M with more features)
Connecting GPS Module to the Arduino
Connecting this small GPS module to Arduino is very easy. You have to use only 4 pins. Those are VCC, GND, Rx, Tx. Please use the below table to understand the connectivity.
GPS Module
|
Arduino UNO
|
VCC
|
5V
|
Rx
|
Tx (As you define in software serial)
|
Tx
|
Rx (As you define in software serial)
|
Ground
|
Ground
|
In the below image you can see my setup. I just connected the things together and am ready to connect the Arduino to my PC.
Arduino Code
All good. Now let’s move to the software part. I will use a small Arduino library in this project. (Kudos to the developer) You can download this library here. Just unzip this zip file to the Arduino library folder.
Download Library
This library is called TinyGps++ and this library helps us Parsing NMEA Sentences coming from the GPS module and get location values easily. We can read the GPS module data even without this library, but then it is very complicated to read correct location data.
Hope you can install this library to your Arduino IDE. Here is the arduino code.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4;
static const int TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial softSerial(RXPin, TXPin);
void setup(){
Serial.begin(9600);
softSerial.begin(GPSBaud);
}
void loop(){
while (softSerial.available() > 0){
gps.encode(softSerial.read());
if (gps.location.isUpdated()){
Serial.print("Latitude : ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude : ");
Serial.println(gps.location.lng(), 6);
}
}
}
I’ve used RX pin 4 and TX pin 3
Once you connected the GPS module to your Arduino, please double check that your connections are correct. Then upload the above code.
Now open the serial monitor of the Arduino IDE and you will get an output like in the below image. If you are not getting any values, try keeping your setup outside location to get good GPS signals.
You can pass these value to a map service and see the location in a map. I tried using www.latlong.net and the location was accurate.
You can enhance this project by adding more features. For an example you can connect a MicroSD module and log GPS data in a file while you are travelling. Once the journey is done, you can read this file and build a map of your journey using Google map or similar service.
Also there are more examples that come with the TinyGps library.
I tried the full example project and the output was like in the below screenshots.
And one remark in the library examples. You can see the below line in the beginning of the sketches (set the Baud)
static const uint32_t GPSBaud = 4800;
I had to change the value 4800 to 9600 to get the correct output. (Because my module supported 9600 rate)
Conclusion
Hope you enjoyed this tutorial. If you have any questions or comments, please add them in the comments section. Have a nice day.