One lock to unlock them all - the Electronic Door Lock project at KEK

  • Anto Jose on 5 Apr

To make the KEK physical space even more accessible to all of the community, we need to make sure the doors are open to anyone in need, even when the residents have stepped out for a few hours.

One solution would be to circulate around a set of duplicate keys. Or another would be to make sure that somebody is always there to open the door.

Or the fun way would be to automate all of that in a very scalable Electronic Door Lock, as suggested by Cherry. The idea was to interface a motor to the existing deadbolt lock (for which the specs were obtained from Dorset's website).

And last weekend, we had Santhosh and Vinayan doing exactly that. Here is a brief on what happened:

In order to automate the lock system we needed to ensure the following conditions were met
1. Motor driven mechanism that can turn the lock in the desired direction to open or close.
2. Making sure to authenticate the person who wants to get access to KeK workspace.
3. Make sure in case the electronic system fails the door is still functional and accessible.
Let us look into each of the above mentioned points
1. After some snooping around we found that the deadbolt has a turn of 180 degrees, so 180 degrees Anti Clockwise would unlock the door and vice versa would lock the Door, initially we had the idea of using a DC motor to do the job, but that turned out to be complicated. We came across a nice post where they used a Servo Motor to get the job done. And we deicded to not a reinvent the wheel and invested in a simple off the shelf hobby Servo Motor (with Nylon shaft).

2. This was rather tricky, Vinayan and I had brainstormed on this for quite a bit, the initial thought was why not RFID and we had the necessary hardware to do it, but then it would just shift the problem from having a duplicate key to have a proper RFID card, in addition to which the software overload of adding and deleting cards would just be cumbersome. One idea that popped up was to use Bluetooth based authentication and on a similar train of thought was WiFi Based authentication, of course this means we may need to serve a small webpage where people can input some kind of passcode. This Bluetooth / WiFi approach seemed reasonable.
3. To ensure the system still worked in the event of complete electronic / mechanical failure, the Door lock that is installed can operate indepdendently from either side, meaning the Knob and the Key based mechanism could open the lock without knowing the state of one another, so if the power were gone the door could still be opened from outside. Incase things failed inside, the shaft of the motor was able to turn in the direction of opening or closing with a bit of effort from the side of the user, of course this being done regularly will eventually damage the motor, but no one will get locked out or locked in the building.
So keeping these in mind we went on to make a prototype of the system as a Proof of concept demonstration. We had some things to start off with and we spent a bit of money on the others.
* Prototype Door Lock to play with - INR 1390
* Servo Motor with a nylon shaft - INR 650
* NodeMCU (ESP8266 based microcontroller board) - Had this one lying around
* 12V 1A Power Supply - This was also lying around
* Intel Edition with Arduino Expansion Shield - Vinayan was kind to bring the one he had
* Duct Tape - We always have this lying around
* Cable Ties - We had some that we used for tying up the cables etc
We spent quite sometime trying to mount the Motor to the dead bolt knob correctly. Using a technique similar to what is mentioned in the blog[3], we were able to place the motor over the lock, with some cable ties and duct tape we were able to reinforce the motor in position over the knob, so that the torsional forces would not move the motor around instead of the knob.

We powered up the Edison board and did some continous run of the Sweep example from the Arduino IDE, in the rounds of stress testing of continous turning of the lock to open or closed state, we did notice that at time, the motor failed to move or just was stuck in position. Interestingly adjusting the delay between each step of the sweep from 15ms to 10ms gave us a smooth movement without the lock getting stuck occasionally.
Later that night, we were trying out various methods to do Authentication including Bluetooth and WiFi, since we both were not familiar with operating the WiFi off the Edison board, we used the NodeMCU board to do some prototyping. One of the ways we tried to authenticate a person was for the NodeMCU board to act as a Soft Access Point to which people can login with their devices and then activate the lock, but we ran into problems ranging from magically disappearing APs to not getting an IP from DHCP hosted in the NodeMCU, eventually we concluded that the device is just not powerful enough to Act as an AP, Serve Web pages, do DHCP leases, authenticate the user and run a servo motor.
Eventually Vinayan came up with the idea, to serve the page in the KeK local WiFi where NodeMCU will be just another device with an IP, he wrote up a simple sketch in Arduino IDE that would authenticate an User using a webpage and open the lock. And that one worked like a charm.
We had thought about this idea, but one of the small issues with this approach is if a power outage also cuts power to the Router then the lock is inaccesible from the outside. One way to overcome this is to have a 9V back up power on the electronic lock system along with a bluetooth module, that can accept serial inputs to which the passcode can be given by a smart phone or a computer, we did not get time to try this out but we are confident it can be made to work. The only downside is the user may need to download an additional application on their phone to communicate with the electronic lock.
In addition to this, we also thought about implementing a microSD reader, so that the system configuration can be loaded dynamically on bootup. Things like passcode, open to close duration etc can be stored in a simple text file in the SD Card. The SD Card also can act as a log to show at what times of the day the door was opened and closed and by which device, so that one can track the activity if needed.
This is how the final setup looks like

Here is a list of TODO for the system, which would make the system nice and practical.
1. In case of complete power failure, Develop a failsafe mechanism for the lock.
2. Implement a push-button to open the lock from inside.
3. Relevant data logging mechanisms.
4. Cleaner and sassy looking web interface.
5. Bluetooth keypad (via phone) as a failsafe mechanism.
6. Design the layout in Fritzing or some other equivalent PCB layout software.
7. Buzzer to indicate success when opening / closing the door.
8. A Door state detector to see if the Door is currently open or closed. The knob need to move into the locked position only if the Door is closed.
9. A Frame to mount the Servo Motor, this would be a nice addition instead of duct taping the motor on to the lock.
Here is a small video of what we implemented.