Sunday, November 15, 2009

Dorm Room Door Cardswipe Unlocker

When I was a Sophomore, I was living in Purdue's Cary Quadrangle dorm, and decided that my door was far too low-tech and needed sprucing up. What I decided on, was making my door automatically unlock somehow. Since I was not able to modify the physical door in any way, I had to find a way to have it do so without changing the doorjam, installing anything permanently or impeding the normal function of the door (for safety regulations).
For the method of opening the door I had to have something that was nondescript enough that it wouldn't be stolen or broken, but also wasn't something that could easily be hacked, because that would defeat the purpose of locking the door in the first place. After doing some research on what would fit within my limited budget, I found a used magnetic stripe reader on ebay for $15 that interfaced with a standard keyboard port. This was doubly nice, because it would allow me to use a standard Purdue ID card as the key, and others could be entered with just their Purdue ID number, which was coded onto the card.
Having come up with a solution for getting input, I could then move on to how I would unlock the door itself once a person was confirmed. This was an issue that stumped me for quite a while, because of the constraints of not modifying the door impeding door functionality. What I eventually came up with was a motor that ran off of 9v and ran through a massive gearing-down that pulled down a rope, which pulled down the handle, which unlocked the door (the first image below). I was really lucky with the type of door handle that we had, because it only was openable from the inside by pulling down, and pulling down on the locked door unlocked it. As a result, the rope that attached to the motor just went slack when it was opened normally, and it just had to pull the handle to unlock the door.
The second image below shows the circuitry that controlled the motor, which turned out to be a lot more complex than you might think. To interface with the computer, I found a class that allowed extremely easy control of the parallel port. The result of this, was that I had 8 pins that I could easily turn on or off, and would provide ~1.5v to the active pins. I found solid state relays that were perfect for this purpose. SS relays are basically electronic switches that connect 2 pins when a small voltage is applied to the other 2. While this was good for activating the motor, I also needed a way to be able to reverse the motor, and for that I needed a mechanical relay. For that I had a SS relay that was activated from the parallel port activate a mechanical relay to reverse the motor's direction (to let the handle back up). Finally, I found that some of the time, the motor would keep running, because there was a trickle of power running through that kept the circuits closed, so I added an additional set of relays that disconnected the power supplied (9v for motor and 12v for relays) from mains power.
This box I kept in a drawer with the computer that controlled the door, and it had a long keyboard cable running to the card reader, 2 wires running to the motor on the door, and mains power.
Once I had all the mechanical parts finished, I needed the code to run all of it. I had the parallel port class that allowed me to control physical things from code, so that part was easy(once I found that). The computer that this app was running on was an old laptop with no screen that would be sitting in a drawer accessed via remote desktop, and I wanted an easy way to modify the user control list. For this, I had the program copy an access control file from a network drive every hour that contained Purdue IDs and names so that it could be logged back to the server in case something went missing. For getting the data from the card reader, the reader sent a specific series of characters and emulated keystrokes whenever it read a card, so I made a service that listened for that series of keystrokes, parsed the ID from it, and acted accordingly.
As an interesting sidenote, I recently found out that my card reader has become somewhat of legend in Cary, and people are still talking about it 2 years later. Awesome.
This was the version that I had in the dorms, and once I moved to a house where I could modify things, I made version 2, which I will go over in my next post. Let me know if you have any questions!



1 comment:

  1. Dan, this is amazing! I love it! If I knew what half of this computer lingo meant, I would try it myself!!!

    Also, I think that you spent more time making and planning the system than you would spend fiddling with keys!

    See you around Bay for winter break!
    -Teddy

    ReplyDelete