RFID Door Access System | Arduino DIY Project

Hey everyone! Welcome back to Mahade DIY!
In today’s article, I’m going to show you how to make your own RFID Door Access System using an Arduino.
This project allows you to unlock a door using an RFID card — just like in hotels, offices, and other secure areas!
Let’s get started and see how it’s built.

Pins of RFID Reader Module

VCC/3.3VThe power pins are VCC. In some versions of RC522, this pin is denoted by 3.3V on the module instead of VCC.
RSTIt’s a reset pin for the module. Therefore, it uses to reset the device in case of an error on when a device isn’t giving any response.
GNDGround helps to make the common ground with every external device, e.g. power Supply, Microcontroller or Arduino.
IRQThe device can go into sleep mode to save power. So, the IRQ helps to wake it.
MISOThis pin connects with the Arduino/Microcontrollers for SPI communication. However, it transfers the data from module to Arduino.
The MISO pin is also useable for other functions instead of SPI.
It can also interface with I2C for clock pulse and UART Serial for Data transfer from the module.
MOSIMOSI is the data input pin for RFID module in SPI communication
SCKThe SCK pins help to send the clock pulse in SPI communications.
SDAThe SS pin is a chip enable pin in SPI communication. Therefore, it receives the signal when Master (Arduino) must perform SPI communication.
The SS pin in RFID is useable as a second pin (SDA) for I2C communication.
It also receives data during UART communication.

Components need for this Project

Let’s take a look at the components we’ll need for this project:

  • Arduino Uno microcontroller board, which will act as the brain of the project.
  • RFID Reader Module
  • 16×2 LCD Display with an I2C Adapter
  • small breadboard.
  • 5V Relay Module
  • DC female and male jack
  • RFID cards/Tags
  • 12V Solenoid Door Lock
  • Jumper wires — both male-to-male and male-to-female

Gather all the components, and let’s start wiring the circuit step by step. Follow the connections carefully.

Hook up with Arduino

Connecting the RFID Reader to the Arduino:

  • Connect the RFID reader 3.3V pin to the Arduino 3.3V power pin
  • Connect the RST pin to Arduino Digital Pin 9
  • Connect the GND pin to Ground.
  • Connect MISO to Digital Pin 12
  • MOSI to Digital Pin 11
  • SCK to Digital Pin 13
  • SDA to Digital Pin 10

We need 5V and GND for both the LCD and the Relay, so we’ll make some extra power lines on the breadboard by connecting 5V and GND from the Arduino.

Connecting the LCD Display (via I2C interface):

  • LCD GND → Arduino GND
  • LCD VCC → Arduino 5V
  • LCD SDA → Arduino Analog Pin A4
  • LCD SCL → Arduino Analog Pin A5

Connecting the Relay Module:
The relay will act as a switch to control the 12V solenoid door lock.

  • Relay GND → Arduino GND
  • Relay VCC → Arduino 5V
  • Relay Input Signal → Arduino Digital Pin 7

Connecting the Power Supply:
Finally, connect the power supply adapter through the DC jack.
The Arduino is powered via the DC male jack, and another line goes to the relay and solenoid lock for 12V.
The ground connects directly to the solenoid’s negative wire.
The 12V positive from the power supply goes through the relay’s normally open (NO) and common (COM) terminals.
If you’re using a low-level trigger relay, connect it through the normally closed (NC) and common (COM) terminals instead.

Software

Arduino IDE

Step 1: Download the Arduino IDE software from the link.

Arduino IDE download link: https://www.arduino.cc/en/software

Step 2: Include two Libraries

Arduino RFID Library for MFRC522 : Click Here
Liquid Crystal Display Arduino library: Click Here

Download .ZIP file of these two libraries and add them like bellow

Coding

Coding part 1: upload a simple program to read the unique ID (UID) of the RFID card

Step 1: Include two libraries in your Arduino IDE — one for the LCD and another for RFID.
Download both ZIP libraries from the provided links. Then go to:
Sketch → Include Library → Add .ZIP Library, select the ZIP file, and click Open.
Repeat the process for the second library.

Step 2: Select your board.
Go to Tools → Board → Arduino AVR Boards → Arduino Uno (or select the board you’re using).

Step 3: Select the correct port.
Go to Tools → Port and choose the port your Arduino is connected to.

After completing these three steps, upload the code.


//RFID tag scan code
//Youtube Channel : Mahade DIY
// Ask me if you face any problem to your project

 

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN  10
byte readCard[4];
byte a = 0;

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  while (!Serial);
  SPI.begin();
  mfrc522.PCD_Init();
  delay(4);
  mfrc522.PCD_DumpVersionToSerial();
 
 Serial.print("Scan your card");
}

void loop() {
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return 0;
  }
  a = 0;
  Serial.println(F("Scanned PICC's UID:"));
  for ( uint8_t i = 0; i < 4; i++) {  //
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
    Serial.print(" ");
  
    delay(500);
    a += 3;
  }
  Serial.println("");
  mfrc522.PICC_HaltA();
  return 1;
}


When the upload is complete, open the Serial Monitor — you’ll see the card ID appear whenever you tap your RFID card on the reader.

Copy that card ID; we’ll need it for the next step.

Let’s assume we have a card which has UID = 83 B9 BE 18

Coding Part 2: Door access code

Step 1: Open a new sketch. Copy the following code and paste in the sketch.


//RFID door lock code
//Youtube Channel : Mahade DIY
// Ask me if you face any problem to your project
 

#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
String UID = "83 B9 BE 18";
byte lock = 1;

const int RELAY_PIN = 7;

LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 rfid(SS_PIN, RST_PIN);


void setup() {
  Serial.begin(9600);
   pinMode(RELAY_PIN, OUTPUT);

  lcd.init();
  lcd.backlight();

  SPI.begin();
  rfid.PCD_Init();
}

void loop() {
  lcd.setCursor(4, 0);
  lcd.print("Welcome!");
  lcd.setCursor(1, 1);
  lcd.print("Put your card");

  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scanning");
  Serial.print("NUID tag is :");
  String ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    lcd.print(".");
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
    delay(300);
  }
  ID.toUpperCase();

  if (ID.substring(1) == UID && lock == 0 ) {
   
    digitalWrite(RELAY_PIN,LOW);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Door is locked");
    delay(1500);
    lcd.clear();
    lock = 1;
  } else if (ID.substring(1) == UID && lock == 1 ) {
    
    digitalWrite(RELAY_PIN,HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Door is open");
    delay(1500);
    lcd.clear();
    lock = 0;
  } else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Wrong card!");
    delay(1500);
    lcd.clear();
  }
}

Check the copied ID pasted into the following line of the code

String UID = “83 B9 BE 18“;


This code checks whether the scanned card matches the stored ID.

After uploading the final code, your system is ready for testing!

Now you can disconnect the Arduino from your computer and use the 12V power adapter instead.


Conclusion


First, scan an unauthorized card.
You could see, the system correctly denies access.

Now, scan the authorized RFID card.
The relay activates, unlocking the door.
To lock the door again, simply scan the same card once more.

Here’s what’s happening behind the scenes:
When you place the RFID card near the reader, it sends the card’s unique ID to the Arduino.
The Arduino checks if that ID matches the one stored in the code.
If it matches, the relay is triggered, unlocking the door.


Check out the step-by-step tutorial on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *