Interface RC522 RFID Reader with Arduino | Arduino Code

Share This

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 NameQuantity
Arduino UNO ((you can use other types of Arduino like Arduino NANO, MEGA, etc.)1
MFRC522 RC522 RFID Reader Module1
MIFARE Classic-1K RFID Card and Key fob tag1+1
Connecting WiresAs required in the circuit diagram

RC522 RFID Reader Module Pin Diagram

RC522 RFID Module Pin Diagram, Pinout, Pin Configuration. What is RFID RC522 Module, Hardware Overview, Pin Diagram, Working Principle, Features, Specification, and Applications.
RC522 RFID Module Pin Diagram, Pinout, Pin Configuration.

 

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 PinsArduino Uno PinArduino Nano PinArduino Mega Pin
VCC3.3v Pin3.3v Pin3.3v Pin
RSTThe RST pin can be connected to any Digital Pin on the Arduino.
GNDGND PinGND PinGND Pin
IRQThe IRQ pin is left unconnected because the library we are going to use doesn’t support it.
MISOD11D11D51
MOSID12D12D50
SCKD13D13D52
SDAD10D10D53

Circuit Diagram/Schematic of RC522 RFID Reader Module with Arduino Uno

Circuit Diagram of RC522 RFID Reader with Arduino Uno, Interface RC522 RFID Reader with Arduino | RFID RC522 Arduino Code
Circuit Diagram of RC522 RFID Reader 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.

Download MFRC522 RFID-Master.zip Library
Download MFRC522 RFID-Master.zip Library

Follow the below steps to download the Library.

Download RFID-Master.zip Library
Download RFID-Master.zip 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.

RFID-Master.zip Library Add to Arduino IDE
Library Add to Arduino IDE

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.

DumpInfo Example Sketch to read Card and tag
DumpInfo Example Sketch to read Card and tag
Interface RC522 RFID Reader with Arduino Code
Interface RC522 RFID Reader with Arduino Code

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.

RFID Card and Tag information on Serial Monitor
RFID Card and Tag information on Serial Monitor

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

Card’s Unique ID (UID)
Card’s Unique ID (UID)

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

Share This

Leave a Reply

Your email address will not be published. Required fields are marked *