Want to be a spy? Arduino Car Tracker!

Isn’t it hard to finish watching a spy movie and not want to do something…spy-like?  You know, like having 40 video cameras in your house, dancing the tango with some ambassador, or jumping off a helicopter onto a wild cheetah?

Well, what about secretly logging the GPS coordinates of a car on an SD card?

Here is the basic concept – you build a tiny Arduino GPS data logger and put it in a magnetic key case. Then, attach the key case to the vehicle you want to track. When the car returns, you pull off the GPS tracker, upload the secret data to your computer, then map the data using the free Google Earth software.

This turns out to be really easy to do.  We can use existing code that was originally featured in MAKE magazine for building a cat tracker.  Track cats or be slick – your choice!

In this video, we will walk step by step through building this GPS data logger.

Your Guide to Creating a Tiny Arduino GPS Data Logger

I wanted to keep my tracker discreet, so it needed to be small.  For this project, I chose to use the TinyDuino platform.  For all intents and purposes, it operates basically the same as an Arduino UNO, it’s just a whole lot smaller.

You Will Need:

This sounds like a lot of stuff – but really it’s not!  Essentially, it’s a processor board and two shields with a battery and a case.

Tools You Need:

You will also need to solder for this project, so you will need:

  • Soldering Iron
  • Solder

Arduino GPS Tracker Code:

/*
   This Arduino sketch will log GPS NMEA data to a SD card every second
*/

#include 
#include 


// The Arduino pins used by the GPS module
static const int GPS_ONOFFPin = A3;
static const int GPS_SYSONPin = A2;
static const int GPS_RXPin = A1;
static const int GPS_TXPin = A0;
static const int GPSBaud = 9600;
static const int chipSelect = 10;

// The GPS connection is attached with a software serial port
SoftwareSerial Gps_serial(GPS_RXPin, GPS_TXPin);


void setup()
{    
  // Init the GPS Module to wake mode
  pinMode(GPS_SYSONPin, INPUT);
  pinMode(GPS_ONOFFPin, OUTPUT);
  digitalWrite( GPS_ONOFFPin, LOW );   
  delay(5); 
  if( digitalRead( GPS_SYSONPin ) == LOW )
  {
     // Need to wake the module
    digitalWrite( GPS_ONOFFPin, HIGH ); 
    delay(5); 
    digitalWrite( GPS_ONOFFPin, LOW );      
  } 
     
  
  // Open the debug serial port at 9600
  Serial.begin(9600);
 
  // Open the GPS serial port  
  Gps_serial.begin(GPSBaud);  
   
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");   
}


int inByte = 0;         // incoming serial byte
byte pbyGpsBuffer[100];
int byBufferIndex = 0;

void loop()
{
  byte byDataByte;
  
  if (Gps_serial.available())
  {
     byDataByte = Gps_serial.read();
    
     Serial.write(byDataByte);
     pbyGpsBuffer[ byBufferIndex++ ] = byDataByte;
     
     if( byBufferIndex >= 100 )
     {
       byBufferIndex = 0;       
       File dataFile = SD.open("gps.txt", FILE_WRITE);
    
       // if the file is available, write to it:
       if (dataFile) {
        dataFile.write(pbyGpsBuffer, 100);
        dataFile.close();
      }  
      // if the file isn't open, pop up an error:
      else {
        Serial.println("error opening gps.txt");
      }        
     }      
  }
}

Step One: Solder the External Power Connection

The first thing, we will need to do is solder up a power connection on the TinyDuino.

The TinyDuino can run on a coin cell battery, but since we are using the GPS shield, the GPS module requires more power than the coin cell battery can provide.

Power.solder_op

Take a female JST connector and solder on the positive (red) wire to the positive terminal of the TinyDuino Processor.  Then, take the negative (black) wire, and solder that onto the ground (labeled GND).

They have two versions of the TinyDuino – one with a coin cell battery holder and one without.  The one I used had the coin cell holder, but I think it would be easier to solder, if it wasn’t there.  You will want to solder the wires to the back side of the board.

TinyDuino.poer arrows

Step Two: Build the Stack

Once we have the external power connection setup, let’s go ahead and build the “Stack” we will use for this project.

Connect the TinySheild GPS on top of the TinyDuino processor board. On top of that, connect the TinySheild SD Card writer/reader.  Insert your microUSB card into the SD card shield. Finally, attach the TinyShield USB adapter.

That’s it for the stack for now. In a moment, we will remove the the USB shield, but first let’s keep it attached as we load the Arduino code.

Step 3: Load the Code

To load the code on the TinyDuino, attach a micro USB cable from the TinyShield USB to your computer.

Open up the Arduino IDE.

Under Tools > Board, make sure to select Arduino Pro or Pro Mini (3.3V 8 MHz) w/ ATmege 328

Under Tools > Serial Port  and select the correct Serial Port.  For a PC it is likely COMM 4 or 3.  On a Mac, it will start with tty.

Now go to File > Open and navigate to where you loaded the sketch.  Depending on where you saved the file, you will probably get a message that the sketch was put into a subfolder – this is normal.

Click upload – you will see some LEDs flicker on your tinyDuino. It should take about 20-40 seconds for everything to load. You will see “done uploading” in the Arduino IDE.

Check to see that the Green indicator light on the TinyDuino is blinking about once every second, this tells us that the TinyDuino is writing to the SD card (not necessarily that you are getting a GPS signal).

Go ahead and detach the TinyShield USB connector. Attach the lithium battery to the processor board.

Now, place everything in your case.

My Tiny Arduino GPS care tracker

Step 4: Test Placement and View the Data

I highly recommend doing a test run, before you start doing your real-deal tracking.  Since the tinyGPS shield is so small, it’s antenna can be a bit weak – the bottom line is, it needs to be outside to collect data – and preferably pointing toward the sky.

Once you have collected some outdoor data, let’s take a look at the data. This is the fun part!

Take out the microSD card and insert into your microSD card reader.  When the SD card opens on your computer, you will see a file named gps.txt.

In order for us to read this file using Google Earth, you will need to change it to a different file extension, called nmea – this stands for National Marine Electronics Association – it is the standard file type for organizing GPS data.

To do this on a Mac, right click and select “get info”. Then go to file name, and change it from .txt to .nmea.  You will get a warning about changing the extension, so choose to change the extension.

On a PC, you will simply right click and rename the file extension to .nmea – that’s it!

Before we get started looking at the data, we are going to need a program to display the information.  I used Google Earth – it’s free and easy to use. You will need to download it to your computer’s hard drive.

Once it has installed, go ahead and open it up.  Now go to Tools > GPS.

Using Google Earth to upload my Tiny Arduino GPS data via the Tools > GPS menu

From the popup window, select “Import from file” and click all of the options for import and output, then click “Import”.

Using the Google Earth GPS Import pop-up menu to upload data from my tiny Arduino GPS logger

Now browse to the file gps.nmea on your sdCard and select “open”

All the routes will be imported and whalla! You can check out the individual points and the track.  That’s pretty much it – not as hard being a spy as you might think!

I would love to hear how it works for you – let me know in the comments.

installing Arduino libraries

Installing Arduino Libraries | Beginners Guide

IoT sewage project

Pumping poo! An IoT sewage project

ESP32 webOTA updates

How to update ESP32 firmware using web OTA [Guide + Code]

error message Brackets Thumbnail V1

expected declaration before ‘}’ token [SOLVED]

Compilation SOLVED | 1

Compilation error: expected ‘;’ before [SOLVED]

Learn how to structure your code

12 Comments

  1. Alan Cláudio Melo on February 23, 2015 at 5:29 pm

    Fantatisc project. How do I get purchase the complete kit of the project? I would like to contact you.

    • MICHAEL JAMES on February 24, 2015 at 5:12 pm

      Glad you liked it – thanks for posting Alan! I don’t sell any complete kits, but it is a cinch to make if you buy the parts individually (which I have linked in the post above).

      You can reach me at michael at programmingelectronics.com

      Have a great one.

  2. James Carter on March 11, 2015 at 10:05 am

    A brilliant project, particularly for someone who just jumped into the world of Arduino about six hours ago. I have a few issues getting libraries and stuff to work on OS X which made it very difficult to work out why the tracker code wouldn’t upload properly. However Codebender came to the rescue and I got it to work. But I do have a couple of questions. When I attempt to upload the NMEA data from the SD card into Google Earth an alert box comes up saying “Loaded No Data”. I thought that was odd so I jumped into the NMEA strings and extracted a line of code, converted it to decimal Longitude and Latitude and put that into Google Earth. Sure enough the GPS was unbelievably accurate – we’re talking to within a metre. So it proved that valid NMEA code was logged on the SD card. Any idea why Google Earth couldn’t open/load the data? Secondly, after unplugging the USB cord to my Mac and running off the LiPo battery, if I turn off my Tiny Arduino and turn it back on, the GPS Tracker program doesn’t boot back up. The LED doesn’t flash and I have to reload the code again to get it to work. Any idea on what might be happening? Thanks again for a fantastic project.

    • MICHAEL JAMES on March 11, 2015 at 8:56 pm

      Hi James, glad you liked the project and nice work on your part for doing this and being so new to Arduino! Unfortunately I am not sure about either of your questions (I am not much help here sorry!). Maybe Google Earth has a setting looking for specific Lat/Long format – not sure. I did see that you posted on the Tiny Circuits forum, but as I was searching around, I found this thread… http://forum.tiny-circuits.com/index.php?topic=1382.0 – maybe it could help?(maybe not related too 🙁 ?)

      In any case – best of luck!

  3. My first Arduino Cat Tracker | Excis3.be on August 15, 2015 at 8:13 am

    […] Here some code that logs the GPS data to the SD card. Modify as you like, or if you have some tips to improve it just let me know. Original from another site. […]

  4. Alex on December 1, 2015 at 1:04 am

    Hi Thanks for the tutorial. Happened to read now only. Quick question. I would like to add the functionality of live tracking instead of storing in micro SD. is TinyDuino have GSM shield?

  5. Alex on December 2, 2015 at 1:23 am

    Hi Thanks for the tutorial. Happened to read now only. Quick question. I would like to add the functionality of live tracking instead of storing in micro SD. is TinyDuino have GSM shield?

  6. kecz on June 14, 2016 at 7:58 am

    hi, how hard is it to make the tracker with the built-in battery holder?

  7. Nimal on July 9, 2016 at 12:01 am

    can we do real Time tracking via remotely?if so what’s the modification we should do for this

  8. bunkaten on August 21, 2016 at 4:44 am

    A very well documented tutorial
    But the cost of the bill of materials you list, makes this non realistic.
    In this case I use my GPS/SatNav (same price like this assy budget), downloading the “.gpx” files. Then with Google Earth or Maps, you can get also all your routes, as you explain, via USB without remove any SD card.
    Anyway yours it’s a good job indeed. Congratulations for it.

  9. 張皓翔 on January 18, 2017 at 9:20 am

    HI, when I import the nmea file to the google earth, it can’t accurately show the position.
    I am in Taiwan but every time I try it show me I am in Africa.
    Is there anyone can help me:(

  10. Peter on December 30, 2020 at 1:52 pm

    Hi, it’s a while ago since you’ve published the article. Do you think this projects works also with the AEAK NEO-6M board on https://de.aliexpress.com/item/32967428465.html ?

Leave a Comment