Automatic Door Lock Using RFID

About: An Electronics engineer and a hobbyist. I love to keep experimenting with microcontrollers.

Hello guys and welcome to a brand new instructable. In one of my previous instructable I made an automatic door lock mechanism using IR sensors. And today I decided to upgrade that project with a RFID sensor. The last version of this project did not have any method of securing the door (i.e anyone could enter in and out). So adding an RFID will help us restrict people from entering the door. Only one's having valid tags will be granted access inside. Let's build this project !!!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Gather the Supplies

Getting electronics supplies online can be a bit worrisome because you do not know if the components / modules you purchased are in working condition or not. So to erase these doubts I recommend for buying the components. They provide high quality components at affordable rates and deliver them at your door step in good condition. Also if you are a maker or hobbyist, do check their PCB Service. You can get up to 16 layers of PCB's designed that too at affordable rates.

Things we need to make this project are -

1. Arduino Uno Board

2. Old DVD Writer (working)

3. SMPS to power the DVD Writer

4. Bread Boards

5. RC 522 RFID Module

6. Relay Module

7. IR Sensor

8. Connecting Wires

Step 2: Circuit Diagram

Make all the connections as shown in the diagram above.

If you want to see how I modified the DVD Writer to make it work with the Arduino then Click Here .

The IR sensor gives the status of the door's open or closed state.

As we bring the correct RFID card in the readers proximity the door opens. It will stay open for a short time and then close again. But let's assume that a person entered by using the correct tag and now he wants to come out. This could be achieved using another RFID module at the inside but I went on with a easy method.

I gave a switch in the inside to open the door. This will help the person to get outside.

Step 3: Coding

The code for this project is given below. But before uploading the code you will have to find the Tag number of your RFID Tag. And to do that check out this instructable >> Click Here .

Now change the UID in the code below and upload it to your Arduino Board.

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10 #define RST_PIN 9 const int Relay = 4; const int sen1 = 2; const int SW = 5; int buttonState = 0; int val1; MFRC522 mfrc522(SS_PIN, RST_PIN); void setup() { digitalWrite(Relay, HIGH); Serial.begin(9600); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 pinMode(Relay, OUTPUT); pinMode(sen1, INPUT); pinMode(SW, INPUT); digitalWrite(Relay, HIGH); delay(250); digitalWrite(Relay,LOW); delay(250); digitalWrite(Relay,HIGH); delay(250); digitalWrite(Relay,LOW); digitalWrite(Relay,HIGH); delay(250); digitalWrite(Relay,LOW); } void loop() { val1 = digitalRead(sen1); Serial.println("SEN1"); Serial.println(val1); buttonState = digitalRead(SW); Serial.println("Button"); Serial.println(buttonState); { if (val1 == HIGH && buttonState == HIGH) { digitalWrite(Relay, HIGH); delay(250); digitalWrite(Relay,LOW); delay(4000); digitalWrite(Relay,HIGH); delay(250); digitalWrite(Relay,LOW); } else { digitalWrite(Relay, LOW); } rfid(); } } void rfid() { if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } if ( ! mfrc522.PICC_ReadCardSerial()) { return; } String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } content.toUpperCase(); int val1 = digitalRead(sen1); if (val1 == HIGH && content.substring(1) == "F4 90 E0 1F") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); digitalWrite(Relay,HIGH); delay(250); digitalWrite(Relay,LOW); delay(4000); digitalWrite(Relay,HIGH); delay(250); digitalWrite(Relay,LOW); } else { Serial.println("Unauthorized access"); } }

The .ino file for this code is given below. You can directly download it.

If you have any trouble with the code then please drop a comment below. I will try my best to answer your queries.

Step 4: Working Video

If you want to see how this project works then watch the video I attached in this section. I also attached a .gif file here for your convenience. If you like my work then please support by sharing this instructable. Also follow me here to see my upcoming projects. So that's it for today see you soon with another project.

Be the First to Share


    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest