RFID DOOR LOCK - ARDUINO
Intro: RFID DOOR LOCK - ARDUINO
This is a fun an very useful project that allows easy access into any door with a deadbolt. I have another version that is used on my garage door and uses the same basic circuit and fobs. The system operates in the RF region at 125 KHz. Fobs are used to actuate one of two relays on the main control board. With each scan the deadbolt toggles - if it is unlocked it locks and the red LED comes on, if locked it unlocks and the green LED comes on. One relay causes the deadbolt motor / mechanism to lock the door, the other causes the door to unlock. A regular key can still be used and the deadbolt can still be locked and unlocked manually if desired. Operating the circuit with the key or manually operating it with the deadbolt knob can cause it to fall out of sync with the controller and indicate locked when it is actually unlocked or vice versa. To correct this just cycle the unit with the pushbutton on the deadbolt housing or flip the deadbolt knob the opposite way. I have thought about adding some limit switches to eliminate this problem. Perhaps in some future version I will implement them. I have been using this project for a couple of months with very few hiccups. It is fun to build and adds a definite 'nerdivity' to my home.
I based the project on a store-bought electronic deadbolt. It was battery operated and had a keypad on the outside to allow entry with a user defined code. I removed all of the electronics from the indoor housing keeping only the electric motor and mechanism. The mechanism has a built-in clutch that prevents damage should the motor remain on for too long when cycling. My motor is set for a cycle time of about 1.25 seconds.
This project is based on the Kwikset Powerbolt Model # 907 15 SMT CP. It cost $69.97 at Home Depot. Almost any battery operated deadbolt will work. It needs some type of clutch mechanism to protect from over-cycling. This was the cheapest unit that Home Depot sold. You may get lucky and find an open box item or a defective unit that can be salvaged. It looks neater than trying to build the motor drive myself.
In future versions I will try to place all components inside the plastic housing where the OEM circuit board was located. There are many similar projects you can research on the Internet. Do a search for 'RFID ARDUINO DEADBOLT'. There a few on Instructables as well. A Universal RFID Key by drj113 available in Instructables is a good read on RFID theory. Going over this material will be time well spent.
STEP 1: Operation
Here is an example of the device in operation. It is a bit noisy as the gears grind inside. It is virtually impossible to lock yourself out of the house using one of these. I had done this one too many times with my door key, so I disabled the locking mechanism of every door knob lock in my home. I only use deadbolts for locking doors now and am happy to report I have never locked myself out since.
STEP 2: The FOBS
Here is a picture of the FOBs used in this project. They are fully encased and are almost indestructible. A look inside shows a coil and microchip. There are two form factors that can operate the device, a FOB or a card. I keep the card version in my wallet and a FOB on my key chain. I just take my wallet an wave it over the reader and it unlocks. I use the same card / FOB to access my garage and my house. There will be more about this in the Arduino sketch section later. Power and data are delivered and retrieved via the antenna coil. There are no batteries inside to ever fail. This version contains an identification number and is read only. Other types are available that can have information stored on them. That would require a different reader than the one used here. I have yet to experiment with the read / write type. This technology is finding it's way into our everyday lives at breakneck speed.
STEP 3: Prototyping and Breadboarding
This is the experimental version of this project. The microcontroller is an ATMEGA 328 loaded with a program called a bootloader. It is the bootloader that makes it an Arduino. It took some time to work out the kinks, but I enjoyed learning along the way. This version has an LCD display that when scanned shows the name associated with the FOB. It also shows fault messages like 'FOB Not Recognized' and 'Welcome Home Bill'. I thought adding a ladies voice to it might be cool. I will wait to add that to a doorbell project that I am pondering.
STEP 4: Sub Assemblies
A quick shot of the subassemblies needed to build the project. Don't let the complexity scare you away. Build and test each piece one at a time. You may want to stop along the way and experiment. If you are new to Arduino there vast amounts of tutorials available online. The best one is the official Arduino website at http://www.arduino.cc/. Breadboarding the unit first can be helpful in working out the bugs.
STEP 5: Circuit Boards and Major Components
I built two boards for this project. One has the Arduino microcontroller on with all input / output connectors attached. The Adruino is in a socket mounted on a breakout style board called RBBB from ModernDevice.com. It allows the resonator, voltage regulator, reset switch, power jack and power conditioning in one convenient place. Power for the entire project is fed into this board from a wall-wart (9VDC @ 1A) AC adapter. Power before the 7805 regulator is taken to run the motor. Power after the 7805 regulator and filtering is used to power everything else. Note the blue shrink wrap on the 7805. This was removed after testing and a small heat sink added in it's place. I have about 20 of these RBBB boards in my lab and this one was changed out sometime during construction.
The RFID reader itself is located on the small green circuit board on the lower left end of the controller board. It comes with a rectangular coil of wire which is the antenna. I housed it inside a plastic project box. You can read details about it's construction below. Be sure the use the UART type and not the WEIGAND. Only the UART will work with the code I have written for this project.
I like to use pre-made jumpers in my projects. They are very cheap and allow quick connect / disconnect during construction and debugging. The Arduino RBBB board above uses these and it makes for efficient work.
STEP 6: Parts Layout - Control Board
The main board is located inside a beige box labeled CPU / INTERFACE MODULE. I could not think of a better name so I'll stick with this for now. Anybody have any ideas? When I refer to the main board I am speaking of the large perf board. There is also an Arduino board that I have been calling RBBB. This is what the manufacturer calls it. Both boards are located in the hinged box hanging to the left of the deadbolt enclosure.
STEP 7: Schematics
The red circled numbers denote Arduino pin numbers. If you like, you can build the entire project on one piece of perfboard or create a PC board layout. When communicating with the Arduino chip you must unplug the connector labeled RX. You will get a fault from the Arduino software if you leave this wire connected while attempting to communicate. This pin is one of two that are used to send serial data to and from the RFID reader board to the Arduino. In normal operation this pin must be connected. I have placed a male pin on the circuit board with a female connector going to the RX pin on the Arduino circuit board. This pin is labled TX on the green RFID board and is connected to RX on the Arduino board. Simply unplug it, upload your sketch, plug it back in and all should be well.
The motor is wired using two single pole double throw relays. In the normally closed position both relays connect both motor terminals to - causing no movement. If relay A is energized and relay B is not then motor pin A will be connected to + and pin B will be connected to - causing the motor to spin. If this condition is reversed and relay A is not energized and relay B is energized then motor pin A is connected to - and motor pin B is connected to + causing the motor to spin in the opposite direction. In the unlikely event that both relays are energized then both motor pins will be connected to + causing no movement of the motor. When you are done assembling the project and you find the motor works backwards from your expectations, just reverse the polarity to the motor. If you have a connector like I had on mine just unplug it and plug it back in the other way around.
I received some great advice from fellow builder steveastrouk concerning motor noise. He recommends adding a bridge rectifier and 100 nF cap to guard against excess motor noise. I believe mine came from the factory with a cap across the motor leads but when I desoldered everything to add the wire cables, I forgot to replace it. Soon I will add a modified schematic to reflect the changes he recommends. The schematic shows a 100nF cap across the motor leads, but the cap is located on the main control board. It should be directly accross the motor leads.
STEP 8: Control Board Assembly
Notice the red and black dots on back of the board. They indicate positive and negative power supply rails. It is very easy to get them mixed up during assembly. The relays, RFID receiver board, LEDs and miscellaneous connectors are all mounted on this board. You can use whatever construction method your imagination can come up with. Creating a universal PC board with all major parts on it might be an efficient approach if you are planning to build more than one. Wiring is not critical since only control signals are being used. The antenna coil is the only exception as it sends both power and data to and from the RFID board. My antenna coil is mounted about 14 inches away from the RFID board and has proven to be quite reliable.
STEP 9: More Power to You
During tryout I found the motor would strain to cycle and the Arduino would sometimes restart. The problem was the power supply rail being pulled well below 5 volts. The fix was adding a 6800uF 25V electrolytic capacitor to stabilize the power rail thus allowing the motor the extra power needed to cycle the deadbolt.
Electric motors draw maximum current during startup, then draw less as they come up to running speed due to back EMF. Back EMF (Electromotive Force) is created because a motor acts like a generator when it is running. The generated current flows opposite to the current powering the motor. When the motor first starts there is very low rpm and very low back EMF. This is what causes the motor to draw maximum current during startup. As motor speed increases so does back EMF and the current needed to run the motor goes down.
STEP 10: Main Control Enclosure (AKA CPU / INTERFACE MODULE)
Here are some pictures of the main enclosure. I added hinges to the left side and salvaged a knob and screw from an old lamp to keep it closed. The wiring could have been a little neater. There is no convenient way to resize the jumper extensions.
STEP 11: Indoor Deadboalt Case
In the first picture at the top of this instructable there is a red push button where a hole is present in the unaltered deadbolt cover. Drill this out and install a normally open push button switch there. Be sure to put long enough wires to reach the control board. Notice the missing capacitor across the motor leads in rightmost picture.
STEP 12: Outside Antenna / LEDs
Here you can see how I built the receiver box. I used the top of an old project box. Packaging tape was used to stick the antenna coil to the inside but it kept peeling off. I added some foam I had laying around to back it up. Just before screwing the box to the door I slipped enough foam behind the antenna to firmly hold it in place. Clear label tape gives a professional appearance that looks neat and clean. One hole was drilled through the door coming out in an open area of the deadbolt knob mounting plate. The wires were fed through this hole and then through some split loom wire raceway. The split loom is the black corrugated plastic tubing joining the deadbolt box to the control box which I labeled the CPU / INTERFACE MODULE. It was the best name I could come up with, Warp Reactor coil just didn't sound right. Flux Capacitor might have worked!
In my version, the receiver is not exposed to the elements since it is located inside a garage. If your version is outdoors I recommend caulking around the box after working out all of the bugs. This will also help to keep the real bugs out! Some small critters would likely find this a great place to set up a home with the groovy lights and everything, like a miniature bug-disco!
STEP 13: Arduino Sketch Details
- Download the Arduino programming software.
- This can be downloaded free from the Arduino website: http://arduino.cc/en/Main/Software
- Download and open the .txt file in word or some other generic program that can display text files.
- Copy and paste the text of this file into the Arduino programming software.
- Connect the Arduino board (RBBB) to your computer using USB to serial cable.
- Disconnect the RFID reader board at the TX terminal or a fault will be generated and the upload will fail! (I forget to do this every time!)
- Upload the sketch into the Arduino chip.
- Under the tools menu, open the Serial Monitor and check that the .com port being monitored is the same one you just used to upload the Arduino sketch.
- Wave a compatible FOB or card over the antenna coil. You should see numbers displayed.
- These numbers should be unique for each FOB you wave over the antenna coil.
- Cut and paste these numbers into the top of the Arduino sketch.
- The numbers are located at the beginning of the sketch and are located under the heading 'SETUP VALID BADGES'.
Upload the sketch into the Arduino again.
- Plug the TX connector back in or there will be no communication between the RFID board and the Arduino and it will be unresponsive.
- Wave the card or FOB and the motor should cycle and LEDs change state indicating a successful scan. If the number in the FOB matches one in the table the deadbolt should cycle to the opposite state that is in. If the deadbolt is locked, it will unlock. If it is unlocked, it will lock.
- Edit the sketch as desired to help you keep track of your cards and or FOBs.
- I find it works best to wave the FOB about an inch away from the antenna coil and use a smooth even motion. Do not wave it back and fourth or the unit will click on and off over and over.
STEP 14: Construction Tips and Final Thoughts
- Build the project on an experimenters socket first.
- Using the RBBB PC board for the Arduino makes is more convienent, but it is not necessary. If you prefer you can install the Arduino chip directly on to whatever type of board you are using. If you choose this method you will have to install the resonator or crystal, 7805 regulator and other components on the board as well.
- I use a 9 volt ac adapter to power the unit. If power fails, the key will always work.
- This could be operated from batteries but the current draw would cause them to need frequent replacement.
- Clear labels were printed with a Brother label printer. I used the computer software from the Brother website to create all of the labels.
- Be creative and play with the program. Let me know of any improvements you may suggest.
- If there is something I can help clarify let me know.
- I mentioned earlier I have a version of this for my garage door. It has been working for about two years now with very few problems. I plan on posting an instructable for that project in the near future.
- Some great ideas about dealing with potential electrical noise problems were posted by steveastrouk. Read through the comments below and the schematic section for more information.
26 Comments
rjkorn 10 years ago
Nice Job.
I made something similar for my garage but i used an old fashioned electrified strike for the door lock and commercial waterproof 125khz reader.
i used eeprom to store the valid cards. now i want to make a menu to allow card updates remotely. I started on a serial menu but using a full size arduino with ethernet or wifi sheild would be nice
jeepdude48507 9 years ago
When you strip off all the extra stuff, you can build an Arduino circuit using just the Atmel 328-PU and a resonator (or crystal and 2 capacitors). All that extra stuff on the Arduino Uno, Leonardo and others make a project more expensive and bulky. I typically use the RBBB (Really Bare Bones Board) from Modern Device. They are compact and nice to work with.
rjkorn 10 years ago
Nice Job.
I made something similar for my garage but i used an old fashioned electrified strike for the door lock and commercial waterproof 125khz reader.
i used eeprom to store the valid cards. now i want to make a menu to allow card updates remotely. I started on a serial menu but using a full size arduino with ethernet or wifi sheild would be nice
jeepdude48507 10 years ago
What type of reader did you use. Are there any pictures of it posted? I would love to see a picture of it.
rjkorn 10 years ago
I want to post it this weekend ill have plenty of pics by then
I used the cheapest readers I could find on ebay....
like these....
http://www.ebay.com/itm/1Pcs-New-Waterproof-Security-Door-Black-ID-Wiegand-26-RFID-Card-Reader-125KHz-/281345619308?pt=LH_DefaultDomain_0&hash=item418181756c
jeepdude48507 9 years ago
I found the Wiegand protocol a little to difficult to decode with my limited Arduino knowledge. The UART type allows the straight forward use of Arduino's serial functions. I could never get a Wiegand reader to work.
jeepdude48507 9 years ago
I used the RDM630. If you do an EBAY search for "rfid reader 630" you should see a bunch of them. Be sure to buy the UART type. There different serial protocols used by various RFID readers. The ones I just looked at on EBAY today (September 30, 2015) sold for $6.43 (US$). You may get a better deal if you buy more than one. Sorry it took me a year to get back to you. I have had some health problems. The Lord delivered me! If you look closely at the pictures the reader is the rectangular green circuit board mounted on the main board. I have read the RDM6300 is supposed to be backward compatible with the RDM630. Look for the 125Khz EM4100 type.
steveastrouk 10 years ago
You might also find it helpful, for noise suppression, to put a 100n cap and an 100 ohm resistor in series, across the motor. Also, diodes on the motor wires will help stop nasties. Put the cathodes towards the +ve supply.
jeepdude48507 10 years ago
The schematic shows a 100n cap across the motor terminals, but I left it off when I soldered the jumper wires. Next time I have it apart I will add one. I am sure there was one installed before I modified. I didn't follow the diodes you mentioned. Could you expand on the idea some more?
steveastrouk 10 years ago
If you look at this circuit I did a long time back, you can perhaps see how I did it.
jeepdude48507 10 years ago
I have never seen this circuit before now. It looks like when the motor is running, B+ would be routed to +12 so no current would flow. The negative side would be routed to common with no current flowing. The same thing would happen when the motor is reversed. You mentioned this helps to reduce noise? Is there a common name for this configuration? It looks quite interesting and I would like to learn more. Anything else you may have about this or other comments are welcome. Thanks for the heads up.
steveastrouk 10 years ago
The point of this is the condition when the motor is STOPPING. Very large voltages are generated at the terminals of the motor as it stops, THEN the diodes conduct and allow the energy to flow in a loop around the motor - keep the wires short.
These are called flywheel diodes. The RC combo is called either a suppressor or a snubber.
jeepdude48507 10 years ago
Much like when a relay coil generates a counter EMF when the power is opened. A diode is inserted across the relay coil that bleeds unwanted induced currents from destroying the transistor. In the future I will use this idea. I have seen and used snubbers at work on most relays and motor starters. They come in a single package made by the manufacturer that fit across the coil terminals. Thanks for your input.
steveastrouk 10 years ago
The trick is the diodes on a bridge. You can't put the diodes across the motor, because for some directions of the motor, they are forward biased. This is the fix.
jeepdude48507 10 years ago
I think I got it. Diodes across the motor terminals would be a bad thing. The diodes in the bridge are reverse biased for motor current and forward biased for back EMF. I understand that they must be in a bridge configuration with the AC (~) terminals connected to the motor leads. Connecting a single diode across a DC motor would be bad mojo.
steveastrouk 10 years ago
See if this is clearer - you get the 4 diodes you need in a bridge rectifier you can "steal" from a dead PC power supply
2n2222 10 years ago
I would like to follow your sketch, but I get an error see
below:
RFID_DEADBOLT_125KHz.ino:70: error: 'Toggle' was not
declared in this scope
I have always wanted to do this; Last week I ordered RFID
reader/writer form parallax. I hope ti will work with your wonderful system.
Thanks
jeepdude48507 10 years ago
Your right! Thank you for bringing this to my attention. It seems the text portion of instructables is limited. It cut off a large part of my sketch. I am not sure how to attach a file to an instructable yet. If anyone knows please drop me a line. In the mean time if you want to email me at jeepdude48507@yahoo.com I will send you the file. I rarely use this email address as it is my 'junk email' account. I will check it and send the sketch to anyone who wants it until such time as I learn how to attach a file to an instructable..
horphmyre 10 years ago
I don't know how many times I've pointed my vehicle remote at my front door, expecting it to unlock. Nice to see one that works.
zx lee 10 years ago
You have a neat stripboard layout. What is the tools you used to design the stripboard and the schematic?