Door Beacon - A Fully Autonomous Door Lock
- Brett Schenck
- Mar 28, 2017
- 4 min read
You know what I'm far too guilty of doing? Leaving my door unlocked when I go outside. And in this day and age, you never know what kind of scary person could enter your cave. I don't really know why I forget to lock it. I suppose sometimes it is just the inconvenience of toting my wad of keys around with me. Nevertheless, I set out to solve this problem and completely remove the human element from the equation.

The first thing I did was search the internet to see if I wasn't alone and if this problem hadn't been solved before. Turns out, it actually has been. Well, sort of. I came across a hackaday.io post for a web enabled door lock created by Hacker House. This was exactly what I was looking for in terms of lock covers (see right), but the software wasn't the "hands-free" approach I was going for and the controller/wiring weren't as eye-catching either.
I knew for Door Beacon, I'd need a way for it to be autonomous. Therefore, it would require no direct human input to achieve our desired output. I needed something that could sense when I was walking towards my door or away from my door. There are probably dozens of ways I could have achieved this (PIR, Computer Vision, etc), but I had worked with Bluetooth Low Energy (BLE) before and that's the road I set out on. What's great about BLE is implied by its name, "Low Energy." With BLE, I can transmit an advertisement once a second for a over a year on a single cell battery. This is just the power consumption I was looking for.
In radio signal theory, there is a theoretical electromagnetic relationship between the transmit power (A_dBm), the received signal strength indicator (RSSI_dBm), the propagation constant/path-loss exponent (n), and the distance between antennas in meters.

This project takes full advantage of this relationship to calculate our theoretical distance to Door Beacon at any given time. Our device receives the defined transmit power at 1m in the BLE beacon advertisement. It also knows the strength of the signal that it is receiving. From there, we could calculate the distance.

Moving past all the fun math stuff, we get into the hardware. I didn't want to dedicate a larger Raspberry Pi 3 like Hacker House did. Instead, I wanted to use my Raspberry Pi Zero I had laying around. The Pi Zero is a scaled down version of the Pi 3 and was perfect for this embedded project. During the time I was designing this, the Pi Zero W had come out with built in WiFi/Bluetooth. However, they were on backorder as they sold out almost immediately upon release. Fortunately for me, RedBear makes a HAT (Hardware Attached on Top) that adds WiFi/Bluetooth to the Pi Zero AND it comes with a pre-soldered u.FL antenna connector to switch between the on-board antenna or using your own. Which turned out in my favor over the Pi Zero W, because I ended up needing to boost the signal with an external antenna.

After I located my controller and receiver, the next important design phase was to determine how I was going to power this. I am quite fond of UPS (Uninterruptible Power Supply) systems. When it comes to getting into your home, I couldn't risk having a power outage knock me offline. I wanted a fail-safe to guarantee entry into my home. So I took a 3.7V Li-Ion 18650 and the popular Adafruit PowerBoost 1000C Battery Charger to provide a constant power source for my system. If the micro USB is unplugged, the system runs off the battery. Conversely, if the battery is unplugged, the system runs off the micro USB connection. Yay power!

I then set out to design an enclosure for my battery and electronics. I always feared the realm of 3D modeling and CAD, but it wasn't painful or scary at all! I made use of this free online CAD tool called OnShape. It is quite powerful and allowed me to design shelves for the Pi Zero and HAT to slide into. The curve on the bottom was design to sit right on top of the lock cover. The rectangular hole on the bottom is for the 18650 to sit in. Once I had this designed, it was ready for 3D printing. I printed mine in Hatchbox white PLA on my Makerbot Rep 2.

Once the Pi electronics were mounted in the designed enclosure, next was to fix the cover to the servo horn:

Now on to the most challenging part of this project: programming. The software that Hacker House used was written in Node JS to connect to a Blynk server. Blynk allows you to build a drag and drop IoT project in as little as 5 minutes. While this sounds inherently easy to use, it was actually quite the opposite if you're unfamiliar with Javascript, let alone Node JS. The server side language must be event driven, non-blocking code. Meaning that if your main process is a loop constantly connecting to a server and listening to virtual pin events, then trying to implement a second loop that constantly scans for iBeacons that is "non-blocking"would prove to be more of a hassle than I was prepared to deal with. I did try valiantly to spawn and fork a child process scanning the beacons, but it was always blocking. Nevertheless, I persevered and decided to write my own Python script that would scan the beacons, determine the proximity, and control a servo motor. Turns out that doing any semi-advanced arithmetic is better suited in Python anyways than in Node JS due to availability of math libraries. If you guys are interested in this code or a more detailed DIY guide, please let me know!
Once I had this coded and working, I was ready to solder it and mount everything to my door. While the wiring isn't concealed, it is still wireless in the sense that it doesn't need to be powered continuously from an AC outlet. There is some lag in the system and room for improvement/addons. Let me know what you guys think!

Comments