RFID Door Lock

I’ve been a college student for a few years now and one of the first things that I hacked together while staying in a dorm room was an RFID (Radio Frequency Identification) lock. I was always in a rush to get in and out of my room and having a wireless key made it that much easier. The challenging bit was that I needed to be able to attach it to my door without modifying any of the hardware and I also wanted it to be hidden from the outside. My first prototype was pretty rough, but over the past year I’ve refined my design and finished a minimalistic circuit board.

RFID Lock PCB

Prototype RFID Lock

In the first half of the RFID TTJ episode, I walk through the process of building this design and loading the board up with code. I’d highly recommend watching the video as it will give a good explanation of how everything is put together and goes further in detail than this post.

Now then, let’s get onto the details. The first thing you’re going to need for this build is the actual circuit board that everything gets connected and soldered to. I put together the minimal board design using Eagle.

RFID Lock Circuit Board

You can download all of the Eagle files and generated board files here:

rfid_lock_eagle_v01.zip

For actually having the board manufactured and sent to you, I highly recommend BatchPCB. Although you may have to wait upwards of a month to get the finished board in the mail, it’ll only cost you $10-$15 including shipping. I’m hoping to put together kits in the near future to make this step a bit easier.

As explained in the video, you have two options for RFID readers. You can either use an HID reader (common among universities and corporate environments) or a Parallax reader that uses the EM4102 card standard. As I was issued an HID card to gain access to the various buildings on campus, I decided to go with an HID reader for my purposes. The main issue is that HID readers are significantly more expensive (~$150 retail). You can find them cheaper on eBay, so if you really want to be able to read HID cards then I would suggest that route. If you don’t already have any RFID cards, the Parallax reader (~$40 retail) is most likely the way to go. This circuit board will work with both options – you’ll just be connecting the readers to different pins and loading different code.

As for all of the parts you’ll need for this build, I’ve compiled the list below:

1. (1) Custom Circuit Board (~$15 ordered from BatchPCB)
2. (2) 47uF Capacitors [Mouser.com Part #: 647-UHE1E470MDD] ($0.30)
3. (1) 5V Regulator [Mouser.com Part #: 511-L4931CZ50-AP] ($1.15)
4. (1) 20 Pin Socket [Mouser.com Part #: 571-1-390261-6] ($0.21)
5. (1) ATtiny2313 [Mouser.com Part #: 556-ATTINY2313-20PU] ($1.91)
6. (1) Header Pins [Mouser.com Part #: 649-68000-416HLF] ($0.40)
7. (3) 3 conductor screw terminals [Sparkfun.com Part #: PRT-08235] ($4.50)
8. (1) 2 conductor screw terminals [Sparkfun.com Part #: PRT-08084] ($1.25)
9. (1) Magnet [Sparkfun.com Part #: COM-08914] ($1.00)
10. (1) Reed switch [Sparkfun.com Part #: COM-10601] ($2.00)
11. (1) Dome Button [Sparkfun.com Part #: COM-09181] ($10.00)
12. (1) 6V Power Supply [http://www.radioshack.com/product/index.jsp?productId=2049709] ($1.50)
13. (1) Hitec HS-311 Servo [http://www.amazon.com/Hitec-RCD-Inc-31311-Standard/dp/B0006O3WVE] ($10.00)
14. (1) Parallax RFID Reader + Sampler Kit
[http://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/441/Default.aspx] ($43.00)
15. Door mounting hardware (foam, double sided tape, zip ties) [Home Depot] ($5.00)

Total Cost: ~$100

As far as assembly of the board goes, it’s pretty straight forward. Solder in the 20 pin socket (make sure to line up the notch), snap the screw terminals together and solder them in place, solder in the 2 capacitors, the voltage regulator, and then break apart the header strip to populate the programming header and servo header. Pop your ATtiny2313 microcontroller into the socket (making sure to match up the notch) and you’re ready to program.

Assembled Circuit Board

At this point you’ll need something that is capable of writing code to an AVR microcontroller. If you have an Arduino, it’s possible to use that. For this build I ended up using a USBtinyISP Kit. You can pick one up from that link for $22 and it’ll give you a simple interface between USB and the ISP programming header (which will also come in handy for the second half of the episode). In the video I demonstrate how to write the code to the RFID board. The 3 software packages I mention correspond to which operating system you’re using:

OS X: CrossPack
Windows: WinAVR + USBtinyISP Driver
Linux: avr-gcc/avrdude from your package manager

You can download the source code for either a Parallax reader or HID reader from here:

parallax_rfid_lock_v01.zip
hid_rfid_lock_v01.zip

As an additional step that wasn’t included in the video, you’ll need to get the code off your HID tag if you’re using an HID reader. I’ve put together an extremely simply Arduino sketch included in the HID source code zip file above that will allow you to get your tag code. All of the explanation should be included in the comments at the top of the file. If you’ve still got questions after checking out the sketch, feel free to post them in the comments.

Now that your board is assembled and the code is loaded up, all you have to do is screw in your connections and mount the reader to your door. Once again I’m going to prod you to watch the video because there’s a pretty good explanation of how all the components wire together (with the Parallax reader). I also talk about how the HID MiniProx reader gets connected. In summary, there are 4 wires you’ll need to connect. You can wire the Vcc and Gnd directly to the 6v adapter input and then just connect your Data 0 and Data 1 wires to the corresponding IN0 and IN1 connections on the PCB.

Fully Wired Board

As far as mounting goes, each door is different. For the most part I’ve been able to get away with using zip ties to hold the servo onto the actual deadbolt handle and then use lightweight foam and double sided tape to hold the servo in place. Stick your magnet onto the door frame and mount your reed switch on the edge of the door so it detects the door opening/closing. Everything else can be mounted using double sided tape.

Servo Lock Mounting

Foam used for mounting the Servo

There you have it! Your very own RFID door lock that requires no modifications to the door. I know there was a lot covered in this post, so I will continue to update it with information I feel is useful. Although we love using RFID for a lot of our projects, make sure to check out our post on spoofing RFID tags to understand how they can be exploited. Hit up the comments below if you’ve got any questions and I’ll do my best to answer them and get your RFID door lock up and running!


47 Comments on “RFID Door Lock”

  1. Taylor Cox says:

    Hey, I also have put one of these on my dorm room door running with an arduino when I was a freshman. Can you post or email the schematic for your board design? Instead of having a custom one made…I’ll just DIY my own board.

    • Eric Barch says:

      Hey Taylor,

      That’s awesome you’re going to DIY the board 🙂 If you download the schematic and board design I posted above you can load it up in the free version of Eagle. It should give you a pretty good idea of what you’ll have to put together. Just let me know if you have any questions!

      Eric

      • Taylor Cox says:

        Hey I just finished my door setup..turned out my apartment door is metal so I couldn’t have a completely indoors contained system. I am using a 11.1v li-poly battery with a 5 volt regulator to run my system…the last question I have is how do I make it so that the reader can verify and open the door with more than one rfid code. I have a tag for my roommmate and myself, but how do I enable both tag’s code’s to be allowed to open the door in the code? In the quotations do I just separate the two 10 digit codes by a comma?

      • Eric Barch says:

        Hey Taylor,

        Sounds like you’ve made great progress! You should shoot over an image or two of your finalized design if you have a chance. As far as reading two tags, you’ll want to add another variable at the top:

        char validKey[] = “TAG_VALUE_GOES_HERE”; //Valid RFID Tag
        char validKey2[] = “TAG_VALUE_TWO_GOES_HERE”; //Valid RFID Tag

        Then down in the code a bit you just need to check either of the tags like this. What strncmp does is compare two strings and returns 0 if they are equal to one another:

        else if (receivedByte == 0x0D) { // This is the stop byte – we now have a tag
        if (strncmp(readBytes, validKey, 10) == 0 || strncmp(readBytes, validKey2, 10) == 0)
        validTag = HIGH;
        }

        Eric

  2. Taylor Cox says:

    And how long does the 6v battery last before you have to recharge it?

  3. […] of the first things that [Eric] hacked together when he got to college was an RFID door locking system. He found that he was often in a rush to get in and out of his dorm room, and that using a simple […]

  4. Ed says:

    Hey Eric-

    I just tried uploading your eagle schematics into BatchPCB, but I’m getting the following error. Any help would be appreciated.

    Thanks,
    Ed

    BatchPCB is locking down. We are no longer accepting any floating files. Please clean up your uploaded file and resubmit.
    We are only accepting the following list of file extensions:

    TopCopper – “.gtl” , “.cmp”, “.top”
    BottomCopper – “.gbl”, “.sol”, “.bot”
    TopSolderMask – “.gts”, “.stc”, “.smt”, “.stoptop”, “.tsm”
    BottomSolderMask – “.gbs”, “.sts”, “.smb”, “.stopbot”, “.bsm”
    TopSilk – “.gto”, “.plc”, “.sst”, “.positop”, “.leg”, “.slk”
    BottomSilk – “.gbo”, “.pls”, “.ssb”, “.posibot”, “.bsk”
    Drill – “.drl”, “.txt”, “.tap”, “.drill”, “.gdd”, “.drd”, “.cnc”, “.exl”
    KeepOut – “.gko”
    MiddleCopper1 – “.g2”
    MiddleCopper2 – “.g3”
    BottomStencil – “.gbp”
    TopStencil – “.gtp”
    Outline – “.outline”, “.oln”

    BatchPCB Support

    • Eric Barch says:

      Hey Ed,

      BatchPCB doesn’t need all of the files generated by EAGLE…you should just be able to send them the .cmp, .drd, .plc, .pls, .sol, .stc, and .sts files and be good to go. Let me know how it goes!

      Eric

  5. Andrew K says:

    Hey!

    I just received the HID reader I ordered off EBay for my Arduino.

    Red: 5V on Arduino
    White: 1
    Green: 0
    Black: Ground.

    I’ve hooked these up all to their respected connections, but can’t for the life of me get anything returned down the data pins.

    Any ideas what I could be missing out on?

    Thanks! and keep up the great work

    • Eric Barch says:

      Hey Andrew,

      What code are you using to test out the reader? The sketch I included in hid_rfid_lock_v01.zip? Does it beep a few times when you power it up? What color is the LED on the front?

      Eric

      • Andrew K says:

        Hey thanks for the quick reply.

        I actually figured out my issue. I only have 10K and 330ohm resistors on hand, so I had to do what I could with what I had..

        I wound up putting two 330s in parallel and that brought me to exactly the 30ma maximum current for the reader. It powered up perfectly, read the code, and now I just need to get the hardware to burn one of those chips.

        Unfortunately I got one of the Arduino Unos that have the new mini chip (basically meaning I can’t remove or replace the processor). Any suggestions on what’s the best method on burning the code onto one of the ATtiny85 chips?

        Thanks,
        Andrew

      • Eric Barch says:

        Hey Andrew,

        Awesome…good deal on the reader. It looks like you can still use the Uno to burn code over the ISP header:

        http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1289761852
        http://arduino.cc/en/Tutorial/ArduinoISP

        Even though the page states that it doesn’t work with the Uno, apparently people are reporting that it does indeed work. If you can’t get it to work though, I’d highly recommend the USBtinyISP from adafruit: https://www.adafruit.com/products/46 It’s a simple kit that will get you up and burning code in no time. You just need to build a programming cradle so you have a 6 pin ISP header connected to an 8 pin socket.

        Let me know how it works out for you!

        Eric

      • Andrew K says:

        Looks like it works – didn’t even use the ICSP header pins.

        I used the following with the SMD version of Arduino Uno (for reference.. if people want to mimic..
        http://hlt.media.mit.edu/?p=1229

        I confirmed that the blinking LED worked. Then proceded with the following command line (pulled from monitoring what flags the Arduino software sends to avrdude.. On my one Windows7 64bit comp):

        avrdude “-CC:Program Files (x86)arduino-0022
        hardware/tools/avr/etc/avrdude.conf” -q -q -pattiny85 -cstk500v1 -P\.COM6 -b19200 -Uflash:w:avrfid.hex -v -v -v -v

        It seems to write okay. Before I set the clock source to the 2 pins, I need to ensure the numbers I’m putting in are okay (since I know there was limited info about HID card programming in the video.

        #define HID_SITE_CODE 0x##
        #define HID_UNIQUE_ID ##### // May be written on the back of the card

        Now, I put the decimal numbers (the ones I converted from binary) into each of those fields. Is that correct, or does the Site Code need to be converted to HEX instead?

      • Eric Barch says:

        Hey Andrew,

        Looks good. The site code does need to be in hex (it should just be those 8 bits of binary to hex) and the unique ID is indeed just your 16 bit binary number converted to decimal.

        Eric

      • Andrew K says:

        Awesome.. Looks like I got it to read on my HID reader!

        The only concern I have is the 2 parity bits are reversed (if that matters). IE, the very first is 1 and last digit is 0 on my legit tag, but it’s 0 and 1 on my cloned tag..

        Will that matter?

      • Eric Barch says:

        Huh…that’s really strange. The code should’ve automatically taken care of the parity bits properly. Are all the other bits exactly the same? It’s up to the device taking input from the reader to check parity, so it may or may not work. Check out this document for a bit more info on the card format:

        Click to access understandCardDataFormats_wp_en.pdf

        The first 13 bits should come out to be an even number (eg. there are an even number of 1s) and the last 13 bits should come out to be an odd number.

        Eric

      • Andrew K says:

        Hey Eric,

        Thanks so much for all your help – I haven’t said it enough 🙂

        Original: Even, Odd
        Cloned: Odd, even.

        Other than that, the rest of the numbers (the 8 bit site code and 16bit card number) are identical to one another. I guess it will depend on the system whether it accepts the opposite parities or not.

        I’m sure it would be an easy code fix in the code sent to the chip, but still strange nonetheless.

      • Eric Barch says:

        Andrew,

        No prob…happy to help =)

        I am a bit baffled at the fact that you ended up with flipped parity bits. You pulled the code off this link, right?

        http://svn.navi.cx/misc/trunk/avrfid/avrfid.S

        And you also had the defines setup as such?

        //#define FORMAT_IS_EM4102
        #define FORMAT_IS_HID

        If that’s the case, the #define statements should’ve calculated the correct parity bits before the code was flashed to the micro. Very strange indeed that you ended up with flipped bits.

        Eric

      • Andrew K says:

        Eric,

        Yep, it’s identical (I ran a compare between the two codes) – except mine has the HID codes listed, and the FORMAT_IS_HID uncommented (while commenting EM4102).

        I guess this may be a good way for me to dig into some assembler … 🙂 . This is going to be fun to debug.

        My site code is 5, so I listed it as 0x05 in the code. Think the extra 0 would be the cause? I wouldn’t think so… But who knows.

      • Eric Barch says:

        Hmm, the 0 shouldn’t matter. Very strange, that’s for sure. Let me know if you figure anything out…I’d love to find out why that happened.

        Eric

      • Andrew says:

        I got in touch with the creators of the code and it appears there is in fact a bug with the way the parities are being calculated/outputted.

        Looking at the code, only ONE parity (“odd parity”) is being created. Since there are only 2 parity bits, and each can only be a 1 or 0, there’s a 25% chance it’ll be right on your cloned tag, depending on your site ID and unique ID 😉

        I got a version 1.2 of the code, but still doesn’t totally look right to me. The parities are being calculated by doing a parity calculation on the Site ID and Unique ID (which is incorrect). It might be a bit tricky, but I may have to create a code fix and submit it- Taking SiteID + first 4 bits of the unique ID (for parity 1) and last 12 bits of unique ID (for parity 2)..

        Stay tuned..

      • Eric Barch says:

        Aha! Interesting indeed…keep me in the loop.

  6. Spencer says:

    Would you guys build me one and send it to me? I don’t have the time or the ability haha

    • Eric Barch says:

      Hi Spencer,

      Do you just need the assembled board and RFID tag or do you also need a way to mount it? I wouldn’t mind putting together some of the boards for everyone who wants one…it’s just tricky for mounting hardware because all door locks are different.

  7. Dustin says:

    Hello,
    Awesome guide. I am looking to do this, however I would like to use a strikeplate as I can mod the door for my application of this. New to electronic building, but should I be able to simply replace the servo with the strike plate connectors and be good to go for the design? Voltage looks to be ~ equivalent.
    Looking at this for the strike plate:
    http://www.ebay.com/itm/Door-Fail-Secure-access-control-Electric-Strike-v5-NO/350230332833#ht_3787wt_1167

    Thanks again!

    • Eric Barch says:

      Hi Dustin,

      I’ve been wanting to implement that on the next revision…unfortunately it’s not quite as simple as just swapping in the lock. For controlling a servo a very low current PWM signal is being generated by the microcontroller and the power is being pulled straight from the 6V adapter. You’ll most likely need to incorporate a MOSFET into the design that can switch the amount of current that the strike plate pulls. The easiest way to do this is with a logic level FET that will accept 5V as an input and tie it into one of the microcontroller pins (the same one that generates the PWM signal for the servo could be used).

      Best of luck,

      Eric

  8. RFID Door Lock is so awesome, it’s amazing. Very helpful guide. Hope you come up with another tutorial. Thanks.

  9. […] hard, but with a handful of groceries it’s a difficult task. You can piece together your own RFID lock that unlocks with a wireless key and locks itself automatically. It’s not the most exciting […]

  10. jost says:

    I have a business idea for you that involves your RFID thing. Please contact me via email so we can exchange telephone numbers.

  11. […] hard, but with a handful of groceries it’s a difficult task. You can piece together your own RFID lock that unlocks with a wireless key and locks itself automatically. It’s not the most exciting […]

  12. Derek says:

    Great guide here and I would love to implement this in my apartment, but there is one concern that I have. Would this system still allow for the physical key to be used to open the door? I would imagine that the answer would be yes as a blackout would basically lock you out of your house if this did not allow for it. But, I also need to make sure the maintenance people can get in if needed without having to dismantle the entire thing.

    • Eric Barch says:

      Hi Derek,

      The Servo powers off after it locks or unlocks the door, so you can still easily rotate the deadbolt using a key.

      Best of luck!

      Eric

  13. Andrew says:

    Wondering if the TX wire has any implementation yet, built it this weekend and would love to have it connect to another board to play music when the door opens 🙂

  14. Jesper L says:

    Cool! possible to operate the whole setup using batteries?

    • ericbarch says:

      Provided you had a 6V battery to power the servo, sure! You could also use a larger battery with a regulator to bring it down to the correct voltage.

  15. Yvon Cau says:

    Hey, I’ve been putting together this project for a few weeks now, and got a couple questions.

    1) My door is approximately 2.5 inches thick, made of wood. Do you think the RFID reader will be able to read tags from outside the door?

    and

    2) My deadbolt isn’t a perfect 90 degree turn to lock/unlock. Would that break the servo if the deadbolt only turns about 70ish degrees?

    Thanks! I appreciate all the info on this article; super helpful!!!

    • ericbarch says:

      Hey Yvon,

      1) If it does work, it’ll just BARELY work. Worth a shot either way though!

      2) You should be able to tune your servo values so it only turns the exact amount you want it to. Just start off with some conservative values and keep bumping them up until it successfully unlocks the deadbolt.

      Thanks for the feedback! Glad it helped you out!

      • Yvon Cau says:

        Thanks for replying!!!! I ran into another problem today…I have no idea how to get the power cord to power the actual servo. Am I suppose to cut off the end of the power cord and somehow attach it to the servo itself?

        Thanks!

      • ericbarch says:

        Hey Yvon,

        Servos typically run at 6V. You should be able to use any sort of 6V power supply. You can cut the red/black wires and connect these to 6V. Then just tie the ground of the Arduino to the ground of your 6V supply.

  16. J says:

    soooo cool! thnx for the inspiration & info!

  17. tws says:

    Hey Eric,

    Great tutorial! I’m looking to order a board but it’s been a while since you posted this tutorial and BatchPCB has been taken over by these guys. http://oshpark.com
    I tried to upload the file as you had it but it didn’t meet their guidelines.
    Do you have any suggestions as to how to upload to get the correct board?

    Thanks!

  18. Tiffany says:

    Hey Eric, Im actually working on something similar to this but I’m making it so that you can lock and unlock the door from a website. i’m having problems coming up with the actual hardware for the locking mechanism. Do you have any suggestions? Thanks!

  19. […] of the first things that [Eric] hacked together when he got to college was an RFID door locking system. He found that he was often in a rush to get in and out of his dorm room, and that using a simple […]