Click here to Skip to main content
15,946,316 members
Articles / Internet of Things / Arduino

GPS Walker : Get GPS Data With Your Arduino

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
6 Aug 2018CPOL8 min read 15.3K   501   7  
Build this circuit and learn how easy it is to grab GPS data and store it on an SD Card. Walk around your neighborhood and then upload data to a map.

Introduction : Satellite Story

Back in 1977 I got my first telescope and began watching the night skies.  I trained my telescope on the moon and would stare at the moon for long periods of time trying to understand what I saw.  Next, I would try to point the telescope at various stars that I saw, but the telescope was too weak and I didn't know what I was looking at. I finally obtained a star map and tried hard to discern what I was looking at.  Where was Saturn?  If I could just get a look at those magnificent rings around Saturn I would be amazed.  

One very clear night while l lay on the ground staring at the sky I saw something moving.  It was ever so small, just a pinprick of light, smaller than many of the stars I could see.  It was racing across the sky at an amazing speed.  I wanted to leave to tell someone and show them, but I knew it would be gone so I just stared and wondered.

There Was No Internet (Available to Civilians) In 1977

Back in '77 you couldn't look something like that up.  As a 10 year old I had no idea what I had seen but it was fantastic.  Luckily, I mentioned it to one of my mom's friends who was an engineer and he told me, "You've seen a satellite which is orbiting the Earth."  

The 24 GPS satellites* that make up the system weren't placed into service until 1989** so I saw some other satellite.  I must've been pretty lucky too, since the number of satellites was much smaller back then.

*I thought GPS satellites were geostationary but they are not, they have 12-hour orbits.  

**Edit - found this which says Navstar^ first GPS satellite was put in place in 1978.

GPS Component Talks to Satellites

If you would've told me back then that some day I would be able to build my own device that ran off batteries and fit in my hand which would communicate with a satellite I would've thought you were nuts.  

This is why this little experiment is so exciting to me.  You can build this inexpensive little circuit powered off of 4 AA batteries, connect to the GPS satellites and store the data on an SD card.  

First Look At the Circuit

I got everything (Atmega328p-pu, GPS Component, SD Card reader/writer) onto a small breadboard.  It is a bit ugly because of my long wires but I built this circuit in just a few hours yesterday (Aug. 5, 2018).

Image 1

 

You can see that I've put the bare Atmega328p-pu chip onto the breadboard.   After programming the chip, using my Arduino Uno board, I took the chip off so I could create a smaller footprint.  I needed to do this because I wanted to walk around with the device and carrying the Arduino Uno board around too, just doesn't make sense.

Won't Run Without the 16Mhz Crystal

As I've detailed in another article (Arduino Uno: Using Your ATMega328p-u As Stand-alone[^]) this circuit won't work properly with the Atmega328 running stand-alone without adding the 16Mhz crystal which you can see in the middle of the board, below the Atmega chip.

Since the wires look a bit jumbled up in the picture, I'll provide you with a nice schematic so you can easily build the circuit.

First, I'll list everything you need.

Project Parts List

  • 1 - 16Mhz Crystal Oscillator - 10 for $5.04 USD (https://amzn.to/2MmYPru ) You only need 1 for this project but these are very inexpensive and you'll probably use more of them for projects later.
  • 2 - 22pF ceramic capacitors (non-polarized) - for use with the Crystal  You can get 50 of them for $5.69 USD (https://amzn.to/2AM3KRz)
  • 1 - GPS Module - I was amazed when I found this for less than $20 -- only $15.66 USD (https://amzn.to/2KvA2zP) Very well made and works better (more precise) than an iPhone set on high granularity.  Amazing!
  • 1 - SD Card Reader/Writer You can get a pack of 5 of these for $8.98 USD (https://amzn.to/2vmi51C)
  • 1 - Arduino Uno You'll use your Uno to program your Atmega328 chip.  This knock-off board is inexpensive, works great and comes with the Atmeg328 installed and USB cable all less than $12 USD (https://amzn.to/2KySU0J). This is the one I use.
  • 1 - Breadboard (https://amzn.to/2vtlCLZ) pack of three for $8.20 USD.
  • AA Battery holders - I use these ones that take two batteries and I connect them serially.  12 of them for $7.99 USD (https://amzn.to/2vkjPJ4)

Now, take a look at the schematic.  You can build the circuit in just less than an hour.

Circuit Details

Image 2

 

Pin Labels

I've labeled the pins on the Atmega328 by combining a few different methods.  The first number (reading left to right) on each pin is the physical pin number on the Atmega chip.  Physical pin numbers start on the upper left side of the chip and increment down to the bottom and then coninue up the right side of the chip.   I've skipped some pins to save room.  

I've also labeled the pins with their Digital pin numbers (used by the Arduino).  And I've also added their Pin bank numbers (PBx, PDx, etc) that they are referred to when examining the Atmega data sheet.  I've done it this way to insure you can tell which pin you are connecting to.

Here's a very good pin mapping diagram that will help you sort it out (provided by the official Arduino site here^).

Image 3

Once you build that circuit you can upload the code, insert an SD micro card in the reader/writer and run it.

Arduino Sketch Overview

I've added the Arduino sketch to this article so you can download it.  

The first thing you're probably going to notice if you try building the sketch is that it fails because you (probably) don't have the TinGPS library that it depends on. 

What Is The TinyGPS Library?

TinyGPS is a helper library that formats the GPS data from the raw data that comes from the GPS component into something that is a bit more readable.

In our case we use it to just get the Longitude and Latitude values from the data, but there is more data that can be obtained.

You can get the library at GitHub here^.

You only need the two source files (TinyGPS.cpp, TinyGPS.h).  They need to be in a folder named TinyGPS which you will place under your Arduino IDE libaries folder.  

Since that code is open source, I've placed them in the TinyGPS folder, zipped them up and included them in this article as a download.  That means you can just download the zip, unzip it and drop the TinyGPS folder into your Arduino IDE libraries folder (probably installed under \Program Files x86\.

What The Code Does

This code is based upon a sketch that I found where the author was testing the GPS component^.  That's an informative article and it is very interesting because he found that the GPS component is far more precise than the iPhone's GPS.  However, that author only writes the data to a Bluetooth module and I wanted to write the data to an SD card for later analysis so I have altered the code quite a bit.

The basics of what it does can be summarized in the following few lines of code:

C++
if (latitude<=90 and latitude>=-90 and longitude>-180 and longitude<180){
    dtostrf(latitude,1,4,latitude_str);
    strcat(out_data,latitude_str);
    strcat(out_data,",");
    writeToSD(out_data);

If the value read from the GPS unit is in a valid range then grab the latitude and write it to the SD card.

Then next chunk of code does the same thing longitude values.  

It writes the data every second so if you are moving it will pick up changing values.  It writes the values as float values (to four decimal places) and comma delimits them. The data is saved in a file named gps.txt and looks something like the following:

  • 39.7624,-84.0624
  • 39.7624,-84.0600

That data format is the same that Google Maps will accept and you can copy those coordinates and paste them in and they will show you the location.  Later you can upload multiple points from your SD card capture and create paths that show where the GPS Walker went.

Now, you can power it up with 4 AA batteries and go for a walk.  Of course you can throw it in your car or put in on your bike too.

Here it is running off battery power.

Image 4

 

The first time you run it you should be outside to get a good signal from the GPS Satellite.  This module seemed to work very well though and it would even pick up the satellite inside my house.

The green LED will let you know when it has connected with the satellite.

Try it out.  I think you'll find it a lot of fun and amazing that you can build this thing that commuicates with a satellite that is 20,000 kilometers away.  

When you obtain your data, you can upload it into Google Maps and use their API to create routes from the data.  

History

2018-08-06: First publication

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) RADDev Publishing
United States United States
"Everything should be made as simple as possible, but not simpler."

Comments and Discussions

 
-- There are no messages in this forum --