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.

100 thoughts on “How to Make a Smartphone Connected Door Lock

  1. Wow! That's an awesome video! Thanks for using Blynk.

    By the way, if you'd like to share the access to the lock – you can use the Sharing Functionality. In this case you won't need to give others your email and password.

    http://docs.blynk.cc/#sharing-shared-access-to-your-hardware

  2. Good day, Is it possible to merge or connect two of your projects: Smart Security Camera and Smartphone Connected Home Door Lock in one project? Does the raspberry pi 3 can run them simultaneously? Thank you

  3. Sir ji i want.. My mixi to Canect to Remote
    I wan crate 1Remote and 1 Remote Reciver
    I canect any 10 Home product. On/off bye 1 Remote Like Fan. Light. Mixi. On/ off by 1Remote…Plz. Help Me
    my Whatapp No.+91 9266644470 Mk.Beniwal

  4. hi there, i want to ask if the owner can perform the lock and unlock operation away from home( using mobile data) or only able using home wi-fi range only?
    im very thankful for your help.

  5. Great project. The only thing I'd say is that, to get the same functionality with an ESP8266 would be infinitely simpler and cheaper. Still, if it's a Raspberry Pi project you're after, this is a great one!

  6. I have a question beyond the subject – where can I buy the jacket the young woman has at the beginning of the video? Or what is the brand name? Tkanks.

  7. I'm getting an error when I try to run 'sudo node /path/doorlock.js' (obviously I replace path). I checked to make sure all the dependencies were installed correctly (they did). The error message thrown is '/path/node_modules/pigpio/node_modules/bindings/bindings.js:91
    throw err
    ^

    Error: Could not locate the bindings file. Tried:
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/build/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/build/Debug/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/build/Release/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/out/Debug/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/Debug/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/out/Release/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/Release/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/build/default/pigpio.node
    → /home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/compiled/6.12.3/linux/arm/pigpio.node
    at bindings (/home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/node_modules/bindings/bindings.js:88:9)
    at Object.<anonymous> (/home/pi/Downloads/Smartphone-Doorlock-master/node_modules/pigpio/pigpio.js:5:31)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/pi/Downloads/Smartphone-Doorlock-master/doorlock.js:46:30)"
    My interpretation is that it is not creating the nodes so I reinstalled the latest recommended C compiler which yielded an identical error. Any advice is appreciated. I'm a veteran user so I just need a solution. Also just in case anyone else was having the issues. I had trouble installing npm on/off for some reason, and had to cd into the troublesome directory and sudo chown root:root * that sucker which fixed it nicely. Thanks in advance!

    Edit: I checked and pigpio's C library was installed correctly in /usr/share and I think some other places. I believe there must have been a version change which broke your code. Unfortunately I don't know javascript so I cannot help you.

  8. Could you add another button on the case that is programmed to lock or unlock the door depending on which state it is in?
    I don't know too much about this kind of stuff but for sure want to learn about it. The servo is it always in one place until told to be moved or can it be freely turned as you want but moves when it is told to? If it can be moved freely an opening could be made on the casing so you could reach a finger in a turn the lock physically right? Also, does the servo keep track of how much it has turned or is it just a motor that moves when it is told?
    I would love to learn about this so if you have any knowledge to share please do so! Thanks.

  9. Hi guys, i have recently bought my raspberry pi 3 but when i use this tutorial i get the following code after trying to start doorlock program,

    [email protected]:~/code/Smartphone-Doorlock $ sudo node doorlock.js
    /home/pi/code/Smartphone-Doorlock/doorlock.js:40
    var blynkToken = '042336f74eb64113b4e1e00d40eaded7':
    ^

    SyntaxError: Unexpected token :
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

    It would be greatly appreciated if someone can help me with this!!!

  10. You should be able to design it so you can use the servo and the key to open and close the lock. You just need to have a slack between the servo and the lock turn. Like let the servo lock with a fork on the original manual lock turn.

  11. i faced an issue , the lock was working perfectly earlier, but now the state of motor is 1.0 or 0.0 and the motor is not working . Although it's working for simple interfacing with R-pi code.

  12. I keep getting the error "could not locate bindings file" when running the program with "sudo node doorlock.js"
    do you know what might be wrong?

  13. Would be good if you could manually override your servo if you need to enter with a key in case your internet is out

  14. how can i running at startup? i have follow all the instruction but everytime i power on my raspberry in blynk it says offline, i must run it on terminal every single time. or do i used to run it on terminal every time? thanks

  15. Guys, I just stumbled onto your site today. You two rock! This is a GREAT site. I am pretty obsessed with home automation and seeing what home users can accomplish. I love that you guys are giving us great tools and the projects are in stable shape. Seriously making them pretty and hiding wires and painting cables.. I would rather we do that and you guys concentrate on the bones and muscle of the projects. (I am just putting that in cause amazed when people are complaining about "I see wires!!!!". They should know how to hide a wire!) I am looking back now at your project list for fun cool ideas! you ROCK!

  16. Since you already have raspberry pi , you can install https://github.com/KhaosT/HAP-NodeJS into the pi and configure properly so this will be available in you home network and can be accessed by any apple devices.

  17. For doors with not a turning handle on the outside, would it be possible to remove the door knob lock (we call it tongue in my country, I am talking about the thing that closes and opens when you turn the door knob). Remove it or replace it with one that opens and closes with some basic force then have an external lock that has a female insert screwed on the door and a male remote controled piece on the wall that locks the door tightly closed using the app.

    that way you can still use your doors lock system and as a backup and keep that unlocked when you want to remotely open the door by opening the external mechanism.

  18. Thanks. But why would you not combine a 3d printed housing for the Pi as well so it doesn't look like garbage.

  19. Any thoughts on using an HTTP server on NodeMCU rather than a NodeJS on Pi. I'm thinking less complexity, less spaghetti. A magnetic closure sensor would be cool too so that you could also open/close state.

  20. Can u please make a video on temperature control ing using pis controller? It's my final year project if anyone in the comment section knows this please help me

  21. its stupid to use raspberry pi for this. All you need is a simple wifi connected board that does on off and is connected to a smart home hub. takes less space therefore better.

  22. Amazing video, but I was wondering if it’s possible to add Alexa voice recognition to some how control the raspberry pi in order to lock and unlock the door 🙂

  23. Innavations full of image!~ the most difficult task for a a new project is from idea to a real product, …Makerfabs provide maker& startups PCBA prorotyping , to make these project from dream to true..

  24. Just use esp886 and some microcontroller like stm32 still there's a need for a server or computer logged into internet so we can access and that's why we use raspberry. Miss you guys, hopefully you are doing great in your other projects. YouTube isn't enough anymore

  25. That's amazing. Many of Molilock's app controlled door lock can be controlled by an app. I think it meets the need of current customers

  26. To anyone having issue with the install.

    DO NOT FOLLOW THE NODE INSTALL GUIDE THEY SUGGEST.

    Legit don't do it. Just install from apt-get. This allowed me to run the program with no issue.

  27. This looks really nice, but also really dangerous if someone really uses this. Blynk has to get 1 database breach and every door can be unlocked by logging in and yeah, opening the door. It looks fun for other things tho! 🙂

  28. Kits? can you give an SD card with all the tec parts done? So i can just plug and play with my Pie?
    Anyways, awesome vid! I'm doing to a door that's a secret door to a secret room. It'll also be spring loaded so it'll unlock and open. I'm going to put most of this inside the door and connect the wiring inside the wall. Been wondering how to do the lock on this door, so thanks again!

  29. It is possible to connect the App with Alexa or Google Assistant? To Lock and Unlock with Voice Command?

  30. Plastic parts, glue, double sided tape, an overkill controller, that runs 3rd party software and uses unreliable SD card as storage… Wow! There's some high level security for your home… 😉

  31. Can you please make a tutorial on port forwarding the blynk local server on raspberry pi ?
    Thank you in advance.

Leave a Reply

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