Saturday, March 09, 2013

Electronic Doorknob Combo Lock

Turned a doorknob into an electric combination lock (Turning the doorknob inputs numbers)

Overview

Turned a doorknob into an electronic combination lock. Turn the doorknob and it changes values on display, once the proper combo is input it will trigger a solenoid to release the lock.

Electronics

Cost under $10 with part of a bigger order. The most expensive part was the EM relay.
  • Cheap Trimpot, ohm rating doesn't matter as long as it goes from zero resistance to pretty much a short. Make sure the knob is secure, since it will eventually be taking alot of stress
  • LM7805 -- Linear regulator
  • Power supply for the microcontroller, needs to have around 300 mA of current.
  • Power supply for solenoid, needs about an amp of current and roughly 18V give or take
  • Pull type solenoid
  • 47 uF electrolytic capacitor, to clean up the power signal
  • Dual seven segment display
  • NPN Transistor
  • Electromagnetic Relay
  • Crystal Oscillator(I used 10 MHZ, but it doesn't matter)
  • PIC18F4520, could be any PIC with enough IO, this is just what I started with.
Below is a basic schematic. The PIC and pins differ some from the code, just because the schematic program I used didn't have the PIC4520:



The circuit was quite easy, although I did have to plus up my microcontroller power supply with a 9V, to get enough current to drive the relay(I originally had a smaller display that broke, and adding the larger one sucked just enough amps to stop the relay from reliably switching). The software is a simple analog to digital conversion, then chop off all but the upper bits to get the proper hex value. It uses a separate thread to monitor how long the number was held for.

One issue that took me forever to debug is the conversion takes several cycles and the number you are storing to has no definite value at that time. Meaning if another thread interrupts in the middle and tries to read that value it will get garbage. This is easily mitigated with a temporary variable being used during the conversion.

Soldering it up was hassle free, although I had a lot of wires that were required. 2 Power supplies to the control box, then 4 wires of power to the solenoid and microcontroller, 9 wires from the microcontoller to the control box for the display, and then a phone cord was used to hook up the trim pot to the microcontroller. If I had been willing to, it would have been *much* nicer to have embedded everything into the door, control box and all, so there were only the power wires.

Picture of the terrible spaghetti wiring:



The basic electronics working:

 

Source Code

https://github.com/plurSKI/comboLock

 

Hardware

  1. Mostly the same as the wireless lock, except the additional usage of a trimpot
  2. The door handle was modified, since it only allowed 90 degrees of freedom, and a standard trim pot is just shy of a full 180. I ended up bending anything that hits the side upwards till it didn't hit. Pic below:

  3. Cut a dowel to the proper length. Enough to mount the trimpot inside the metal and then have it be snug against the wheel of the potentiometer. There is a picture further down when I discuss gluing that shows this better. Below is a picture of the dowel in the door(I was dumb and had to shape a circular one to work), it's sticking out a little just so I could feel how tight it was in the handle:

  4. The most difficult part was getting the dowel to fit into the trim pot. The potentiometer I used had a straight slit for a flat tip screwdriver so I had to carve something roughly resembling a flat tip head on the dowel. I used a Dremel sanding tool to to this, and it worked reasonably well.
  5. Glued the dowel onto the trimpot, ended up taking off the door handle assembly entirely to get it straight. I originally tried epoxy but it didn't stick to the trimpot plastic so I went with hot glue which worked pretty well. Picture of it 'clamped' up below:

  6. Soldered up wiring to the trim pot since it would be difficult to get at later.
  7. Finally put it all back on the door.  I had to take out the door's latch since it also hinders rotation.

 

Conclusion

Here's a video of it in operation:


It worked well, but the trim pot embedded in the knob ended up breaking free after a while, and I didn't bother to fix it since this whole project was for practice.  If I was going to try to make a longer term one I'd have used a metal potentiometer, metal rod, and epoxied the whole mess together. 

No comments: