If you buy something from a this link, myelectricsparks Media may earn a commission. See our Read More.

For better understanding in this Article, the Servo Motor is used for opening and closing of the gate. If you want a professional setup then use Solenoid Door Lock or an Electromagnetic door lock. If you had limited expenses then use a Solenoid Door Lock.
Outline
[lwptoc colorScheme=”dark”]Introduction
• AUTHORIZATION:
• ELECTRONIC ACCESS CONTROL (EAC):
Anatomy of Access Control System using the RC522 RFID module
- 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
Main RFID Scanner,
Or Reader Module attached with PCB.
Smart Card Antenna ???? Key Fob ( both from MIFARE 1K Classic).
Soon there will be a dedicated Article on Interfacing RC522 RFID MODULE with Arduino.
MG 996R Servo Motor
NOTE:
Now, install a separate power supply for servo but make sure the the ground is same between the external power supply and Arduino.
PCF8574 I2C LCD Module
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
Components Required for Access Control System using the RC522 RFID module
RC522 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
Prerequisites for Access Control System using the RC522 RFID module
Install Libraries
UID of Master Card(s)
Slave Address for I2C LCD Module
At Last, Using an I2C LCD Module with 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 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
#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 of Access Control System using the RC522 RFID module
The LCD displays ‘Access Granted’ message and also the UID of the card.
When the key fob is scanned and the Servo remains in the closed position when it is not a master card.
An ‘Access Denied’ message is displayed on the LCD.
Conclusion
About Author
Aizaz khan
Aizaz was the first person to get a byline on his blog on technology from his home in Bannu in 2017. Then, he went on to a career in breaking things professionally at my electric sparks which is where he eventually took over the kit as a hardware editor. Today, as the senior editor of hardware for my electric sparks, he spends time reporting about the most recent developments in the hardware industry and technology. If he’s not reporting on hardware or electronics, you’ll see him trying to be as remote from the world of technology as possible through camping in the wild.