loading

What is a GPS or GLONASS ?

A GPS tracking unit is a device, normally carried by a moving vehicle or person, that uses the Global Positioning System to determine and track its precise location, and hence that of its carrier, at intervals. The recorded location data can be stored within the tracking unit, or it may be transmitted to a central location data base, or Internet-connected computer, using a cellular (GPRS or SMS), radio, or satellite modem embedded in the unit. Data tracking software is available for smartphones with GPS capability.

The Global Positioning System (GPS) is a satellite-based navigation system made up of a network of 24 satellites placed into orbit by the U.S. Department of Defense. GPS was originally intended for military applications, but in the 1980s, the government made the system available for civilian use. GPS works in any weather conditions, anywhere in the world, 24 hours a day. There are no subscription fees or setup charges to use GPS.

GPS tracking unit architecture :

A GPS tracker essentially contains a GPS module to receive the GPS signal and calculate the coordinates. For data loggers it contains large memory to store the coordinates, data pushers additionally contains the GSM/GPRS modem to transmit this information to a central computer either via SMS or via GPRS in form of IP packets. The diagram depicts a hardware architecture of an advanced GPS tracker.

Project :

The Adafruit FONA 808 is an amazing little breakout board that integrates not only a GSM/GPRS chip, but also a GPS on the same board.

Today I am going to use the FONA 808 breakout board along with Arduino to make a cool tracking project. This project can for example be used on objects that you don't want to go after a given distance. For example, you could place this project in a bicycle, and immediately know if it has been stolen.So basically we will be giving parameters for the boundary.

I will be using a simple on-board alarm system, composed of a LED and a Piezo buzzer, to tell when the boundary has been breached. Then, we will use Adafruit IO to track the location of the project in real-time, and immediately know if the boundary has been breached from the Adafruit IO dashboard.

Step 1: This Is How It Works

GPS satellites circle the earth twice a day in a very precise orbit and transmit signal information to earth. GPS receivers take this information and use trilateration to calculate the user's exact location. Essentially, the GPS receiver compares the time a signal was transmitted by a satellite with the time it was received. The time difference tells the GPS receiver how far away the satellite is. Now, with distance measurements from a few more satellites, the receiver can determine the user's position and display it on the unit's electronic map.

A GPS receiver must be locked on to the signal of at least 3 satellites to calculate a 2-D position (latitude and longitude) and track movement. With four or more satellites in view, the receiver can determine the user's 3-D position (latitude, longitude and altitude). Once the user's position has been determined, the GPS unit can calculate other information, such as speed, bearing, track, trip distance, distance to destination, sunrise and sunset time and more.

The GPS satellite system :

* The 24 satellites that make up the GPS space segment are orbiting the earth about 12,000 miles above us. They are constantly moving, making two complete orbits in less than 24 hours. These satellites are travelling at speeds of roughly 7,000 miles an hour.

* GPS satellites are powered by solar energy. They have backup batteries onboard to keep them running in the event of a solar eclipse, when there's no solar power. Small rocket boosters on each satellite keep them flying in the correct path.

What's the signal ?


GPS satellites transmit two low power radio signals, designated L1 and L2. Civilian GPS uses the L1 frequency of 1575.42 MHz in the UHF band. The signals travel by line of sight, meaning they will pass through clouds, glass and plastic but will not go through most solid objects such as buildings and mountains.
A GPS signal contains 3 different bits of information - a pseudorandom code, ephemeris data and almanac data. The pseudorandom code is simply an I.D. code that identifies which satellite is transmitting information. Ephemeris data, which is constantly transmitted by each satellite, contains important information about the status of the satellite (healthy or unhealthy), current date and time. This part of the signal is essential for determining a position. The almanac data tells the GPS receiver where each GPS satellite should be at any time throughout the day. Each satellite transmits almanac data showing the orbital information for that satellite and for every other satellite in the system.

Step 2: Hardware

Link's to Parts:

Arduino Uno(Clone works fine)

Adafruit FONA 808 breakout board

Jumper Cables

Breadboard

SMA or uFl antenna (depends on your board version, anything works perfectly well)

LED ( green/red)

330 ohm resistor

piezo buzzer

3.7V LiPo Battery

A 2G Sim ( Important )

Tools :

Soldering Iron

Rosin Core


For the FONA board, you will need a set of additional components: a GSM antenna, and also a GPS antenna. You will also need a working GPRS SIM card, with some data credit on it, that needs to be placed inside the FONA 808 breakout board. You will also need a 3.7V LiPo battery to power the breakout board.You can get a 1200 mah battery.

There are two versions of FONA, one is the SMA version and the other is uFl version.Both share the same features the only difference is their antennas.But for today's project I will be using the SMA Version.

For the 'alarm' part, you will need a simple red or green LED, a 330 Ohm resistor, and a piezo buzzer.

If you want an add on version you can get the FONA 808 which can be stacked on top of the UNO and you don't have to do any wiring just solder the header pins and connect the antennae and the sim card. Then upload the code.But since I don't have that version I am going use the 800 version of it for today's project.

Step 3: Library for Fona

The following is the library for FONA. If you would like to test the FONA,

Go To:

Arduino IDE >File>SketchBook>Libraries>Fona Lib..>Fona Test

The following connections are different and has been edited in the code.

There are variety of options to choose from Battery Voltage to Query, GPS Fix, Calling and SMS.

Step 4: Assembly

If you're using the FONA 808 shield, just plug it in. For the breakout, a little wiring is required. First, connect the power supply to the breadboard:

  • Connect the 5V pin from the Arduino board to the red power line/positive on the breadboard
  • The GND pin to the blue power line/negative.

You might have to solder the header pins to the breakout board properly or there might not be proper electrical conductivity.

After soldering, place the FONA 808 breakout on the breadboard.

  • Connect the VIO pin to the red power line
  • The GND & Key pins to the blue power line.

After that,

  • Connect the FONA RST pin to Arduino pin 4,
  • FONA TX to Arduino pin 3
  • RX to Arduino pin 2

Also connect the 3.7V LiPo battery, the GPS antenna, and the GSM antenna to the FONA 808 shield or breakout.

Also place the LED on the breadboard, in series with the 330-1K Ohm resistor. Connect it to pin number 6 of the Arduino board, and connect the other end to the ground.

This is how the completely assembled project looks like (Take a look above for the image)

Step 5: Adafruit IO

We are now going to take the same hardware & integrate it with Adafruit IO. We are going to use Adafruit IO to display the location of the project in real time on a map, and also display an alert in case the fence has been breached.

To use Adafruit IO you should have an Adafruit account a you must register your name for the invite, only then you can use Adafruit IO.After all this is done, it might take a week or two to get your Adafruit IO.

Step 6: Tracking and Alerts

In this first project, we will continuously check the location of the project, and see if we exceeded a given distance that we set in the sketch as well.

If that's the case, we will make the LED blink, and also make the buzzer emit a sound.

We first declare some constants & variables for the alarm:

// LED & Buzzer pins<br>const int ledPin = 6;
const int buzzerPin = 9;
// Alarm
int counter = 0;
bool alarm = false;

Then, we set the maximum distance that the project can go without raising the alarm. Note that the precision of a civilian GPS like this one is around 10 meters, so I really suggest setting a value which is superior to 20 meters or so:

const float maxDistance = 100;

We also declare two variables that will contain the initial location of the project:

float initialLatitude;<br>float initialLongitude;

By default, we set the alarm to be false:

alarm = false;

In the setup() function of the sketch, we get a GPS fix to set the initial location of the project:

bool gpsFix = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);<br>initialLatitude = latitude; 
initialLongitude = longitude;
In the loop() function of the sketch, we constantly get the current GPS location, and then calculate the difference between this & the initial location:
float distance = distanceCoordinates(latitude, longitude, initialLatitude, initialLongitude);
we also print this distance inside the Serial monitor:
Serial.print("Distance: ");<br>printFloat(distance, 5);
Serial.println("");
If the measured distance exceeded the maximum distance we allowed, we also set the alarm on:
if (distance > maxDistance) {<br>  alarm = true;
}

After that, we check if we are in alarm mode or not, and act on the LED & Piezo buzzer accordingly:

if (alarm == false) {<br>
  if (millis() - counter > 5000) {
    
digitalWrite(ledPin, HIGH);
 
 }
  if (millis() - counter > 5100) {
    
digitalWrite(ledPin, LOW);
    
counter = millis();
  }
  noTone(buzzerPin);
    
} 
else {
    
  
if (millis() - counter > 100) {
    
digitalWrite(ledPin, HIGH);
 
 }
  if (millis() - counter > 200) {
    
digitalWrite(ledPin, LOW);
    
counter = millis();
 
 }
  
 
 tone(buzzerPin, 1000); 
}

It's now time to test the project! Upload the code to the Arduino board, and open the Serial monitor. You should see that initially, the distance is equal to zero, or at a small value.
Indeed, note that the precision of the GPS is around 10 meters, so between two measurements the position will change slightly. You can also take the project for a short walk by going out of the boundary you set, and see if it raises the alarm!

The best thing is it leaves points, where it was last found in other words Geotargeting.

Step 7: Resources

You can refer to the following links for any information on SIM800 for your doubts or your next project.

SIM800 COMMAND MANUAL

SIM800 FM APP NOTE

SIM800 IP App Note

SIM800 GSM Location App Note

SIM800 Embedded AT App Note

Step 8: Battery Consumption

The other aspect we haven't talked about here is power consumption. It would be safe to assume that if you are building a cellular tracker, you will want to put it on something that moves, which will mean it will need to stray from the power outlet/usb ports of our world. This means battery power, which means measuring power consumption and calculating battery life, etc.

Cellular stuff has a reputation for being pretty power hungry. Adafruit says this module can draw up to 2 Amps (!!) in short bursts. However, the way we are using it, it spends most of its time power off, consuming very little.

I measured the power consumption from the Battery during normal use.


Powered on: ~ 25mA

Get Request: Peaks at 150-200mA for short durations

One full cycle of requesting location and sending a GET request consumes ~ 7.47 joules

avg of 53.4 mA for 35 Seconds

Powered off: ~150µA quiescent power consumption

If we were using a battery with a capacity of 1200mAH, we could get send locations for ~ 12 days at 15 minute intervals before the battery gave out. (in theory, and not considering the power consumption of the Arduino).

Step 9: Upgrades

Ideas for upgrading:

3G version of FONA for a fasterer experience

Upgrading antennae for a wider coverage

Using Sparkfun Data Service

Upgrading to stackable version of the board

Setting up a box for storing the project

<p>Hi! This is really valuable information here, even more since I am a beginner in arduino who wants to build something very similar. Do you happen to know if this would work with the adafruit flora board, since I am planning to make a wearable tracker?</p><p>Thanks a lot!</p>
You cannot use the flora with this project because the flora operates at 3.3v if I am not wrong.
<p>The code won't work with the 3G version because they have different sim modules</p><p>Here is the Difference :</p>* FONA 800 starts at 1 (one) where as the FONA 3G starts at 0 (zero)<p>* After sending an SMS using <strong>AT+ CMGS</strong> the FONA 3G returns two sets of CRLF's that do not appear with the FONA 800.</p><p>* GSMLOC (location via triangulation of nearest cell towers) is supported by the FONA 800 but not 3G.</p><p>* If you request the # of SMS's on the SIM module with <strong>AT+CPMS?</strong> the FONA 800 reply starts with<strong> +CPMS: &quot;SM_P&quot;</strong> whereas the 3G starts with <strong>+CPMS: &quot;ME&quot;</strong></p>
<p>Hi do you know if the same code works for the 3g fona?</p>

About This Instructable

10,367views

72favorites

License:

Bio: I am a 14 year old kid who is passionate about electronics and love exploring on Arduino, Pixhawk and Rasberry Pi.
More by Arbot:Arduino GPS/GSM Tracker (WatchDog Enabled) Arduino Ble Rover 
Add instructable to: