Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arduino for Secret Agents

You're reading from  Arduino for Secret Agents

Product type Book
Published in Nov 2015
Publisher
ISBN-13 9781783986088
Pages 170 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Marco Schwartz Marco Schwartz
Profile icon Marco Schwartz

Table of Contents (16) Chapters

Arduino for Secret Agents
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
A Simple Alarm System with Arduino Creating a Spy Microphone Building an EMF Bug Detector Access Control with a Fingerprint Sensor Opening a Lock with an SMS Building a Cloud Spy Camera Monitoring Secret Data from Anywhere Creating a GPS Tracker with Arduino Building an Arduino Spy Robot Index

Chapter 8. Creating a GPS Tracker with Arduino

We are now going to build a very common tool that any secret agent should have: a GPS tracker. We'll use the Arduino platform again to build our own DIY GPS tracker. We will actually build two applications using the same hardware:

  • The first one will be a location device that sends its position via SMS

  • The other project will be a GPS tracker that you can actually locate live on a map

Let's dive in!

Hardware and software requirements


First let's see what the required components are for this project. As usual, we are going to use an Arduino Uno board as the central part of the project.

For the GPRS and GPS parts, we are going to use the Adafruit FONA 808 module again, which we already used in Chapter 5, Opening a Lock with an SMS. We'll also need a GSM antenna for GSM/GPRS communications.

However, as here we want to use the onboard GPS, we'll also need an additional GPS antenna. I used a standard uFL passive GPS antenna from Adafruit:

Then, you will need a battery to power the FONA shield and the onboard GPS module, as the Arduino Uno board doesn't allow you to power the FONA shield (it can use up to 2A at a time!). For that, I used a 3.7V LiPo battery, along with a microUSB battery charger.

A very important part of the project is the SIM card, which you need to place inside the FONA shield. You will need a normal SIM card (not micro or nano), which is activated, not locked by a PIN, and...

Hardware configuration


It's now time to assemble the hardware of this project.

First, connect the power supply to the breadboard: connect the 5V pin from the Arduino board to the red power line on the breadboard, and the GND pin to the blue power line.

Then, place the FONA shield on the breadboard. Connect the VIO pin to the red power line, and the GND and Key pins to the blue power line.

After that, connect the RST pin to Arduino pin 4, TX to Arduino pin 3, and RX to Arduino pin 2. Also connect the 3.7V LiPo battery, the GPS antenna, and the GSM antenna to the FONA shield.

This is a close-up picture of the shield after the project was assembled:

And this is an overview of the whole project assembled:

Testing the location functions


Before we dive into the two exciting projects of this chapter, we'll first make a simple test using the FONA shield, and see whether it can actually locate our project on a map. The sketch will actually test whether the GPS location is working correctly.

If not, no worries: the sketch, and the other projects of this chapter, will automatically use GPRS location instead. It's less precise, but works quite well. This will be the case if you are testing this project inside, for example.

This is the complete code for this part:

// Libraries
#include "Adafruit_FONA.h"
#include <SoftwareSerial.h>

// Pins
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

// Buffer
char replybuffer[255];

// Instances
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

void setup() {
 
  // Init board
  while (!Serial);
  Serial.begin(115200);
  Serial.println(F("FONA location test...

Sending a GPS location by SMS


Now that we have the location part working correctly, we can start building our GPS tracking projects for secret agents. The first project will simply use the location and send it via SMS to the phone number of your choice.

As the sketch is quite similar to previous one, I'll only show which parts changed compared to the location test sketch. We first need to define the phone number where you want to send the tracking data to:

char * sendToNumber = "123456789";

After getting the location just as in the previous section, we can now build the message that we will send via SMS:

char messageToSend[140];
String message = "Current GPS location: " + latitude + "," + longitude;
message.toCharArray(messageToSend, message.length());

Using the FONA instance, it's very easy to actually send the SMS to the number we defined earlier:

if (!fona.sendSMS(sendToNumber, messageToSend)) {
  Serial.println(F("Failed to send SMS"));
} else {
  Serial.println(F("Sent location data!"));...

Building a GPS location tracker


It's now time to build the last project of this chapter: a real GPS location tracker. For this project, we'll get the location just as before, using the GPS if available, and the GPRS location otherwise.

However, here we are going to use the GPRS capabilities of the shield to send the latitude and longitude data to dweet.io, which is a service we have used before. Then, we'll plot this data in Google Maps, allowing you to follow your device in real time from anywhere in the world.

As the sketch is very similar to the ones in the previous sections, I'll only detail the most important parts of the sketch here.

You need to define a name for the thing that will contain the GPS location data:

String dweetThing = "mysecretgpstracker";

Then, after getting the current location, we prepare the data to be sent to dweet.io:

uint16_t statuscode;
int16_t length;
char url[80];
String request = "www.dweet.io/dweet/for/" + dweetThing + "?latitude=" + latitude + "&longitude...

Summary


In this chapter, we built a device that allows us to track the GPS location of any object it is attached to. We built two projects based on the same hardware: one that sends SMS messages to your phone with the location of the device, and another one where you can see the current location of the device on a map.

There are of course many ways to improve this project. You can, for example, add sensors to the project and monitor them as well from the Freeboard dashboard, just as we did in the previous project. One useful thing is also to make the project autonomous, and for this, you can simply power the Arduino board directly from the FONA shield, as it has a 5V output.

In the final chapter of the book, we are going to build another cool application for secret agents: a small mobile surveillance robot.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Arduino for Secret Agents
Published in: Nov 2015 Publisher: ISBN-13: 9781783986088
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}