Monday, March 26, 2018

GPS Lockbox

I recently completed a project for my computer science project in school. The project was an end of the year type thing, and it was to make anything you wanted using code. Most other people made apps or games, but I wanted to do something with hardware. My partner and I came up with the idea to make a box that only unlocks itself when it is within a set radius of a location. I already had a Raspberry Pi, so I planned to use that. To open the box, we used a servo motor from an RC plane. I ended up purchasing a GPS module for the Raspberry Pi and a small LCD screen to print out location data. Getting the GPS to interface with the RPi was pretty hard. I watched a lot of Youtube videos and did a lot of research before finally being able to receive some data. However, this data just looked like random strings of different characters. I did some more research and found that GPS uses special tags in front of different data to identify what type it is. For example, the string "GPRMS$" will be in front of the date and time data. I found the tag for latitude and longitude data and wrote some code in Python to only print out the latitude and longitude. Next, I had to figure out how to make sure the device was within the radius of a set lat/long. I found a mathematical formula online called the Haversine formula that could be implemented in my code. It takes in destination and current location coordinates and spits out the distance between the two, taking into account the earth's curvature. After doing some tuning and testing of the coordinates, the code worked. I figured out how to control the servo motor with the Raspberry Pi using PWM (Pulse With Modulation) and added the servo control part to my existing GPS code. I cleaned up the final code a bit so that the data being outputted to the LCD screen was more reader-friendly and usable. Finally, I put all the hardware components into a plastic container I found lying around and created a simple locking mechanism with some old Lego pieces and hot glue (this box is really easy to get into even when it was locked, but it was meant to be a proof of concept). The RPi was powered by a portable charger and the LCD from a 9V battery. This made the whole setup portable, so you could walk towards the location and watch the current lat/long. change. Overall, the whole project was a success. I learned about GPS and got better at programming in Python during this experience. See pictures and code here
Entire Assembly 

Raspberry Pi Code

Locked Position

Unlocked Position

Servo connected to GPIO Pins

Command Line UX

GPS module via GPIO

Pi and GPS module