Maker Portal

View Original

Arduino GPS Tracker

“As an Amazon Associates Program member, clicking on links may result in Maker Portal receiving a small commission that helps support future projects.”

See this content in the original post

The NEO-6 is a miniature GPS module designed by u-blox to receive updates from up to 22 satellite on 50 different channels that use trilateration to approximate fixed position of a receiver device every second (or less, for some modules). The particular module used in this tutorial, the NEO-6M, is capable of updating its position every second and communicates with an Arduino board using UART serial communication. The NEO-6M uses the National Marine Electronics Association (NMEA) protocol which provides temporal and geolocation information such as Greenwich Mean Time (GMT), latitude, longitude, altitude, and approximate course speed. The NEO-6M and Arduino board will also be paired with an SD module to create a portable logger that acts as a retrievable GPS tracker.


See this content in the original post

The GPS tracker will be fully contained and isolated from any external power or communication. In order to achieve this, we will need to use an SD card and LiPo battery. And after measuring the approximate current consumption of the whole Arduino GPS tracker at roughly 120mA-180mA, I decided to use an 850mAh battery, which yields 5-6 hours of tracking and saving to the SD card. The full parts list is given below with some affiliate and store links:

  1. NEO-6M GPS Module - $15.00 [Our Store]

  2. 3.3V SD Module - $8.00 [Our Store]

  3. 16GB Micro SD Card + USB Reader - $10.00 [Our Store]

  4. 850 mAh LiPo Battery - $18.99 (4 pcs + charger) [Amazon]

  5. Arduino Uno - $11.00 [Our Store]

  6. 3.7V to 5.0V Buck Converter - $7.99 (2 pcs) [Amazon]

  7. Jumper Wires - $6.98 (120 pcs) [Amazon]

See this content in the original post

See this content in the original post

See this content in the original post

The NEO-6 GPS Datasheet can be found here, where the specific workings of the module can be found. In short, the NEO-6M can update its fixed position roughly every second and can use anywhere between 3-22 satellites. The particular module communicates with the Arduino over UART (pins 5/6 are used here). The SD module uses SPI communication, with the chip select on pin 4. Pins 4/5/6 are therefore specifically determined in the code.

The full code is given below, followed by a description of the basic usage and output:

See this content in the original post

The code follows the outline specified below:

  1. Plug in LiPo battery

  2. Arduino checks that both the NEO-6M and SD module are wired and started correctly

  3. If a valid GPS signal is received, create a .csv file based on the date in the format: “ddHHMMSS.csv” - where dd is day, HHMMSS are hour, minute, and second; respectively.

  4. The GPS data will be logged onto the .csv file in the following column format (with headers):
    Date [mm/dd/YYY HH:MM:SS], Longitude [degrees], Latitude [degrees], Altitude [meters], Heading [degrees], Speed [km/hour]

See this content in the original post

A Simple Cardboard Box Housing for the GPS Tracker


See this content in the original post

QGIS is a geographic information system (GIS) tool used by geographers, statisticians, and engineers interested in geographic-related visualization. QGIS is an open-source tool and fairly easy to use. Click the logo below to go directly to the QGIS download page. I recommend downloading the stable release. I will be using QGIS 2.8.9 (2016), but 3.x versions have been made and the newer downloads should work just the same.

The user should download a map base, in my case I’m using Bing’s road map. You can use Google or other basemaps. You can insert the basemap by:

  1. Click “Web”

  2. “Web -> OpenLayers Plugin -> Bing Maps -> Bing Road”

If there is no OpenLayers plugin, it will need to be downloaded by following the process outlined at https://support.dronesmadeeasy.com/hc/en-us/articles/115003641026-QGIS-Installing-Google-Maps-Plugin essentially it follows:

  1. Click “Plugins”

  2. Click “Manage and Install Plugins …”

  3. Type in “openlayers”

  4. Click on “OpenLayers Plugin”

  5. Install Plugin

  6. Follow the process above after install

For my particular case, I walked around New York City and mapped the route using various basemaps (Bing Maps, OpenStreetMap, Wikipedia Labeled Layer). Below is a sample mapping where I walked around the campus at the City College of New York, and the data points from the GPS sensor match nearly exactly with the route taken. When walking near some larger buildings, the GPS lags or jumps around, which is expected as it is likely that the satellites are having trouble communicating with the sensor through or around the taller masses.

Below is the GPS route atop the Bing aerial street map, which closely resembles a satellite image of the surface:

The OpenStreetMap of the same route is shown below:

Wikipedia also has a labeled layer, similar to the OpenStreetMap layer:

Here is another route atop the OpenStreetMap:


See this content in the original post

QGIS is a powerful tool for static visualization, but if we really want to dig into the GPS data, Python is a better fit for many reasons. I wanted to clean up the data, and I find it much easier to get rid of erroneous points in Python rather than QGIS. Time series analysis is also very difficult in GIS software, so I will do that in Python. Lastly, I will create some animations that I wouldn’t even know how to broach with the QGIS software.

Below are two mappings of the routes above with different basemaps, both plotted in Python with the Basemap toolkit:

The code to replicate the plots above is given below:

See this content in the original post

Using Heading and Speed:

Next, I’ll be using the heading and speed to create a quiver plot that can represent the speed and direction of travel on the map. The way we do this is by looking at the geometry of the heading outputted by the GPS. The NEO-6M outputs heading information which in short calculates the heading based on consecutive points. A typical compass uses true north as 0° and counts clockwise movements as positive changes in heading.

We can derive a relationship between the heading, speed, and latitude and longitude points on the surface of the earth. Invoking geometry:

Calculating each quiver point

See this content in the original post

Plotting the quiver points using Python, we get the following mapped result:

The plot above shows the rough direction of travel. To start, the upper-left portion of the GPS data is moving north, and the right-hand data is moving south. This is the trend that was followed during acquisition. The quivers can be helpful for determining direction and speed of travel, which we can see here is fairly accurate, though a bit noisy.

The other route is shown below, which started in the upper-right and followed a clockwise travel direction - which is mostly captured with the quiver plot, especially on the left-hand side of the route (where there’s less interference from buildings).

The full quiver code is also given below:

See this content in the original post

Mapping Over Time:

For the time series map, I’ll just be plotting point-by-point to see how and at which point each GPS point was set (at some interval, which I set depending on the size of the route). Below is an animation of the GPS route, which was created using Python and a .gif creator algorithm. The route roughly follows the trajectory laid out by the quiver plot.

The code to replicate this is also given below:

See this content in the original post

See this content in the original post

The goal of this tutorial was to develop a portable and self-contained GPS tracker. With Arduino, I paired the NEO-6M GPS module and SD card to act as the GPS logging system. Using the system, 1Hz update rates from the GPS system was achievable. I analyzed two routes in QGIS and Python, demonstrating the accuracy and ability to analyze the data produced by the Arduino GPS tracker. I also introduced some methods for visualizing in Python that were more involved, such as quiver plots and time-related plots. This tutorial was meant to demonstrate the capability of the NEO-6M GPS module and the power of Python for analysis of geographic data.

More in Python, Arduino, and GIS:

See this content in the original post