Home > Arduino > Arduino RFID Door Lock

Arduino RFID Door Lock

Arduino RFID Door Lock

Once again me and one of my class mates have finished a project in school using the Arduino.
This time it’s an RFID Door Lock made with a real door and a real lock. The lock is turned using a standard 6V servo.

The project was about luxury, and we thought it might be luxurious if the door could be unlock automatically, fx when you come home from shopping, carrying a bag in each hand. This was the beginning of this project.

In the video below you can see a short demonstration of the system.



We thought you might be interested in the code, and to see how we implemented the “Master-system”, so the code can be found beneath. Remember that you should download the Servo library, and the Parallax RFID reader should be connected to the Serial RX pin (Pin 0).

//Start
#include <eeprom.h>
#include <servo.h>

//Initialiser
Servo servoLock;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

#define RFID_Enabled_Pin 2  // sets RFID enable pin to pin 2
#define servoPin 3 // sets the servo's pin to pin 3
#define LockedPos 10
#define UnlockedPos 110

byte buffer[100]; //used to store the incoming bytes from the RFID
byte RFID_Master[10] = {'1', '7', '0', '0', '7', 'D', 'B', '2', '4', 'F'}; //the secound RFID fob (key) to look for
byte RFID_Slave1[10], RFID_Slave2[10], RFID_Slave3[10]; //the first RFID fob (key) to look for
byte i; //used to keep track of which bit to write to
byte i2; //used to erase the RFID fob (key) number from the buffer

boolean DoorLocked; //true if door is locked

byte checkPosition; //used to check if the incomming number is true or false
boolean RFID_Master_Correct; //true if it's the right RFID fob (key), false if not
boolean RFID_Slave1_Correct, RFID_Slave2_Correct, RFID_Slave3_Correct; //true if it's the right RFID fob (key), false if not
boolean RFID_SaveNextRead;

void setup() {
  pinMode(13, OUTPUT); //enables the diode on the arduino
  pinMode(RFID_Enabled_Pin, OUTPUT); //sets the RFID pin to output
  RFID_Enable(false); //used to set the status of the RFID reader
  EEPROM_Read_Slaves();
//Lock
  PreLock(); //locks the arduino on startup
  RFID_Enable(true); //used to set the status of the RFID reader
  Serial.begin(2400);  //sets baudrate
  i = 1; //sets the varible to 1, and thereby skip the start byte (0x0A)
}
//Go To
//Loop
void loop() { //the main loop
// Serial data
  if (Serial.available()) { //check if the RFID reader sends anything
    if (buffer[0] != 0x0A) { //check if it the start bit is 0x0A
      buffer[0] = Serial.read(); //write bit to buffer
    } else {
//Recieve
      buffer[i] = Serial.read(); //write next bit to buffer
      if (buffer[i] == 0x0D) {   //if end bit is send, disable the RFID reader temporary
        Serial.print("RFID Tag scanned: ");
        RFID_Enable(false);
        RFID_Master_Correct = true;
        RFID_Slave1_Correct = true;
        RFID_Slave2_Correct = true;
        RFID_Slave3_Correct = true;
//RFID ID
        // We have read all bytes - we are now going to check them
        for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
          Serial.print(buffer[checkPosition+1], BYTE);
          if (buffer[checkPosition+1] == RFID_Slave1[checkPosition] && RFID_Slave1_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave1_Correct = true; //Slave1 RFID tag is detected
          } else {
            RFID_Slave1_Correct = false; //Slave1 RFID tag is not detected
          }
          if (buffer[checkPosition+1] == RFID_Slave2[checkPosition] && RFID_Slave2_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave2_Correct = true; //Slave2 RFID tag is detected
          } else {
            RFID_Slave2_Correct = false; //Slave2 RFID tag is not detected
          }
          if (buffer[checkPosition+1] == RFID_Slave3[checkPosition] && RFID_Slave3_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave3_Correct = true; //Slave3 RFID tag is detected
          } else {
            RFID_Slave3_Correct = false; //Slave3 RFID tag is detected
          }
          if (buffer[checkPosition+1] == RFID_Master[checkPosition] && RFID_Master_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Master_Correct = true; //Master RFID tag is detected
          } else {
            RFID_Master_Correct = false; //Master RFID tag is detected
          }
        }
        Serial.println("");
        if (RFID_SaveNextRead == false && (RFID_Slave1_Correct == true || RFID_Slave2_Correct == true || RFID_Slave3_Correct == true) && RFID_Master_Correct == false) { //see if the right RFID fob (key) is detected
          if (RFID_Slave1_Correct == true) { Serial.println("Slave1 Card Scanned"); }
          if (RFID_Slave2_Correct == true) { Serial.println("Slave2 Card Scanned"); }
          if (RFID_Slave3_Correct == true) { Serial.println("Slave3 Card Scanned"); }
//Door
          if (DoorLocked == true) { //see if door is locked or not
//Unlock
            Serial.print("Unlocking..."); //if the door is locked then unlocked it
            Unlock(5); //unlock with 5ms delay
            Serial.println(" Unlocked!");
          } else {
//Lock
            Serial.print("Locking..."); //if the door is unlocked then lock it
            Lock(5); //lock with 5ms delay
            Serial.println(" Locked!");
          }
//Vent
          delay(1000); // Wait for you to remove the RFID fob (key)
        } else if (RFID_Master_Correct == true && RFID_SaveNextRead == false) { // If the Master Card is scanned when not in programming mode
          Serial.println("Master Card Scanned - Programming mode Enabled");
          delay(1000);
          RFID_SaveNextRead = true;  // Enable programming mode
        } else if (RFID_Master_Correct == false && RFID_SaveNextRead == true) { // If another card is scanned when in programming mode
          // Save the Card
          if (RFID_Slave1[0] == 0) { // Is the Slave1 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave1[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave1
            }
            Serial.println("RFID Card saved in: Slave1");
            delay(1000);
          } else if (RFID_Slave2[0] == 0) { // Is the Slave2 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave2[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave2
            }
            Serial.println("RFID Card saved in: Slave2");
            delay(1000);
          } else if (RFID_Slave3[0] == 0) { // Is the Slave3 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave3[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave3
            }
            Serial.println("RFID Card saved in: Slave3");
            delay(1000);
          } else {
            Serial.println("No free Card slots");
            RFID_Enable(true); //turns on the RFID reader
            delay(1000);
            RFID_Enable(false); //turns off the RFID reader
            delay(1000);
          }
          EEPROM_Save_Slaves();
          RFID_SaveNextRead = false;
        } else if (RFID_Master_Correct == true && RFID_SaveNextRead == true) { // If the Master Card is scanned when in programming mode
          Serial.println("Master Card Scanned again - Removing all saved Cards");
          delay(1000);
          // Remove all Slave Cards
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave1[checkPosition] = 0;
          }
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave2[checkPosition] = 0;
          }
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave3[checkPosition] = 0;
          }
          EEPROM_Save_Slaves();
          RFID_SaveNextRead = false;
        }

        RFID_Enable(true); //turns on the RFID reader
        EmptySerialBuffer(); //erase the buffer
        Serial.println("");
      }
      i++; //used in the beginning to write to each bit in the buffer
    }
  }
//Go to
}


void EmptySerialBuffer() { //replaces all bits in the buffer with zeros
  while (Serial.available()) { Serial.read(); }
  for (i2 = 0; i2 <= i; i2++) {
    buffer[i2] = 0;
  }
  i = 0;
}

void PreLock() {
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  servoLock.write(LockedPos);              // tell servo to go to position in variable 'LockedPos'
  delay(250);                       // waits 1s for the servo to reach the position
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = true;    //the door is locked
}

void Unlock(byte speedDelay) {
  int pos;
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  for(pos = LockedPos; pos < UnlockedPos; pos += 1)  // goes from 10 degrees to 110 degrees
  {                                  // in steps of 1 degree
    servoLock.write(pos);              // tell servo to go to position in variable 'pos'
    delay(speedDelay);                       // waits 5ms for the servo to reach the position
  }
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = false;   //the door is unlocked
}

void Lock(byte speedDelay) {
  int pos;
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  for(pos = UnlockedPos; pos > LockedPos; pos -= 1)  // goes from 110 degrees to 10 degrees
  {                                  // in steps of 1 degree
    servoLock.write(pos);              // tell servo to go to position in variable 'pos'
    delay(speedDelay);                       // waits 5ms for the servo to reach the position
  }
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = true;    //the door is locked
}

void RFID_Enable(boolean enabled) {
  if (enabled == true) {
    digitalWrite(RFID_Enabled_Pin, LOW); //enables the RDIF reader and turns on the diode on the arduino
    digitalWrite(13, HIGH);
  } else {                               //disables the RDIF reader and turns off the diode on the arduino
    digitalWrite(RFID_Enabled_Pin, HIGH);
    digitalWrite(13, LOW);
  }
}


void EEPROM_Read_Slaves() {
  byte EPROMaddr;
  for (EPROMaddr = 0; EPROMaddr < 10; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave1[EPROMaddr] = EEPROM.read(EPROMaddr);
  }
  for (EPROMaddr = 10; EPROMaddr < 20; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave2[EPROMaddr-10] = EEPROM.read(EPROMaddr);
  }
  for (EPROMaddr = 20; EPROMaddr < 30; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave3[EPROMaddr-20] = EEPROM.read(EPROMaddr);
  }
}

void EEPROM_Save_Slaves() {
  byte EPROMaddr;
  for (EPROMaddr = 0; EPROMaddr < 10; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave1[EPROMaddr]);
  }
  for (EPROMaddr = 10; EPROMaddr < 20; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave2[EPROMaddr-10]);
  }
  for (EPROMaddr = 20; EPROMaddr < 30; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave3[EPROMaddr-20]);
  }
}

Update:
The newest version of the code is now available at Github: https://github.com/TKJElectronics/ArduinoRFIDDoorLock.

Categories: Arduino Tags:
  1. Lewsut
    April 2nd, 2011 at 17:56 | #1

    Thanks for directing me to this.

  2. joshuaUnreal01
    April 5th, 2011 at 17:58 | #2

    Great job!!!!!! well I try to use your code but my RFID module work to 13.56Mhz. Can u tell how use this tag

    tag numbers that can have access
    int tag[10] = {175,175,175,178,175,179,100,100,121,61};

    can you help me whit the code???

  3. April 5th, 2011 at 18:25 | #3

    @joshuaUnreal01
    Dear Joshua.
    You would just have to change the RFID_Master constant to your tag.
    Like this: byte RFID_Master[10] = {175,175,175,178,175,179,100,100,121,61};

    Best Regards
    Thomas Jespersen

  4. Gerard
    July 29th, 2011 at 23:53 | #4

    Hi!

    This project is awesome! I’m starting at electronics, more as a hobby and I would love to do this project, and I was wondering if you can show me the schematic.

    Thanks.
    And I hope you can help me.

  5. July 30th, 2011 at 23:15 | #5

    @Gerard
    Dear Gerard.
    Unfortunately in this project we didn’t make any schematic because the setup was that simple.
    It was just a matter of connecting +5V and GND to the Servo and RFID board, connecting Digital Pin 3 to the Servo PWM pin, Digital Pin 2 to RFID Enable and Digital Pin 0 (RX) to RFID Output. As simple as that ๐Ÿ™‚
    Please do not hesitate writing again with further questions.

    Thomas

  6. Gerard
    August 3rd, 2011 at 03:31 | #6

    Thank you so much for all your help I really appreciate it ๐Ÿ˜€
    Greetings and thanks again, I’m going to do this project as soon as possible ๐Ÿ˜€

  7. John
    September 21st, 2011 at 03:59 | #7

    Hi!What is the servo that you used?

    Nice project BTW ๐Ÿ˜‰

  8. September 23rd, 2011 at 21:50 | #8

    @John
    Thank you.
    We are using a TowerPro SG-5010 from Sparkfun – Servo – Large

    Thomas

  9. Toh
    October 18th, 2011 at 12:38 | #9

    Hello, I am really new to arduino and hardware, but I really like this project of yours. So mind my stupidity in asking this, but i really am clueless:
    When your RFID reader reads a card, does the code of the card go directly from the reader to the computer, or it passes through the arduino, and the arduino passes it to the pc? And if it goes through the arduino, how do you make it give signal to the pc?

  10. October 19th, 2011 at 14:59 | #10

    @Toh
    The Arduino takes care of reading the card and parsing the data/code. If the code is identified as one of the saved cards, the Arduino either unlocks or locks the door, or goes into Master editing mode.

    The computer is only used for debugging purposes. This means that the project works fine without a computer!

  11. Steve
    October 21st, 2011 at 22:23 | #11

    Hi! You are using the USB or the Serial RFID reader?

  12. Lauszus
    October 21st, 2011 at 23:26 | #12

    @Steve
    Hi. We used this Serial RFID reader from Parallax, as it can then be connected directly to the RX pin on the Arduino.

  13. Warren Hanna
    October 27th, 2011 at 21:14 | #13

    @Thomas Jespersen
    hello, i am very interested in starting this project, but i have been confused about one thing, How do you determine the RFID tag numbers?

  14. Lauszus
    October 27th, 2011 at 22:27 | #14

    @Warren Hanna
    It’s actually pretty easy. What we did is we used a USB Serial Converter like this one and then connected the RFID Card Reader Serial directly to the USB Serial Converter, then you just have to open a terminal program and set it to the right baudrate (2400 in this example) and it will print the tag numbers on the screen everytime you put a RFID tag in front of the reader.
    Alternatively you could just read the tag numbers with the Arduino. See this page for information.

  15. October 29th, 2011 at 14:24 | #15

    @Warren Hanna
    As Lauszus said, we determined the RFID tag numbers by reading them with the reader, before programming the numbers into our software routine.
    This can be done as either explained by Lauszus, by using an USB to Serial converter – or you could also connect the RFID reader to another port on the Arduino and make use of the Software Serial library, and then print the numbers to the Arduino serial console.

  16. December 17th, 2011 at 13:26 | #16

    hello I am very interested with your project..i would like to ask what was that thing that is placed above the arduino, is it a motor shield for the servo motor?thanks and how qwas the pins connected..thanks a lot!!

  17. December 17th, 2011 at 13:28 | #17

    *was

  18. December 23rd, 2011 at 17:56 | #18

    @jessica
    Hi Jessica.
    Are you talking about the “shield” mounted on top of the Arduino?
    That is not actually a real shield. It is just a prototyping PCB which connects the proper pins to wires in the cable going into the door.

    Best Regards
    Thomas Jespersen

  19. Pablo
    February 4th, 2012 at 22:49 | #19

    Hello ! Iยดm from Brazil and I found this great website. I am a newbie with Arduino and I did a copy and paste of you code. when i complided it, the message apeared:

    ———————————————————–

    sketch_feb04a.cpp: In function ‘void loop()’:
    sketch_feb04a:57: error: ‘BYTE’ was not declared in this scope

    As of Arduino 1.0, the ‘BYTE’ keyword is no longer supported.
    Please use Serial.write() instead.

    sketch_feb04a.cpp: At global scope:
    sketch_feb04a:234: error: function definition does not declare parameters

    —————————–

    I have no ideia how to fix this issue. Can Anybody help me?

    Thanks a lot

    Pablo

  20. February 4th, 2012 at 22:56 | #20

    @Pablo
    Dear Pablo.
    Thank you for your interest in our project.
    The problem you describe occours because the Arduino team made some changes to the coding environment in the recent V1.0 update.
    To get the code working you simply have to change the following line to the line below.

    Find:
    Serial.print(buffer[checkPosition+1], BYTE);

    Replace with:
    Serial.write(buffer[checkPosition+1]);

    Best Regards
    Thomas Jespersen

  21. Tanner
    February 11th, 2012 at 04:50 | #21

    Is it possible to integrate a milti-colored LED into this project to denote weather the door is unlocked or locked?

  22. February 11th, 2012 at 14:53 | #22

    @Tanner
    Yes, definitely. In the video you will notice the Red/Green LED – this is controlled thru the RFID module Enabling pin, so it that easy to control that.
    But if you added another multicolor LED you would be able to decide which colors to use in the different modes.

  23. Zane
    March 21st, 2012 at 00:22 | #23

    does this require a computer at all times

  24. Lauszus
    March 21st, 2012 at 11:53 | #24

    @Zane
    No, we use the computer in the video for demonstrating purpose only. It is fully functional on it’s own, the Arduino only needs power from a a wall wart or battery ๐Ÿ™‚

  25. jessica
    March 26th, 2012 at 04:34 | #25

    hi thomas, i’m still working on it..I was wondering if how did you connect the servo to the door lock,i really dont have an idea on mechanical side..so, you didn’t use any shield those were just jumpers right? really need it badly thanks a lot..

  26. jessica
    March 26th, 2012 at 04:39 | #26

    and one more thing only the start and stop bits were displayed in the hyperterminal when I was about to see the tag of the rfid. I dont know what’s the problem..thanks!!

  27. jessica
    March 26th, 2012 at 04:41 | #27

    i mean I could not see the key of the tags. only the start and stop bits were being displayed.

  28. jessica
    March 26th, 2012 at 05:30 | #28

    hoping for your reply soon thanks

  29. March 26th, 2012 at 14:55 | #29

    @jessica
    Dear Jessica.
    We actually made our own shield as you can see at 0:50 in the video. Though for prototyping it is just as easy simply to connect the wires to the right pins.
    The servo motor should be connected to +5V (red wire), GND (black wire) and the PWM data signal (orange or brown). In our case the PWM data wire is connected to pin 3 on the Arduino.

    Are you using the same RFID board as we are using – the Parallax one?
    Have you connected the TX line coming from the RFID board to the RX input on the Arduino?

    Best Regards
    Thomas Jespersen

  30. Remi
    March 27th, 2012 at 12:13 | #30

    Dear Thomas,

    I used your code to programme mine. I use the ID-12 from Sparkfun, so I set the Baudrate to 9600.
    If I insert the TAG ID in the master Slave, the programme does not recognize the ID.
    But if I open Serial monitor, I see space between the Serial.print(“RFID Tag scanned: “); and the ID it self. If I copy this space and paste it into the Mastercode, it works.

    So the RFID Reader, reads a sort of space as the first two bits. In serial monitor, the last two bits of the code are missing.

    I hope you understand my problem, if not, you can email me for more information and pictures if needed.

  31. Remi
    March 27th, 2012 at 15:48 | #31

    Dear Thomas,

    I found the problem. The start bit with the ID-12 is 0x02 instead of 0x0A.

    So for the people who want to use the ID-12, adapt the Baudrate to 9600 and the start bit to 0x02.

    Make sure that you put the Reset pin on +5V.

    Grz

  32. Lauszus
    March 28th, 2012 at 15:42 | #32

    @Remi
    Thank you for bringing awareness to the problem.

    Regards
    Lauszus

  33. Josh
    April 6th, 2012 at 17:40 | #33

    Thomas,
    I am very interested in utilizing a fingerprint scanner in conjuction with an arduino nano for a home door lock. I have seen a project utilizing a electric door strike and wonder if that would work as well as the servo motor in terms of reliability and cost. Also, I am taking a minimalistic approach for aesthetic purposes and wonder if you have any thoughts on that as well as cost efficiency. Thanks!

    Josh

  34. April 6th, 2012 at 23:24 | #34

    @Josh
    All right, that sounds like a great project.
    There are definitely different approaches to that project, especially because you have to decide which locking mechanism you would like to use, just as you said.

    The most common industrial use locking mechanism would either be the Strike lock or the Bolt lock. Both locks are electric controllable thru the power of a coil. The main difference is the mechanical part where the bolt lock shoots a bolt into the doorframe when locked, while the strike lock disables you to pull the door without lowering the lever.
    The difference also means that if you have a door where the lever can’t be locked, you can’t use the strike lock.

    If you are really up to this project and are going to utilize it for real, I won’t recommend you to go for any DIY servo solution. The strike or bolt lock is the correct and most secure industrial way – and they aren’t actually that expensive!

    Best Regards
    Thomas Jespersen

  35. June 28th, 2012 at 20:50 | #35

    Hello there,

    I enjoy the presentation and I wanted to learn this maybe think of another way to do something and I would like to know which kits that I have to buy and where can I get the kits so I can try this.

    Thank you for your help and assistance…

  36. July 4th, 2012 at 11:51 | #36

    @Ghislain
    To redo this project you should get the following electronics components together with a door with a rotating door-lock-mechanism:
    Arduino Duemilanove or UNO
    – TowerPro SG-5010 from Sparkfun รข?? Servo รข?? Large
    Serial RFID reader from Parallax

  37. clymment
    August 20th, 2012 at 03:57 | #37

    hi. i’m very interested on this project but it’s really hard for us to build, we kind of new on this sort of things. can you show us the circuit for this project please. really helpful thanks.

  38. clymment
    August 20th, 2012 at 04:06 | #38

    and can you list the materials that you guys use for this project. it’s really helpful thanks guys.

  39. August 23rd, 2012 at 10:44 | #39

    @clymment
    I have listed the materials in my comment response to Ghislain just above yours.
    The connections are very simple as there is nothing big in this project.

    For the Servo you should connect +5V and GND to it and the Signal wire should be connected to the Arduino pin 3.
    The Serial RFID reader board from Parallax that we are using is connected to the Arduino with two pins, the RFID SOUT pin goes to the Arduino serial RX pin (pin 0), and the RFID /enable pin goes to the Arduino pin 2.

    Best of luck with the project.

  40. clymment
    September 21st, 2012 at 10:02 | #40

    thanks for the tips. and one more thing can i use 125Khz RFID module RDM6300 – UART for the rfid reader.?

  41. September 24th, 2012 at 18:36 | #41

    @clymment
    Yes, you should definitely be able to use that.
    But I think you have to change the parts about start bit and end bit to match the output of the module.

  42. Bruno
    October 14th, 2012 at 17:03 | #42
  43. October 15th, 2012 at 23:44 | #43

    @Bruno
    Your module is a bit different as it uses SPI for communication while our used UART.
    See the Arduino reference about SPI for more information: http://arduino.cc/en/Reference/SPI

    Notice that the sensor is running at 3.3V, so you properly have to use a logic level converter like this one from Sparkfun: https://www.sparkfun.com/products/8745, so you wouldn’t damage the module, as the normal Arduino is running at 5V.

  44. Bruno
    October 16th, 2012 at 02:07 | #44

    Thanks for the reply.
    but the arduino provides voltage of 3.3 V, the example code provides that the seller is very hard to understand.
    Do you think your code would work together with my rfid module ?
    Thank you.

  45. October 16th, 2012 at 22:50 | #45

    @Bruno
    Just because it provides a 3.3 voltage source doesn’t mean it’s running at 3.3V. What Arduino are you using?
    Yes the structure of the program will work, but the communication for your module is very different.

  46. Bruno
    October 17th, 2012 at 00:55 | #46

    I’m using the arduino mega.

  47. October 17th, 2012 at 10:55 | #47

    @Bruno
    Okay, then it’s running at 5V. You will have to use a logic level converter so you don’t damage your module.

  48. Garrett
    October 18th, 2012 at 20:59 | #48

    This is a great project! I am writing a tutorial about a similar project. Would you mind if I posted your code on my tutorial? I will also leave a link to this blog if you will let me post it.

  49. October 18th, 2012 at 21:07 | #49

    @Garrett
    Hi Garrett. No, definitely not, it will not be any problem.
    As long as you keep a trackback to this post you are more than welcome to use and publish the code.

  50. Garrett
    October 19th, 2012 at 03:23 | #50

    Ok, thanks! I don’t know when I will get around to posting the tutorial, but I will make sure to leave a link.

  51. Sam
    November 26th, 2012 at 11:45 | #51

    Hello!! I think it is very interesting for me, i have an arduino uno with MF522-AN 13.56 MHz.
    I read the code you did it before. Do you think it is possible for me to use it?
    My arduino can provide 3.3V??
    The codes would be change a lots??

  52. November 29th, 2012 at 21:35 | #52

    @Sam
    You have to change the part which reads from the RFID module, as the one we used works via UART, but you can use the rest of the code without modification.

  53. November 29th, 2012 at 21:40 | #53

    @Sam
    Please have a look at the following page with an Arduino project for the MF522 module: How to get started with the Mifare MF522-AN and Arduino

    Follow the guide on how to connect the module to the Arduino and then uncomment all the places where it says “Serial. ….so on” in the code to get some debugging information.

  54. anne
    January 11th, 2013 at 19:10 | #54

    my rfid card reader has no “enable pin”.
    i use RDM630 Proximity Reader.
    how can i connect the rfid to arduino?

  55. January 13th, 2013 at 22:57 | #55

    @anne
    If you don’t have any Enable pin you should just remove anything “RFID_Enabled_Pin” related. As long as your module is then enabled all the time it doesn’t matter.

    A quick search on Google lead me to this page which gives you a good explanation on how to get started with the RDM630 RFID module connected to an Arduino: http://blog.iteadstudio.com/play-rdm630-with-arduino/

    A bit more advanced tutorial with Interrupts on read can be found here: http://maniacbug.wordpress.com/2011/10/09/125khz-rfid-module-rdm630/

    Regards Thomas

  56. anne
    January 14th, 2013 at 17:23 | #56

    thanks:)
    the servo @ rfid works but the problem now is the display..
    it doesn’t show anything in the serial monitor..
    sorry,;):)i’m not good in programming…:D:D

  57. January 17th, 2013 at 22:45 | #57

    @anne
    Which kind of tutorial have you been following?

    You should be cautious about the serial monitor when you have connected the RFID reader to the Serial port (RX/TX).
    As the pins for the Serial monitor are the same pins as for the RFID board, connecting to the Arduino with your serial monitor in the same time will make the Arduino think that your inputs are actually data from the RFID module.

    Please have this in mind ๐Ÿ™‚

  58. jake vicary
    November 27th, 2013 at 08:34 | #58

    so what is the wiring diagram

  59. jake vicary
    November 27th, 2013 at 08:48 | #59

    the rfid reader that i have has 7 pins consisting of mso, sck, ss, mosi, gnd, 3.3v and rsst its a “mf522-an”. if you can help me out with this at all that would bea big help

  60. November 28th, 2013 at 05:38 | #60

    @jake vicary
    We used a UART based RFID reader, so the code is not directly compatible with your reader, as it is using SPI for communication.

    By doing a simple Google search I found the following blog post: http://www.grantgibson.co.uk/blog/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/, that might be helpful to you.

  61. Mohnnad
    May 23rd, 2014 at 22:07 | #61

    nice work
    but how did you connect the RFID with the arduino and can it work with NFC reader too??

  62. May 23rd, 2014 at 23:13 | #62

    @Mohnnad
    The RFID reader is connected to the RX pin of the Arduino as it transmits the read data thru UART.
    And no, the module we are using in this project doesn’t work with NFC.

  63. Rui Ferreira
    June 26th, 2014 at 14:51 | #63

    Hello,
    Can you please tell me how do you connect the servo with the lock?

  64. June 27th, 2014 at 15:08 | #64

    @Rui Ferreira
    To mount the servo motor to the locking-mechanism on the door we took one of the servo plates and glued it together with the rotating metal-part (in our door a cross) inside the door.
    So it will require you to dismantle the lock and modify it.

  65. Aamir
    March 20th, 2015 at 17:58 | #65

    i have a rc 522 rfid reader module and i am making a rfid security system.it is very similar to your door lock.so can you please write the code of the door lock,which can be processed by the rc522 and how to change a normal rfid tag into a master tag?
    Please answer me

  66. March 21st, 2015 at 16:05 | #66

    @Aamir
    Hi Aamir.
    We can indeed help you write the code for your lock to work with an Arduino and the rc522 but at a cost.
    Instead I would recommend you to have a look at the following already available Arduino library for the MFRC522 device: https://github.com/miguelbalboa/rfid

    Otherwise feel free to contact me.
    Good luck.

    Best Regards
    Thomas Jespersen

  67. Sonal
    May 22nd, 2015 at 09:42 | #67

    how did you connected the arduino with the rfid reader . what components did you used for that ? please provide all the connections and components list .

  68. June 12th, 2015 at 09:52 | #68

    @Sonal
    We are using the Parallax RFID module in this video: https://www.parallax.com/product/28140
    The module connects to the Arduino thru the Serial/UART port where read data is transmitted directly as bytes.
    Other than that we are just using a regular Servo motor connected to a PWM pin on the Arduino Uno.

  69. Favour
    July 27th, 2015 at 15:58 | #69

    Please can you list all the components you used are give the tutorial you followed please my final grade depends on it

  70. Favour
    July 28th, 2015 at 20:11 | #70

    Pls how did u connect the Led

  71. July 28th, 2015 at 23:58 | #71

    @Favour
    As mentioned in a previous post we are using the Parallax RFID module: https://www.parallax.com/product/28140
    Other than that we are just using a regular Servo motor connected to a PWM pin on the Arduino Uno.
    The LED itself can’t be individually controlled by corresponds to whether the module is enables or not (thru the enable pin). So we use the enable pin to exploit the changing of color on this LED.

  72. janko
    September 28th, 2015 at 09:42 | #72

    Can you give us schematichs for this project! I would like to use it for my door!

  73. September 28th, 2015 at 22:40 | #73

    @janko
    There is no schematics for this project.
    We simply use the Parallax RFID module connected to the UART port of the Arduino together with a servo motor connected to a PWM pin.
    Please read the previous comments for similar answers:
    http://blog.tkjelectronics.dk/2011/04/arduino-rfid-door-lock/#comment-548231
    http://blog.tkjelectronics.dk/2011/04/arduino-rfid-door-lock/#comment-551747

  74. Angelo
    October 6th, 2015 at 17:06 | #74

    i am planning on using magnetic lock instead of servo. can you help me to debug your codes. any help would be much appreciated. thank you

  75. jereel
    October 6th, 2015 at 17:13 | #75

    can i replace servo motor with magnetic lock? if possible, can you tell me how?

  76. October 6th, 2015 at 20:24 | #76

    To use a magnetic lock you would need some kind of high-current driver connected to the Arduino. The most easy way would be to use either just a transistor, depending on the magnetic lock current or a combination of a relay and transistor.

  77. jereel
    October 6th, 2015 at 21:16 | #77

    in terms of the program/codes, what should i remove and what should i replace it with? sorry for the bad grammar, english is not my mother tounge.

  78. jereel
    October 7th, 2015 at 22:37 | #78

    got so far in this project but when i use other power source for the arduino, instead of my laptop’s usb port, the RFID_enable pin is always set on high… tell me what cause this to happen

  79. October 8th, 2015 at 18:02 | #79

    @jereel
    Where is this RFID_enable pin connected?
    And which power source do you use for powering?
    Please have in mind that you are recommended to use between 9V to 12V.

  80. jereel
    October 9th, 2015 at 02:28 | #80

    nevermind… i found out that my problem occur because i have a different power source for the parallax. i already fixed the problem by connecting all the ground. thanks for the response. ^_^

  81. Arjay
    October 9th, 2015 at 02:36 | #81

    I have a question. In this part:

    else if (RFID_Master_Correct == true && RFID_SaveNextRead == true) {
    Serial.println(“Master Card Scanned again – Removing all saved Cards”);
    delay(1000);

    for (checkPosition = 0; checkPosition < 10; checkPosition++) {
    RFID_Slave1[checkPosition] = 0;
    }
    for (checkPosition = 0; checkPosition < 10; checkPosition++) {
    RFID_Slave2[checkPosition] = 0;
    }
    for (checkPosition = 0; checkPosition < 10; checkPosition++) {
    RFID_Slave3[checkPosition] = 0;
    }
    for (checkPosition = 0; checkPosition < 10; checkPosition++) {
    RFID_Slave4[checkPosition] = 0;
    }

    how can i delete a specific saved card instead of all saved cards?

  82. October 9th, 2015 at 09:11 | #82

    @Arjay
    You can do so by only including the clearing for-loop for the specific slave that you want to clear.
    Eg. only to clear the slave 1 you replace all the above lines with only:

    for (checkPosition = 0; checkPosition < 10; checkPosition++) {
      RFID_Slave1[checkPosition] = 0;
    }
  83. jhed20
    January 18th, 2016 at 17:56 | #83

    hi sir.. can u show us your circuit diagram ? please..

  84. January 18th, 2016 at 22:17 | #84
  85. Eme
    February 3rd, 2016 at 19:16 | #85

    Can this work with a MF522 RFID Reader? If not what has to change. If as I suspect, you might want a token to write the code how much will it cost? – Please reply I am desperate to have this.

  86. February 4th, 2016 at 22:17 | #86

    @Eme
    The MF522 RFID is SPI based, why the connection scheme would be different.
    The code could indeed be changed to use the MF522 module, though at first I recommend you to take a look at the following article: http://www.grantgibson.co.uk/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/

  87. Hunter
    April 24th, 2016 at 18:16 | #87

    Hello! I plan on attempting this project over the summer, but I would like to use the ID-12 from Sparkfun. I saw that someone above also used it and it worked (with slight modifications). I am confused if I would need the USB reader included in the RFID kit they have. The link below is the kit. RFID is fairly new to me, so I am unsure what ports to use as well, although I know it should be a fairly straightforward answer.

    https://www.sparkfun.com/products/13198

  88. Hunter
    April 24th, 2016 at 22:01 | #88

    After further investigation, I believe I do not need the USB reader after all. I believe I only need the ID-12 (or ID-20) for it to work. Is my suspicions correct? However, I am still not sure what pins to use in conjunction with your code. I have attached the datasheet link below; Thank you! The pin assignments are on page 3 with description on page 6.

    http://cdn.sparkfun.com/datasheets/Sensors/ID/ID-2LA,%20ID-12LA,%20ID-20LA2013-4-10.pdf

  89. April 25th, 2016 at 21:54 | #89

    @Hunter
    It is indeed correct that you do not have to use the USB reader when you want to interface and use the ID-12 or ID-20 unit with your microprocessor-based project.
    Please read about how I used an ID-12 reader with an Arduino to read EM-Marine RFID cards: http://blog.tkjelectronics.dk/2009/06/rfid-modded-safe/

  90. December 10th, 2016 at 12:51 | #90

    Hi Greate job, doing well and this information is worth for anyone who unknown for the rfid door lock. I am sure that this door lock is better than other.

  91. Christian Jude
    January 20th, 2017 at 09:25 | #91

    Hi, this is very awesome.I have only one question how did you customize the door lock?. I want to make a project like this but I don’t have the idea and the schematics. could you share you idea how did you do this and the hardware.thank you very much.

  92. January 24th, 2017 at 23:16 | #92

    @Christian Jude
    We simply made a bracket to allow a standard 5V servo motor to be attached to a regular mechanical turnable door lock knob.
    Although the video shows a working prototype I would probably not recommend this for final and secure applications.

    Instead I would recommend to take a look at the electronic bolt locks that can be found on eg. eBay: http://www.ebay.com/bhp/electric-bolt-lock
    These locks are solenoid-based bolt locks which offers a higher reliability.

    Or as an alternative would be the electronic strike lock: http://www.ebay.com/bhp/electric-door-strike

  1. No trackbacks yet.