Door Security System Using RFID RC522 and Arduino

Door Security System Using RFID RC522 and Arduino:  This  Arduino based project is about how to interface RC522 RFID module with Arduino and how used to it design door security system. Before starting this project, I recommend you to check Arduino programming and Arduino tutorials list written for complete beginners. Door Security System is used to stop the unauthorized person to get access to a room or a building. Such system is very useful if you have important data, information, and researchers stored in a computer or in the bundle of files.

Such security system is very useful in Military, Research Centers, Banks, Server rooms, Jails, Government offices and Nuclear Plants. This system prevents a large destruction and loss.The project is based on RFID RC522 module; don’t know about RFID RC522 module I will explain later. Arduino Uno is the brain of this project.  LCD is used to display messages. Servo motor is used to indicate that the door is opening or closing.

Block Diagram of Door Security System Using RFID RC522 Door Security System Using RFID RC522 and Arduino block diagram

Components Required for Door Security System Using RFID RC522

  • Arduino Uno: I use Arduino Uno in my project because it is easy to use and very cheap in price. It also fits in my project as I need 12 digital pins and 3.3v for RFID module. If you want to learn more about Arduino Uno visit: Getting start with Arduino tutorial 
  • Servo Motor: In this project servo motor is used to indicate that the door is opening and closing. It is easy to use and program and also provide precise movement. Learn more about servo at servo motor interfacing with Arduino
  • 16×2 LCD: LCD is used to show Text and special characters. It has total 16 pins. A 10K ohm potentiometer is connected with pin three to set the contrast of the LCD. It also contains a backlight LED. In this project LCD, we use is capable of display 16 characters in two lines. In this project, LCD is used to show messages
  • RFID RC522: This module is based on MFRC522 IC which is used in contactless communication. It is used as both reader and writer. This module contains eight pins. The pins description are as follow:

Pins Description RFID RC522

  1. SDA: I2C-bus serial data line input/output.
  2. SCK: SPI serial clock input.
  3. MOSI: SPI master out, a slave in.
  4. MISO: SPI master in, slave out.
  5. IRQ: Interrupt request output, indicates an interrupt event.
  6. GND: Ground.
  7. RST: reset and power-down input.
  8. 3V: power supply of 3.3 volts.

This module is cheap in price and very easy to use is a project. Its operation voltages are 3.3v and draw up to 40mA current.

  • Suitable resistors for LCD (10K ohms in my case) and jumper wires for connections

Circuit Diagram of Door Security System Using RFID RC522 and ArduinoDoor Security System Using RFID RC522 and Arduino circuit diagram

Connections  for Door Security System Using RFID RC522 and Arduino

RFID RC522 module to Arduino connections

  • SDA to D10
  • SCK to D13
  • MOSI to D11
  • MISO to D12
  • IRQ is not use
  • GND to GND
  • RST to D9
  • 3.3V to 3.3V

16×2 LCD to Arduino connections:

  • RS o D7
  • Enable to D6
  • D4 to D5
  • D5 to D4
  • D6 to D3
  • D7 to D2
  • R/W to ground
  • VSS to ground
  • VCC pin to 5V

Servo to Arduino Connection

  • Starting from left
  • Pin 1 to ground.
  • Pin 2 to 5V.
  • Pin 3 to D8.

Working of Door Security System Using RFID RC522

When the user brings the token near the module it detects the token and read its value. If the value is same as defined in the code then Access Granted message is shown on LCD and it opens the door for the user. After some delay which is also defined in the code the door automatically closes. This process occurs every time the user wants to access. There can be multiple user but each user has it unique token.

Code

#include <deprecated.h>
#include <MFRC522.h>
#include <MFRC522Debug.h>
#include <MFRC522Extended.h>
#include <MFRC522Hack.h>
#include <require_cpp11.h>
#include<RFID.h>
#include <SPI.h>
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
#define val0 117 // chnage the value according to token no
#define val1 134
int pos = 0;
/* Define the DIO used for the SDA (SS) and RST (reset) pins. */
#define SDA_DIO 10
#define RESET_DIO 9
RFID RC522(SDA_DIO, RESET_DIO);

void setup()
{ 
myservo.attach(8); 
Serial.begin(9600);
/* Enable the SPI interface */
SPI.begin(); 
/* Initialise the RFID reader */
RC522.init();
lcd.begin(16, 2);

}

void loop()
{
byte i=0;
int ID;
if (RC522.isCard())
{
RC522.readCardSerial();
Serial.println(RC522.serNum,DEC);
Serial.println("Card detected:");
ID=RC522.serNum;}
delay(500);
if( val0 == ID)
{ lcd.clear();
lcd.print("Access Granted");
lcd.setCursor(0, 1);
lcd.print("Welcome Haris");
delay(1800); 
lcd.clear();
lcd.print("Door Opening");
delay(1500);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(5000);
lcd.clear();
lcd.print("Door Closing");
delay(1500);
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
} 
else
{
lcd.clear();
lcd.print("Door Security ");
lcd.setCursor(0, 1);
lcd.print("System ");
}
if( val1 == ID)
{ lcd.clear();
lcd.print("Access Granted");
lcd.setCursor(0, 1);
lcd.print("Welcome Bilal");
delay(1800); 
lcd.clear();
lcd.print("Door Opening");
delay(1500);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(5000);
lcd.clear();
lcd.print("Door Closing");
delay(1500);
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
} 
else
{
lcd.clear();
lcd.print("Door Security ");
lcd.setCursor(0, 1);
lcd.print("System ");
}
}

Implementation of Door Security System Using RFID RC522Door Security System Using RFID RC522 and Arduino

Video

4 thoughts on “Door Security System Using RFID RC522 and Arduino”

Leave a Comment

shares