Interface RC522 RFID Reader with Arduino | Arduino Code
In the previous blog tutorial, we have learned the “What is RFID RC522 Module | How Does it Work”, now we will be going to learn How to Interfacing MFRC522/RC522 RFID Reader Module with Arduino. Here we will discuss how to Interface RC522 RFID Reader with Arduino, How to Connect RC522 RFID Reader with Arduino, Circuit diagram, Arduino Code for Reading the MIFARE Classic-1K RFID Card and Key fob tag.
Introduction
The RC522 RFID Reader module creates a 13.56MHz electromagnetic field to communicate with the RFID tags. This Reader module can read the information stored in an RFID card or Key fob tag. We can build lots of electronics projects using the RFID Reader module and card or Key fob tag. You might have seen other similar applications of RFID modules like RFID based Door Lock Systems, access control systems, contactless payment, automatic check-out systems in supermarkets, etc. Before building your own RFID projects, you have to learn how to Interface RC522 RFID Reader with Arduino.
Components Required
Components Name | Quantity |
Arduino UNO ((you can use other types of Arduino like Arduino NANO, MEGA, etc.) | 1 |
MFRC522 RC522 RFID Reader Module | 1 |
MIFARE Classic-1K RFID Card and Key fob tag | 1+1 |
Connecting Wires | As required in the circuit diagram |
RC522 RFID Reader Module Pin Diagram
How to Connect RC522 RFID Reader with Arduino
RC522 RFID reader module supports SPI, I2C, and UART protocols for communication with a microcontroller/microprocessor. The RC522 RFID Reader modules require a lot of data transfer. Hence, we are using SPI protocols for communication because the SPI protocol is the much fastest among all the three serial communication protocols. Another cause of using SPI protocols is we have used an RFID library that supports only SPI protocols. To Interface RC522 RFID Reader with Arduino via SPI protocol, the circuit connection is mentioned below.
RFID Reader Module Pins | Arduino Uno Pin | Arduino Nano Pin | Arduino Mega Pin |
VCC | 3.3v Pin | 3.3v Pin | 3.3v Pin |
RST | The RST pin can be connected to any Digital Pin on the Arduino. | ||
GND | GND Pin | GND Pin | GND Pin |
IRQ | The IRQ pin is left unconnected because the library we are going to use doesn’t support it. | ||
MISO | D11 | D11 | D51 |
MOSI | D12 | D12 | D50 |
SCK | D13 | D13 | D52 |
SDA | D10 | D10 | D53 |
Circuit Diagram/Schematic of RC522 RFID Reader Module with Arduino Uno
Download and Install Library
Before starting to write a code for communicating the RC522 RFID reader module with Arduino, we need to install the MFRC522 library in Arduino IDE. Because without a library communicating with the RC522 RFID module is a bunch of work. Click on the download button below to download the RFID-Master.zip library.
Follow the below steps to download the Library.
After downloading the RFID-Master.zip file, then open the Arduino IDE and go to Sketch > Include Library > Add .ZIP Library > then select the RFID-master.zip file that you just downloaded.
Arduino Code for Reading the MIFARE Classic-1K RFID Card and Key fob tag
When we are using a new RFID Card and Key fob tag in our projects, before that, we have to read the information stored in it mainly Unique ID (UID). We can easily read this information by using the DumpInfo example sketch which is stored by the RFID library.
After installing the RFID library in Arduino IDE, click on File > Examples > open Examples Submenu > select MFRC522 > open DumpInfo example sketch.
Once upload the sketch/code on the Arduino, then open the Serial Monitor. Now bring a card or key fob tag closer to the Reader module, and do not remove it until all the information is displayed on Serial Monitor.
If you remove the card early, then you will get an error message “Timeout in communication” on the serial monitor. You can take out the card after all the information is printed.
We can see all the useful information about the tag including the tag’s Unique ID (UID), the memory size, and the whole 1K memory. In my case, the Card’s Unique ID (UID) is A9 59 1A B4
Analyzing the Memory Map of MIFARE Classic 1K Card
The RFID card and key fob tag are of type MIFARE 1K having 1k memory which is organized in 16 sectors (from 0 to 15), each sector is further divided into 4 blocks (block 0 to 3) and each block can store 16 bytes of data (from 0 to 15).
16 sectors x 4 blocks x 16 bytes of data = 1024 bytes = 1K memory