Arduino RFID Door Lock




Introduction: Arduino RFID Door Lock

About: I like to take things apart, sometimes they go back together sometimes they end up as something entirely different then where they started.
***Updated 8/9/2010***

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!

All of the code, schematics, and PCB designs have been tested and refined. They are all posted here as of 8/9/2010

Updated video of the final system installed and working.

Step 1: Parts Needed

Here are a list of parts and links to where I bought them. This is the basic set of parts you need to build and arduino and a circuit to read RFID tags into the arduino. I am assuming you have a breadboard, power supply and hookup wires already.

Arduino Stuff

ATmega168 with Arduino Bootloader $4.95

Crystal 16MHz $1.50

Capacitor Ceramic 22pF $0.25 (x2)

Resistor 10k Ohm 1/6th Watt PTH $0.25

Mini Push Button Switch $0.35

Triple Output LED RGB - Diffused $1.95

RFID stuff

Either one of these, 20 has better range, 12 is smaller
RFID Reader ID-12 $29.95
RFID Reader ID-20 $34.95

RFID Reader Breakout $0.95

Break Away Headers - Straight $2.50

RFID Tag - 125kHz $1.95


TIP31A transistor (radio shack/local electronics store $1.50)

Door Lock is from ebay.
Door Fail Secure access control Electric Strike v5 NO
$17.50 (kawamall, bay)

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.

Step 3: Build the RFID Reader

Now that you have your arduino bread boarded and working you can put together the RFID reader portion of the circuit that will contain the ID-10 or ID-20 and RGB LED to indicate the status of the circuit. Remember that the reader will be outside and separate from the controller inside so that someone cannot easily break in.

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.

The schematic should be strait forward and easy to follow.

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.; = 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.

Step 5: Expand

This is only some of the cool stuff you can do with RFID. You could expand this much further with a LCD output, logging of who enters and when, network/twitter connection etc. I plan on making a finished PCB version of this circuit. I have never made a PCB before so I am still working on the design and layout of the parts. Once I have them complete I will post them as well. I encourage anyone to take the code I have written and modify it to do even more cool things!

Arduino Contest

Finalist in the
Arduino Contest

2 People Made This Project!


  • Fix It! Contest

    Fix It! Contest
  • Tiny Home Contest

    Tiny Home Contest
  • Metalworking Contest

    Metalworking Contest

342 Discussions

For over a year I've been wanting to do this and I finally got around to it. Since I lived in a college dorm (now I'm in an apartment), we can't modify the locks or install an electric door strike, so I used a servo motor wired to the deadbolt with string instead. I have modified the original sketch so it works with a servo motor. I also connected a pushbutton switch so it can be unlocked from the inside. When the pushbutton switch is pressed or a tag is read, the servo motor attaches and instantly turns the deadbolt to unlock, and relocks it in 10 seconds. The servo motor detaches after relocking so that the regular key can be used in case of emergency (and to comply with building rules).

Anyway here's my modified sketch:

I tried cloning my own Arduino but something's wrong in my circuitry so I just used an Arduino Uno instead. I put the RFID circuit outside and wired it to the Arduino inside conveniently via a single Ethernet cable (used 6 out of the 8 wires). I also connected an RGB LED both inside and outside the door.

4 replies

Link broke again (empty folder, specifically, after some reorganization). New link:

The best part about using a servo is I don't have to modify the existing door frame to fit an electric door strike, and it's fairly portable since everything is just hot glued or Command stripped to the door, no screws required. The USB power cable for my Arduino Uno is taped down. The Ethernet cable connecting to the black box RFID reader outside the door is routed down from the Arduino box and through the gap under the door, back up on the outside of the door to the reader. Usually apartment doors have wide enough gaps underneath.

The worst part about using the servo is getting the string to mesh with the deadbolt perfectly so there's just enough tension both opening and closing the deadbolt. That part takes hours. I wish I could just use a Lockitron that fits right over the deadbolt. Maybe I can 3D print a unit that mounts the servo to the deadbolt easily and without the use of strings.

The string I used is the strong, unstretchy kind used in window blinds. I reused a piece from broken window blinds.

I own a pizzeria and the delivery drivers come in and out of the back door all the time. I have taken your schematic and the modified version of your code (including the eraser card) and modded it myself a little further. I am currently installing this as a system on my back door. I have currently finished all the wiring and am just waiting for a few more parts from spark fun. I have made some changes to fit my actual wants and needs of the location, but overall it is the same lay-out. The whole project has proven REALLY fun so far and I hope to have it all wrapped up with in a week or so.

7 replies

 Thats awesome! Glad to see you are getting some practical use out of my project. I am etching some prototype boards this week and hope to permanently install it on my garage brewery this week.

So like I said it should be a week later and my project is all done. I have some pics and am uploading a "demo" video to you tube right now. I used RJ45 to run everything and with the 8pins there was one short coming of my version of the project. I will let all of you be the judge to see if you can figure it out. The whole system performs far anyway.

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.


After a couple prototypes and attempts I have worked out all of the bugs and published the updated PCB designs and schematics. I also embeded a video on the main page showing the new boards and the system working in action. Im looking into getting boards made somewhere incase others would like to order them.

 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. 

Thanks man. I really appreciate that. I havent soldered anything this "complicated" in about 2 years, so my soldering started out terrible and by the time I was done it was looking great. I wanted to go back and resolder the whole thing, but I decided to leave good enough alone.

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.

 Nice! someone here made a PCB design to get the boards printed... I am going to print and etch my own reader board to fit a small electronic enclosure and mount it outside like you have done. It's under a patto so it should not be too exposed. For now I am going to leave the breadboard inside so I can play with the code more.

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. 

I like the idea of one time use cards or "day pass" cards. In order for this system to meet my needs perfectly it would need to have an hours of operation type feature. So that my workers would not be able to enter the door in the middle of the night (11pm-7am) but at the same time I would like my card to work.
That is a feature I would like.
I also think im going to put a simple switch push button on the Arduino RX line so that I can push the button and break the connection between the ardunio and the ID-12 so that I can just jack in to the black box inside housing the ardunio to change the code. instead of having to curently open the box and disconnect the wire.
I was going to use software serial, but I just wanted to get the project done.

Please let me know as you make any new code. I would love you review it and possibly even help test it.

I don't understand how will you open the door from inside??

Excellent Instructable. I modified the code to work with the mega cheap RC522 and an Arduino clone. Hadn't really used EEPROM stuff before so I was pleased to learn how this all works. Does the Arduino sketch store new cards at the first available memory location or cycle through different locations to ensure the 10,000 write limit takes longer to come into play? I couldn't follow the code but I guess from EEPROM reader sketches I have I could work it out.

1 reply

Hello, I am very interested to see your code that you used with the RFID-RC522 module as I am doing the same. Any help will be greatly appreciated.

am I able to use an Arduino uno to do the same thing?

hi i want ask,if the rfid tag gone, how we open the door??

1 reply

The lock mechanism allows you to push the door open without turning the handle. You can still use the door like normal, with a key.

Hey this is complete video for otp based door lock