The RFID-RC522 is a compact and cost-effective RFID reader/writer module that operates at a frequency of 13.56 MHz. It is designed for reading and writing RFID tags and cards, making it an essential component for wireless communication in various applications. The module is widely used in access control systems, inventory management, and identification systems due to its reliability, affordability, and ease of integration.
The RFID-RC522 module has 8 pins, as described in the table below:
Pin Name | Pin Number | Description |
---|---|---|
VCC | 1 | Power supply input (3.3V). |
RST | 2 | Reset pin. Active LOW. Used to reset the module. |
GND | 3 | Ground connection. |
IRQ | 4 | Interrupt pin. Can be used to signal events to the microcontroller. |
MISO/SCL/TX | 5 | SPI MISO (Master In Slave Out) / I2C Clock / UART TX (default: SPI MISO). |
MOSI/SDA/RX | 6 | SPI MOSI (Master Out Slave In) / I2C Data / UART RX (default: SPI MOSI). |
SCK | 7 | SPI Clock input. |
NSS/SDA | 8 | SPI Chip Select (NSS) / I2C Address Select (default: SPI NSS). |
SCK
to Arduino pin 13MOSI
to Arduino pin 11MISO
to Arduino pin 12NSS
to Arduino pin 10RST
to Arduino pin 9#include <SPI.h>
#include <MFRC522.h>
// Define pins for the RFID-RC522 module
#define RST_PIN 9 // Reset pin connected to Arduino pin 9
#define SS_PIN 10 // Slave Select pin connected to Arduino pin 10
MFRC522 rfid(SS_PIN, RST_PIN); // Create an instance of the MFRC522 class
void setup() {
Serial.begin(9600); // Initialize serial communication
SPI.begin(); // Initialize SPI bus
rfid.PCD_Init(); // Initialize the RFID module
Serial.println("Place your RFID card near the reader...");
}
void loop() {
// Check if a new card is present
if (!rfid.PICC_IsNewCardPresent()) {
return; // Exit if no card is detected
}
// Check if the card can be read
if (!rfid.PICC_ReadCardSerial()) {
return; // Exit if the card cannot be read
}
// Print the UID of the card
Serial.print("Card UID: ");
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i], HEX); // Print each byte in hexadecimal
Serial.print(" ");
}
Serial.println();
// Halt the card to stop communication
rfid.PICC_HaltA();
}
Module Not Responding:
Card Not Detected:
Interference or Poor Performance:
SPI Communication Fails:
Q: Can the RFID-RC522 module work with 5V logic?
A: No, the module operates at 3.3V logic. Use a level shifter if your microcontroller uses 5V logic.
Q: What is the maximum range of the RFID-RC522?
A: The maximum range is approximately 5 cm, depending on the tag and environment.
Q: Can the module write data to RFID tags?
A: Yes, the RFID-RC522 supports both reading and writing to compatible RFID tags.
Q: Is it possible to use I2C or UART instead of SPI?
A: Yes, the module supports I2C and UART, but SPI is the default and most commonly used interface. Configuration changes may be required to use other interfaces.