Arduino RFID Door Lock
Arduino RFID Door Lock
Table of Contents
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Step 4: Program! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Step 5: Expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Author:pcmofo author's website
I like to take things apart, sometimes they go back together sometimes they end up as something entirely different then where they started.
I wanted to make an easy and secure way to enter my garage. RFID was the best way to unlock my door, even with my hands full I can unlock the door and push it open!
I built a simple circuit with a basic ATMega 168 arduino chip and a ID-20 RFID reader to control an electronic door lock.
The circuit consists of 3 separate parts, a Reader to read RFID tags, a Controller to accept data from the reader and control the output of the RGB LED and the Electric
door lock. The door lock is first installed in a door and tested with a 9v battery to ensure correct installation. In most cases you want a Normally Open circuit on the door
lock, or Fail Secure. This means the door stays locked when no current passes through it. When 12vDC is passed through the electromagnet in the door lock, a plate in
the lock gives way and allows the door to be pushed open freely.
The reader is placed on the outside of the door and is separate from the controller on the inside so that no one can circumvent the security by breaking open the Reader
and trying to short circuit the reader. The controller receives serial data from the Reader and controls the RGB led and the Door lock. In this case I have put both on
separate bread boards for testing. Here is a video overview of the system in action Read on to see how to build one for your self!
**Update**
All of the code, schematics, and PCB designs have been tested and refined. They are all posted here as of 8/9/2010
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Image Notes
1. Reader portion of the circuit
2. Controller portion of circuit
3. RFID keychain tag
4. RFID card tag
5. Master programming card
6. 12vDC connection to Door Lock
7. 12vDC power input
Image Notes
1. Reader mounted outside door, RGB LED is blue showing its on and ready.
Image Notes
1. 12v DC power
2. 12v output to door lock
3. TIP31A transistor to trigger door lock
4. Reset button for micro controller
5. Power on LED
6. Programing Header
7. ATMega168
8. 6 pin header going to reader
9. Jumper to switch between programing and reading serial data from the
RFID module
Image Notes
1. 6 Pin header to Controller
2. 2N2222 transistor for buzzer
3. Resistors for Buzzer
4. ID-12 RFID reader glued to front inside of project box
5. Spark Fun break out board
6. Jumper wires used to mount RFID reader 90deg away from the main board.
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Can also be mounted on the PCB without the SF break out board shown (green)
7. RGB LED with hole cut in front
8. PCB cut to slot into groves on project box
Arduino Stuff
RFID stuff
Other
Image Notes
1. Reader portion of the circuit
2. Controller portion of circuit
3. RFID keychain tag
4. RFID card tag
5. Master programming card
6. 12vDC connection to Door Lock
7. 12vDC power input
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Step 2: Build the Arduino controller
The first step to building a RFID door lock with a basic Arduino is to bread board out a basic working arduino. Most Arduino pre-flashed ATMega 168 chips come with the
default blink program pre installed. Connect a LED to digital output 13 and verify that everything is working.
The hardware portion of this RFID reader would be too simple if we used a regular arduino with built in USB programmer. Since I plan on putting this into the wall and not
touching it again I dont want to use a big bulky $30 arduino board when I can buy a $5 ATMega 168 and make a much smaller custom PCB.
Because I chose to make a basic Arduino circuit myself I need an external USB->Serial FDIT programmer. I have included Eagle schematics of the controller with a
power supply built from a 7805 voltage regulator. In testing I used a bread board power supply.
To get an arduino up and running all you really need is the ATMega168 with the arduino software flashed on it, 2x 22pF capacitors, 16mhz crystal, 10k ohm resistor, push
button and a breadboard. The hookup for this is well known but I have included the entire schematic for the circuit.
The arduino is going to trigger 4 outputs, 1 each for Red/Green/Blue LEDs, and 1 to trigger the TIP31A to send 12vDC to the door lock. The arduino receives serial data
in on its Rx line from the ID-20 RFID reader.
Image Notes
1. Breadboard Powersupply
2. TIP31A Transistor
3. ATMega168 Arduino
4. Reset Button
5. 16mhz Crystal
6. 10ohm Resistor Image Notes
7. 22pF Capacitors 1. TIP31A Transistor
8. Connection to Door Lock 2. ATMega168 Arduino
9. RGB outputs to reader 3. Reset Button
10. Serial input to arduino 4. 10k ohm Resistor (for reset)
11. 5v/ground to reader 5. 16mhz Crystal
12. Serial input 6. 22pF capacitors
7. Serial Data in from ID-20
8. Output to open door lock via TIP31A
9. RGB LED outputs
Image Notes
1. Breadboard Powersupply
2. 12vDC
3. 12vDC to door lock
4. Ground output from TIP31A
5. 12vDC from power supply
6. RGB LED outputs
7. Serial data input
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
8. Serial input to arduino
9. RGB outputs from arduino
File Downloads
To build this, we are going to send 5v/Ground over from the primary bread board to a secondary bread board we are building the Reader on. Also send over 3 wires from
3 of the arduino output pins to control the RGB LED, one for each color. One more wire, Brown in the pictures, will be a serial connection for the ID-20 to talk to the
arduino's Rx serial input. This is a very simple circuit to connect. LED's get resistors and a few points on the ID-20 are tied to ground/5v to set the correct status.
To make it easier to breadboard the ID-10/ID-20 Sparkfun sells a Breakout board that allows you to attach longer pin headers that are spaced to fit a bread board. This
part and the pinheaders and listed in the parts list.
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Image Notes
1. ID-20 reader, (ID-10 is smaller). Soldered to the Sparkfun break out board and
pin headers. It allows me to Plug it into the bread board easily.
2. RGB LED
3. Resistors for LEDs
4. RGB LED wires connected to Arduino output pins, Guess which one is which??
5. Serial out of ID-20 and into arduino Rx
6. Optional Resistor/transistor that I was playing with to connect a buzzer
7. Serial coming out of ID-20, hidden under the chip
8. 5v/Ground to power the reader from the main Controller power supply
9. Common ground for the RGB LED
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
File Downloads
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Step 4: Program!
Time to program your arduino. This can be a bit tricky using a basic arduino, you may have to press the reset button multiple times before and during the first part of the
upload. A very important thing to remember, you WILL get an upload error if you do no temporarily disconnect the ID-20 serial line to the arduino's Rx line. The
ATMega168 only has 1 Rx input and it uses it to upload code to talk to the programmer. Disconnect the ID-20 while programming then plug it back in when your done.
I used a FTDI programmer which allows you to program the arduino via USB with only 4 wires. The Controller schematic shows a pin header connection to allow you to
plug one in directly. Sparkfun also sells this part but many may already have it.
You can easily upload my code to your arduino and never look back but whats the fun in that? Let me explain the basic idea of how it works.
First of all, I did not want any external buttons/switches/etc and I did not want to reprogram the arduino every time I wanted to add a new card. Therefore I wanted to use
only RFID to control the operation of the circuit as well as control over the door lock.
The program turns on the Blue LED to indicate it is ready to read a new card. When the card is read it decides if it is a valid card or not by comparing what it read in to a
list of valid cards. If the user is valid, the arduino turns OFF the Blue LED and turns on the Green LED for 5 seconds. It also turns on another output high for 5 seconds.
This output is connected to the TIP31A transistor and allows the tiny arduino to control a much larger 12v 300mA door lock without being damaged. After 5 seconds the
door lock re-locks and the LED turns back to blue to wait for another card to be read. If the card is invalid then the LED changes to RED for a few seconds and back to
Blue to wait for another card.
It is important that the door lock still work even if the arduino loses power overnight or is reset. Therefore all valid card ID's are stored in EEPROM memory. The
ATMega168 has 512 Bytes of EEPROM memory. Each RFID card has a 5 Hex Byte serial number and a 1 Hex Byte Check sum that we can use to verify there were no
errors in the transmission between the ID-20 and the arduino.
Valid cards are stored in the EEPROM by using the first Byte as a counter. For example, if there are 3 valid cards stored the first Byte in the EEPROM would be 3.
EEPROM.read(0); = 3. Knowing this, and the fact that each ID is 5 Bytes long we know that 1-5 is card one, 6-10 is card 2 and 11-15 is card 3. We can make a loop that
looks through the EEPROM 5 bytes at a time and tries to find the card that was read in by the reader.
But how can we add new cards to the EEPROM after the circuit is installed?? I have read in one of the RFID cards I have and hard coded it to be the Master RFID card.
So even if the entire EEPROM is wiped the master card will still function. Whenever a card is read, it checks first to see if it is the Master card, if not, then it continues to
see if it is a valid card or not. If the card is the master card we have the arduino go into a "programming mode" where it flashes RGB and waits for another valid tag to be
read. The next tag that is read is added to the next free spot in the EEPROM and the counter is incremented 1 if the card does not already exist in the EEPROM memory.
The reader then returns to normal mode and waits for a new card to be read.
Currently I have not programmed a way to delete a card as the reasons for deleting a card would most likely be it was lost or stolen. As this would most likely be used
with 1-10 people the easiest thing to do would be to hard program a Master Erase card that will wipe all cards from the EEPROM then re add them all, which only takes a
few seconds. I have added code to wipe the EEPROM but I have not implemented this feature yet. .
The code is attached in a text file along with a copy of the parts list.
File Downloads
Related Instructables
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Comments
50 comments Add Comment view all 224 comments
If there is anyone who decides to do anything else with this code I would really love to see it or even help you test it.
The vid link doesnt show up as a reply. I'll make another post with it.
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
pcmofo says: May 31, 2010. 7:04 AM REPLY
Wow, I am impressed. You did a really nice job of throwing that together without using a PCB. I like the eraser card code as well. I cant wait to
get mine up and running as well. I hope you had fun building this. It looks like it turned out really nice.
The "outside board" with the rfid reader... I enclosed it in a water proof box, but I also took the time to "paint" all the connection with "Liquid
Electrical tape" to help water/moisture proof the whole thing.
Like I had said before if anyone had an additions to the code or design, I would love to see it. Maybe even impliment some of it.
I designed the circuit diagram so you can still connect a programmer and reprogram it. I really like the idea of a master erase card. One
idea I thought of is to have a "programming" master card... then a function card, like... "Add" "Erase" "Erase All" etc. which would allow
more customized programming. I'm thinking stuff like one-time-access, access at a specific time of day or span of days.... say someone is
coming to do electrical work.. they can go in and out all day but the card wont work the next day etc....
Also planning on using a networked RFID system to track and identify customers/beers we are brewing in the brewery.... so planning on
using the same readers and tags for everything.... such that anyone carrying a empty keg into the brewery gets access via the keg
because clearly they are helping carry heavy things and dont have time to mess with keys.... or the same tag for a friend may allow them
to pour as much beer as they want and pay later but not access into the brewery unless I authorize it etc....
So basically I have lots of plans for RFID and this door reader is only the beginning.
Working on an arduino remote car starter next... may or may not have RFID... but I expect to be playing around with both sets of code
regardless soon.
Please let me know as you make any new code. I would love you review it and possibly even help test it.
and is it waterproof?
sorry for my very very bad english, i am only 14 years old -.-'
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
Jessecar96 says: Jun 26, 2010. 8:14 AM REPLY
The code comes up with an error for me: In function 'void setup()': error: redefinition of 'void setup()' In function 'void loop()': what do i do?
My project is a complete project, ie, you follow the instructions and you can achieve the same result. If you deviate from those instructions you are on
your own to some degree. This project is very simple in terms of what you need to understand to make it work. If you can build a circuit on a bread board,
and read the first 10 or so lines of code that explains the pinout, then you can make my project work for you.
Good Luck.
Also would it be possible to modify this to allow the controller to use more then 1 RFID reader and door lock? So the board could control 2 or 3 readers and
locks?
In my garage I have a utility room where I keep some high priced electronics and networking stuff and I would like to put a lock and reader on this door
aswell as a lock and reader into the entrance to my house from the garage. Maybe a third would be a stretch, but if there was a reader with a long enough
range maybe it could read an RFID card mounted on the windshield of my car and open my garage door. (They do this at the parking garage where I work,
it's pretty cool)
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
joshnosh says: Jan 26, 2011. 8:23 AM REPLY
well im sorry for being dyslexic
i already searched for "ftdi programmer"
and i was flooded with information but not much off it was relevant
im going to buy a audrino board with removable chip and use the board to program it
thanks anyway!
Thanks
Robb
Great project!
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
brent_750 says: Nov 7, 2010. 1:41 AM REPLY
Hello, I wanted to tell you how much I enjoyed your instructable over the RFID door lock. I ordered the parts and am a little worried though about not knowing
how to hook it up. I am a computer science major but have always programmed and have never actually assembled electronics.
One idea that I was had for it was to give the Arduino the ability to connect to wireless network in my house so it could access the internet and from there
allow it to somehow host it's own webpage or gather it's settings (such as valid RFIDs) from an external webpage that way RFIDs can be added/removed or
enabled/disabled from an external site. Like I said I know nothing about electronics but from what I had been reading I was thinking that this may be possible
using an Arduino WiShield 2.0. I didn't know how one would go about hooking that into your PCB though.
Another though I was having was that it would be nice to be able to set up a schedule allowing certain cards to only work during certain hours and be able to
change that from the webpage.
I'm pretty sure I could code the webpage pretty easily and I might even be able to code the schedule with a little work. The part that I'm stumped on for now
is how to get it connected to the internet and make it communicate with the web page. I guess I could have the webpage store it's settings in a text file on the
server and have the Arduino parse settings from the text file but it's still that initial wiring of the WiShield 2.0 to your board and programming it to work that's
got me stumped for the time being.
Thanks
If you are looking to go from AC to 12v DC then you just need a standard wall wart adaptor thats 12v DC. Like this one.
http://www.sparkfun.com/commerce/product_info.php?products_id=9442
But many times you can find one of these on an old piece of electronics for free.
On my bread board I step down the 12v to 5v using a bread board power supply. This plugs right into the bread board to make things easier but still
requires the 12v adaptor mentioned above.
http://www.instructables.com/id/Arduino-RFID-Door-Lock/
http://www.adafruit.com/index.php?main_page=product_info&cPath=38&products_id=184
http://www.sparkfun.com/commerce/product_info.php?products_id=9319
If you have an arduino already, would it be possible to program the chip (ATMega168) and then put it onto the custom board? Would this save you from
needing an external USB->Serial FDIT programmer?
Thanks.
http://www.instructables.com/id/Arduino-RFID-Door-Lock/