How to Make a Smartphone Connected Door Lock


Oh Hey guys, Davis here. In this video we’re going to be making an automated door lock for your home, which you can connect with your smartphone. And multiple smartphones can be connected to this doorlock using a shared username and password. You can also receive notifications on your phone whenever someone else locks or unlocks your door. And since this design doesn’t work with a key, make sure you have another way to get into your home like through your back door, or your garage. And as always, the full parts list to this project will be posted in the description. To make the door lock actuate, we’re going to need a high torque servo. This particular servo has metal gears. It’s a Tower Pro MG995R, but the MG996R should work as well. You basically want to make sure that it is standard size and has at least 8 kg-cm of torque at 5 volts. This is how we’re going to mount the servo. It’s a couple 3D printed parts we made for the door lock housing, and it holds a servo and a couple other things like an LED light to indicate when it’s locked and also a button to operate it manually. We’ll gonna provide models for these parts on our hackaday.io page, or you can buy them from us if you don’t have access to a 3D printer. Alternatively, we’ve got plans to make a wooden version of this project. We built the door lock head connector, And this is basically just a few pieces of MDF bonded together with wood glue. And it’s not really perfect, but it should do the job. The 3D printed housing has a slot for the servo. There are two holes on one side of the slot, and a rounded gap on the other side. The rounded gap makes it easy to push the wires through while fitting the servo. You’ll have to push the servo up through the bottom, then use some #6 standard or 3 mm metric bolts and nuts to attach it. Depending on how close the deadbolt is to your servo, you might need to add a few spacers to make it fit properly. Next, we glued the servo horn that was included with our servo kit into the slot on the deadbolt connector piece, and let it dry for a couple hours. Make sure that you don’t glue this on backwards. The LED and button are optional, but nice if you don’t always want to use your phone. In addition to these parts you need a 470 ohm, 1k ohm, and 10k ohm resistor as well as 4 female jumper wires. We soldered the wires using the on screen schematic. This will also be provided on our hackaday.io page. For some of the wires like power and ground that had multiple connections like power and ground, we cut a few pieces of wire and joined them all at the end so that we could connect them to just one female connector. We then wrapped all the other components in either electrical tape or heat shrink so that they won’t short out. To hold the components in place, we used some glue and let them sit overnight to dry. This diagram shows how we’re going to connect all the wires to the Raspberry Pi. We’re using the Raspberry Pi 3 to control this project because it has built in WiFi. You can also use any other Pi as long as it is connected to the internet. Since the power, ground, and signal wires on the servo are not in the correct order to connect them directly to the GPIO pins, we’re going to have to switch the brown ground wire and red power wire. To do this, I used a small screwdriver and pulled up on the small tab holding the wire in place, so that I can pull them out of the connector. You can connect the wires by pushing them into the new slot. The signal wire should be connected to GPIO pin 14. Make sure that you have the wires plugged into the correct pin if you’re using a different Pi. We’ve also attached our LED and button. The power cable should be plugged into the 3.3V pin, our button to the GPIO pin 4, and the LED to the GPIO 17 pin. You can change these in the software if you want to use different pins. The ground can be plugged into any available ground pin on your pi. We’re going to be using a pre-existing framework called Blynk to control our doorlock with a smartphone. Blynk allows you to easily interface with hardware on your Raspberry Pi through their phone app. On their getting started guide, there is a section for installation instructions on a Raspberry Pi. You’re going to want to make sure that you follow those steps on your Raspberry Pi. We’re going to be using the node.js library to run this project. Once you’ve installed all of the dependencies on your Raspberry Pi, you need to create a project with their smartphone app. Download the app on Google Play or the app store. When you open the app for the first time, there will be a login prompt. The login credentials that you use in this step can be shared so that multiple smartphones can lock and unlock the door. Once you’ve created an account, click the create a project button. I named my project Doorlock. In the project, you will need to add two components. Double tap to bring up the components menu and create a simple button. This will be the button that we use to control the door lock. Make sure to change the output so that it is a virtual pin zero, which can have the value of 0 or 1. I changed my labels so that 0 corresponds to locked, and 1 to unlocked. The last thing you want to do in the app is add another component for push notifications. Pressing the play button will start the project. You will need to save an API key in order to connect to this project on your pi. You can find it by clicking on the settings button. On your Raspberry Pi, you’re going to need to download some code in order to get your door lock to work. You can clone this code from our GitHub repository by clicking the green button and downloading the zip file, or using the command “git clone” and add the SSH link. This is assuming you already have git installed. Navigate to the directory that you cloned the repository in by using ‘cd’. Then run ‘sudo npm install’ to install all of the dependencies. Add the API key that you found earlier by opening up the doorlock.js file with ‘vim’. In addition to a few other parameters that you can edit, there is a blynkToken variable. Press ‘i’ to edit, then paste your token. You can save your changes by pressing ‘esc’, then ‘:wq’. Type ‘sudo node doorlock.js’ to start the door lock program. You should see the console output ‘Blynk ready.’ if it works properly. You will need to make sure that you enable autostart for the door lock program. First type ‘pwd’ to copy the current directory. I selected the current directory and pressed copy, then used ‘sudo vim /etc/rc.local’ to edit the file. Press ‘i’, then scroll down and add ‘sudo node’, that full path to the door lock directory that you were just in. ‘/doorlock.js’ to the end of the file before ‘Exit 0’ Then press ‘esc’ and then ‘:wq!’ to save and exit. If you run into any issues, make sure to check the GitHub repository for more help. To mount the housing on the deadbolt, we’re going to use some of this outdoor mounting tape. It’s super strong, but it peels off like a command strip, so it shouldn’t ruin your paint. Make sure your dead bolt on the door is locked and also use the app to lock the door in Blynk. This will help you align the housing when you mount it. Hold the door housing up to the door lock with the tab on the bottom. Adjust the deadbolt connector so that it aligns with the lock. We locked and unlocked the servo with the app a few times to make sure that the orientation was correct. Use a few pieces of the outdoor mounting tape to attach the housing to the door. We also attached our Raspberry Pi to the door with another piece of mounting tape. And you want to make sure to mount this Raspberry Pi on the side of the door closest to the hinge, so the Raspberry Pi wire doesn’t get pulled out while the door is opening. Here’s a demo of the door actuating. The red light on the housing indicates that the door is locked. By pressing the button, you can change the state of the door lock. You can also control it with the app. When the door is locked or unlocked, Blynk will send you a notification. But only one notification can only be sent every 15 seconds, so if you spam the button, you won’t get a bunch of notifications. Thanks for watching. I hope you guys enjoyed this video. If you want, we’re thinking about selling kits for this project so you don’t have to manually track down all the parts online. If there is any interest in that, we’ll start selling the kit and then post a link in the description so you can find it easily. If you haven’t already, make sure you subscribe to keep up to date with all our our projects. Until then, see you next time.

Leave a Reply

Your email address will not be published. Required fields are marked *