This Article is a complete guideline for creating an Access Control System using the RC522 RFID module, Arduino, and MG 996R Motor.
It helps people to open and close the gate by using an RFID Smart Card or Key Fobs.
For a better understanding of this Article, the Servo Motor is used for opening and closing of the gate. If you want a professional setup, then use a Solenoid Door Lock or an Electromagnetic door lock. If you have limited expenses, then use a Solenoid Door Lock.
Introduction
Before moving forward toward an Access Control System using the RC522 RFID module, let’s know what Access Control is.
In the infield of security, Access Control is an essential technology in which a person may have restricted access to enter (Source). They might use a key or code to grant access.
• AUTHORIZATION:
It is the process of verification and granting access to the resources.
• ELECTRONIC ACCESS CONTROL (EAC):
This process is one of the easiest and simplest systems used by computers to get rid of physical locks and keys.
It has three types of authentication. They are given below:
• Using Smart locks with a keypad to Enter PIN or Password.
• Scanning Smart Card or Key Fob.
• Using a Biometric system. For example, eye scanning, fingerprint, or face scan.
In this Article, the simple DIY Project rules are applied, and an RFID-based Access Control System is constructed to identify the person using Smart Card and Key Fobs.
NOTE: If you want to use the best soldering techniques, then visit our Soldering category for an interesting and cheap buying guide
Anatomy of Access Control System using the RC522 RFID module
Mostly, the Access Control System is constructed from the following components as few instruments are required to install this system. However, the differences and complexity in the Control System may arise from System to System.
- Controller: A Microcontroller or Microprocessor has the capability of scanning (Source).
- Controlled Entry: It means a place for installation, like a door or gate.
- Scanner/ Reader: A device used for saving input from a user. For example, fingerprint scanning, password, or RFID Scanner.
- Locking Mechanism: Just like a solenoid door lock.
Component Description for Access Control System using the RC522 RFID module
RC522 RFID Module
The cheapest and most reliable RFID Module for Arduino is the MFRC522 IC-based RC522 RFID Module (Source).
The kit carries the following components:
- Main RFID Scanner,
- Or Reader Module attached with PCB.
- Smart Card Antenna Key Fob ( both from MIFARE 1K Classic).
Article on Interfacing RC522 RFID MODULE with Arduino. Must check it out.
MG 996R Servo Motor
Before moving forward, first know about what is MG 996R Servo Motor.
Tower Pro’s MG 996R is a digital metal gear servo device with the highest install torque of 9.4 kg. Cm. It can rotate up to 120 degrees by rotating 60 degrees on each side.
NOTE:
Never charge the MG 996R Servo Motor from Arduino as the present current value is very high, usually for 6V (Source), and the power supply is between 500mA and 900mA. The value of the current depends on the applied load and can reach 2.5A ( at 6V).
Now, install a separate power supply for the servo, but make sure the ground is the same between the external power supply and Arduino.
PCF8574 I2C LCD Module
The most used and beneficial Module available for Arduino is the PCF8574 I2C LCD MODULE (Source). It works as converting a regular 16×2 LCD Display into an I2C interfaced device so that the display is controlled just by two wires (SDA and SCL of I2C).
Soon, there will be a dedicated Article on Interfacing PCF8574 I2C LCD with Arduino. Must read it out, then.
Arduino RC522 RFID Module-based Access Control System
For this project construction, Arduino UNO is selected as the main controller, and for user input acceptance, the RC522 RFID Module is used. For credentials purposes, users will be given RFID Smart Cards and Key Fobs.
Then, for displaying relevant text for users, the 16×2 LCD with PCF8574 I2C LCD Module will be attached to Arduino.
SPI Interfacing connection is used between Arduino and RC522 RFID Module, but for communication purposes, the I²C Interfacing is used between Arduino and PCF8574 I2C LCD Module.
Attached is the Servo Motor to the PWM pin of Arduino, which provides an external power supply for the MG 996R Servo Motor.
Components Required for Access Control System using the RC522 RFID module
- Arduino UNORC522 RFID Module
- RFID Smart Card
- RFID Key Fob
- MG 996R Servo Motor
- 16×2 LCD Display
- PCF8574 I2C LCD Module
- Breadboard
- Breadboard Power Supply
- Connecting Wires
Circuit Diagram
The given diagrams present all important information and connections for the Arduino RC522 RFID Module based on the Access System.
Prerequisites for Access Control System using the RC522 RFID module
First, prepare for a few important things for the build-up of Arduino and RC522 RFID Module based on the Access Control System, then move on toward the construction.
Install Libraries
The very first is to install all the important Libraries. If they are already installed, that’s very good. Then, if not, then install them. For the construction of the RC522 RFID Module-based Access Control System using Arduino, the mentioned Libraries are needed;
- SPI
- MFRC522
- Servo
- LiquidCrystal_I2C
For this project, the first and third Libraries are already installed with Arduino IDE. Install the other two as well.
UID of Master Card(s)
The Next component needed is a Unique ID ( UID). Create master cards that will have permission to access to open and close gates, doors, etc. For the creation of Master Card and key fobs, use the ‘DumpInfo’ example from the “MFRC522 ” library.
Slave Address for I2C LCD Module
Lastly, Using an I2C LCD Module with a 16×2 LCD Display, the value of the I2C address of the PCF8574 IC is known now. Connect only the PCF8574 I2C Module to Arduino (through the I2C bus) and use the given codes to get the slave address.
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial);
}
void loop()
{
byte error, address;
int I2CDevices;
Serial.println("Scanning for I2C Devices…");
I2CDevices = 0;
for (address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address < 16)
{
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
I2CDevices++;
}
else if (error == 4)
{
Serial.print("Unknown error at address 0x");
if (address < 16)
{
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (I2CDevices == 0)
{
Serial.println("No I2C devices found\n");
}
else
{
Serial.println("****\n");
}
delay(5000);
}
Code for Access Control System using the RC522 RFID module
Now, the project is ready for the Arduino RC522 RFID Module-based Access Control System, main code. The code is the simplest one and also creates a list of all master cards that will have access.
Now, scan the RFID card using the RC522 RFID module, which has a connection with Arduino. When the spanned card’s UID is matched, then activation of MG 996R Servo will take place, and “welcome” text will appear on the LCD, and the gate or door will be opened.
But in case the case is not matched with the list, then none of the above processes will take place, and the denied text will appear on the LCD.
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
/*Using Hardware SPI of Arduino */
/*MOSI (11), MISO (12) and SCK (13) are fixed */
/*You can configure SS and RST Pins*/
#define SS_PIN 10 /* Slave Select Pin */
#define RST_PIN 7 /* Reset Pin */
#define SERVO_PIN 9 /* Servo Pin - Must be a PWM Pin */
/* Use 'DumpInfo' example in MFRC522 Library to get RFID Card's UID */
/* Replace the following with your RFID UID */
/* Do not put 0's */
/* In my case, UID is F3 9E 3D 03 */
/* So, I put F39E3D3, without any 0's and spaces */
String masterTagID = "F39E3D3";
/* Create a string to capture scanned card's UID */
String scanTagID = "";
/* Create an instance of Servo */
Servo myservo;
/* Create an instance of MFRC522 */
MFRC522 mfrc522(SS_PIN, RST_PIN);
/* Create an instance of LiquidCrystal_I2C */
/* LiquidCrystal_I2C lcd(Slave Address, # of Columns, # of Rows); */
LiquidCrystal_I2C lcd(0x3F, 16, 2);
/* Custom Character for Happy Face */
byte customCharGranted[] = {
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000
};
/* Custom Character for Frown Face */
byte customCharDenied[] = {
B00000,
B00000,
B01010,
B00000,
B00000,
B01110,
B10001,
B00000
};
void setup()
{
/* Initialize LCD */
lcd.init();
lcd.backlight();
/* Store Custom Characters into ROM of LCD */
lcd.createChar(0, customCharGranted);
lcd.createChar(1, customCharDenied);
lcd.setCursor(0,0);
lcd.print(" RC522 RFID ");
lcd.setCursor(0,1);
lcd.print(" Access Control ");
/* Initialize Servo */
myservo.attach(SERVO_PIN);
/* Set initial position of Servo */
/* In this position, the gate is closed */
myservo.write(90);
/* Initialize SPI Bus */
SPI.begin();
/* Initialize MFRC522 Module */
mfrc522.PCD_Init();
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("*Scan Your Card*");
}
void loop()
{
while (readTagID())
{
lcd.clear();
lcd.setCursor(0, 0);
if (scanTagID == masterTagID)
{
lcd.print("Access Granted ");
lcd.write(0);
lcd.setCursor(0, 1);
lcd.print("Welcome: ");
lcd.print(scanTagID);
/* Open the gate */
myservo.write(20);
}
else
{
lcd.print("Access Denied ");
lcd.write(1);
lcd.setCursor(0, 1);
lcd.print("Get Out: ");
lcd.print(scanTagID);
//myservo.write(90);
}
delay(3000);
/* Close the gate after a delay of 3s */
myservo.write(90);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("*Scan Your Card*");
}
}
boolean readTagID()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return false;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return false;
}
/* Clear the string */
scanTagID = "";
for ( uint8_t i = 0; i < 4; i++)
{
scanTagID += String(mfrc522.uid.uidByte[i], HEX);
}
scanTagID.toUpperCase();
mfrc522.PICC_HaltA();
return true;
}
Working on an Access Control System using the RC522 RFID module
Arduino will command ” Scan your Card ” on the LCD. Then Arduino will display the text ” ready for scanning RFID cards. If you had programmed the RFID card as the master card only, then the key fobs will not work on it as it doesn’t have access to it.
When the RFID card is scanned, the Servo will get activated, which will open the gates or unlock a door.
The LCD ‘Access Granted’ message and also the UID of the card.
When the key fob is scanned, the Servo remains in the closed position when it is not a master card.
An ‘Access Denied’ message is displayed on the LCD.
Conclusion
This article is based on a simple DIY Project that is demonstrated using Arduino, RC522 RFID Module, MG 996R Servo, PCF8574 I2C LCD Module, and a few RFID Smart Cards and Key Fobs.
If you read the article with full attention, then you will be able to understand the required components, and you will be able to implement the Arduino RC522 RFID Module-based Access Control System.
For any difficulty, comment down below and also give us feedback about our article.