ArduinoIntermediate

RFID Access Control with RC522 and Arduino

Build a secure door lock system using RFID tags and the MFRC522 module.

1 April 202612 min read

Introduction

RFID (Radio Frequency Identification) uses electromagnetic fields to identify and track tags. The RC522 module is an affordable way to add RFID to your projects.

Wiring (SPI)

RC522 PinArduino Uno Pin
SDA (SS)10
SCK13
MOSI11
MISO12
IRQNot Connected
GNDGND
RST9
3.3V3.3V

Warning: RC522 operates at 3.3V. Connecting to 5V will damage it!

Libraries

Install MFRC522 by GithubCommunity in Library Manager.

The Code

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

#define RST_PIN 9
#define SS_PIN 10

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Scan your RFID card...");
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) return;
  
  Serial.print("Card UID:");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();
  mfrc522.PICC_HaltA();
}
Tags:ArduinoRFIDSecuritySPI