I wanted to build a complete solution for a GPS vehicle anti-theft device, which would be:
- as cheap as possible
- as complete as possible
- as it-just-works-there's-nothing-else-to-do as possible
So I ended up building an Arduino-based solution that cost me a total of 25$, more or less.
As you can see from the video, it just works! You start the car, you get a notification on your mobile phone that the car is moving, then you open the mobile app and you can see the car moving in real time (with a 10 seconds update lag).
This tutorial will guide you through all the steps, keeping in mind there are several components in the solution:
1) the hardware (Arduino based)
2) the software (Arduino program)
3) more software (server-side receiving of the gps locations)
4) even more software (the mobile app)
Step 1: The Hardware
1) Arduino Uno R3 or clone. I used the "DCcEle DCcduino uno" clone, which doesn't seem to be available anymore. Here's an equivalent: on Aliexpress - 3.75$
2) GPS unit for Arduino (GY-NEO6MV2 new GPS module with Flight Control Flight Control EEPROM MWC APM2.5 large antenna NEO6MV2). I used this: on Aliexpress - 6.66$
3) GPRS / GSM unit for Arduino (SIM800L V2.0 5V Wireless GSM GPRS MODULE Quad-Band W/ Antenna Cable Cap). I used this: on Aliexpress - 6.71$
4) Spare dupont cables like these: on Aliexpress - 0.89$
5) IoT data sim card (or any other sim card with a data connection). I used this: from Hologram.io . I've got a free developer one, only paid shipping - 7.50$
Total: 25.51$, but I had the cables already so it's less then 25$ !
The two pictures show the components before assembling, and the final product. The connections you have to make are:
Arduino -- SIM800L
10 -- RESET
GND -- GND (2 of them)
5v -- 5v
7 -- SIM_TXD
8 -- SIM_RXD
Arduino -- GY-NEO6MV2
GND -- GND
5v -- VCC
3 -- RX
4 -- TX
Connect all the cables and antennas and make sure you power up the Arduino from a source capable of giving you peaks of 2A. The computer usb is barely fine (I'm using a MacBook Pro), a "random" phone charger won't be enough. Most cars usb outlets also are less than 1A. If that's your case, you also need a 12v car 5v power supply with at least 2A.
Insert the sim card. If you are using the Hologram.io sim card, make sure you register on their dashboard and activate the sim card (it takes a few minutes / hours).
Step 2: The Software (Arduino Program)
I'm going to assume you're familiar with Arduino programming. Otherwise, please start with this guide: on Instructables.
You only need one external library, I had to install it manually. Go here : TinyGPS, export the library, and install it in your local Arduino folder.
From there, we are going to "steal" some code from their basic example, and modify it to our purposes.
We are then going to "steal" from this guide and modify the code again to our purposes.
The result is the attached .ino program.
There are a couple of things you can and HAVE to tweak:
the "SECONDS" define, and the "SERVER" define.
I've set SECONDS to 10 and here is why: the Hologram.io developer program gives you 1mb of free data per month. Which means, we want to minimize the bytes sent, but also we need to update our position just so often. We're going to use standard AT modem commands to send UDP packets to our server receiving the messages, with lat/lon, each using 4 bytes, and speed using 1 byte. So the total gps update is 20 bytes (IP header) plus 8 bytes (UDP header) plus 9 bytes (payload). That's 37 bytes. Assuming my car is active no more than 2 hours per day, I can afford an update every 10 seconds and consume only 806kb a month (31 days). That gives me 218kb for the driving time over my own, that is, the car thief. Which gives me 16.76 hours of gps monitoring outside my driving time, with one update every 10 seconds.
Now, these UDP packets have to go somewhere. I'm using an Ubuntu server hosted on a CloudAtCost cloud, which I bought for 8$ with an 80% discount, and which is serving me other purposes, thus doesn't go into the cost calculations. If you don't want to pay for a server, you can get a free Amazon AWS instance for 12months, and install Ubuntu on it. Once you have your server setup (see next step), get its static IP address, and put it next to the SERVER define.
Step 3: More Software (server-side Receiving of the Gps Locations)
Both CloudAtCost and Amazon come with a pre-configured Ubuntu image (CloudAtCost is at Ubuntu 14.04). So I'm not going through the steps to install Ubuntu, as you won't have to. If you're using CloudAtCost, you may want to upgrade to Ubuntu 16.04, that's done with a
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
Then you need to install LAMP (refer to this guide: here), though we're not going to use PHP.
Install Python with
sudo apt-get install python-minimal pip
Then add a couple of modules:
pip install --user urllib3 requests
We need to set /var/www writeable by you, so let's do:
sudo adduser YOUR_USER www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rwX /var/www
Now, we need a "server" to i) receive the UDP packets, ii) build the track, iii) send a notification to our mobile phone, and a "server" to serve the created gps track (this will be apache).
For the first server, copy the attached python code. You need to configure the following things:
iftttuser="YOUR IFTTT USER"
iftttpass="YOUR IFTTT PASSWORD"
iftttappletid="YOUR IFTTT NOTIFICATION APPLET"
iftttkey="YOUR IFTTT KEY"
iftttevent="YOUR IFTTT EVENT"
As you may have guessed, we're using IFTTT to server real-time notifications to our mobile phones. Follow this guide: here but instead of selecting "send me an sms", select "send an app notification". Get your applet id (scroll at the bottom of the applet's configuration to see it) and use that above. Use also the so created key in the settings above. The IFTTT event is the name you gave to your applet, I gave it "carmoving".
Now, there is no real real-time notifications platforms for free, AFAIK. If you do know of one, let me know. IFTTT has a delay. This delay can be minimized to a few seconds if you use the email trigger. Unfortunately, this is not reliable. The just created webhook has a 15 minutes delay. But we don't want to wait for 15 minutes to know that our car is being stolen, right? That is the password of asking you to setup all the above settings. If you scroll the python code, you see there are a few lines, namely 45-53, to automated the "check now" functionality of IFTTT, which forces a sudden check of the triggers, and triggers the notification in less than 1 second! You're welcome :)
Once you have setup your python code somewhere, just run it. If you're a pro user, have it start at server boot. Refer to the tons of free guides online on how to do that, for example this one.
Step 4: Even More Software (the Mobile App)
We need a fast and simple way to just visualize the gps track that the server on the previous step is keeping up to date. Possibly, it has to work on all sorts of smartphone.
Let's then use a cross-platform mobile app suite, like Ionic/Cordova. I'm using Ionic v1, don't confuse it with Ionic Native, or Ionic v2, that's a different thing.
Follow these very simple steps to start your first project in Ionic: here.
Then, you need to start a new project based on the google maps sdk, like this:
ionic start myapp maps
Go into the "resources" folder and copy the large car image here as "icon.png". Upload instead the small icons as "car2.png" and "start.png" somewhere on your server, like http://yourserver/car2.png. You're going to need these as markers in your app.
Use the attached index.html (rename index.html.txt to index.html), directives.js, and controllers.js files, and put them into www (index.html), www/js (all the js).
add your platform like this:
ionic add plaftorm android
build like this:
ionic build android
then ionic will tell you where it built your .apk that you can install on your mobile phone.
To build for iOS, you'll need a Mac, and Xcode. ionic can then save an Xcode project, that you can open in Xcode and build for your phone. If you don't have an iOS developer account, you'll then have to attach your phone to Xcode and setup your phone for development to be able to install the app there. This is outside of the scope of this instructable.
In the various js files, you'll need to find the lines corresponding to "car2.png" and "start.png" and modify them with the path of your images. Same for "plan.json".
Step 5: Future Work
1) I've put everything into a cardboard box which I can hide anywhere near the usb outlet. The best thing to do would be to mount a better case under the hood of the car, with a 12v->5v converter.
2) With a bluetooth sensor, you could actually "sense" if you're in the car, so the gps system won't turn on.
3) Just pay for a sim data plan and set SECONDS to 1 to enjoy super-real-time tracking :)
Hope you enjoyed this first instructable of mine!
Participated in the
Arduino Contest 2017
Participated in the
First Time Author Contest 2018
Participated in the
Wheels Contest 2017