HomeTutorialsArduinoHow to use the RFID-RC522 module (RFID reader) with the Arduino Uno

How to use the RFID-RC522 module (RFID reader) with the Arduino Uno

Setup of this tutorial: RFID reader and two RFID tags.

RFID stands for Radio-frequency identification and can be used for many application that require an identification mechanism. In this tutorial, it is shown how to use the RFID-RC522 module with the Arduino Uno. The RFID-RC522 module is an RFID reader, which can read RFID tags in close-range. In order to read an RFID tag, the reader and the tag must have the same frequency. The RFID-RC522 module reads only High frequency tags at 13.56 MHz.
In order to demonstrate the RFID-RC522 module, a simple application is programmed which identifies a user based on an RFID tag.

List of materials:

Arduino Uno
Jumper wires (female/male)
RFID-RC522 module
RFID tags 

How to connect the RFID-RC522 to the Arduino?

Schematic of how to connect the RFID-RC522 to the Arduino.

The RFID-RC522 module comes with eight pins (of which seven pins are used in this tutorial). In the following, the pin layout is shown as recommended by the documentation of the MFRC522 library (used later in the programming section). The RFID-RC522 module runs with 3.3V. Therefore, the module’s 3.3V pin must be connected to the Arduino’s 3.3V. The module might get damaged, if it is accidentally connected to the Arduino’s 5V pin. The complete pin layout is shown by the following table (works only for the Arduino Uno! Mega, Nano etc. have different recommended pin layouts!):

RFID-RC522 Pin –> Arduino Uno Pin:

  • SDA –> 10
  • SCK –> 13
  • MOSI –> 11
  • MISO –> 12
  • IRQ –> UNUSED
  • GND –> GND
  • RST –> 9
  • 3.3V –> 3.3V

How to program the RFID reader?
The code makes use of an existing RFID library which can be found here: https://github.com/miguelbalboa/rfid. If you are using the Arduino IDE, the library can be easily installed by clicking “Sketch->Include Library->Manage Libraries”. Then, search for “RFID” and you will find an entry with the title “MFRC522 by GithubCommunity”. If you cannot find such an entry, I recommend to visit the official website of the library for further assistance. In order to get the RFID reader running, you have to setup the library itself, a SPI connection, as well as the reader. Luckily, the library offers two very handy convenience functions for reading tags: The first functions allows to detect whether an RFID tag/card is present. The second function reads the RFID tag id. In the following code, a for-loop is used to iterate through the tag. In each iteration, a single byte is read and printed out as hexadecimal value (00..FF). Such an mechanism can be used to identify users, when each user owns a different RFID tag.

// (c) Michael Schoeffler 2014, http://www.mschoeffler.de

#include "SPI.h" // SPI library
#include "MFRC522.h" // RFID library (https://github.com/miguelbalboa/rfid)

const int pinRST = 9;
const int pinSDA = 10;

MFRC522 mfrc522(pinSDA, pinRST); // Set up mfrc522 on the Arduino

void setup() {
  SPI.begin(); // open SPI connection
  mfrc522.PCD_Init(); // Initialize Proximity Coupling Device (PCD)
  Serial.begin(9600); // open serial connection
}

void loop() {
  if (mfrc522.PICC_IsNewCardPresent()) { // (true, if RFID tag/card is present ) PICC = Proximity Integrated Circuit Card
    if(mfrc522.PICC_ReadCardSerial()) { // true, if RFID tag/card was read
      Serial.print("RFID TAG ID:");
      for (byte i = 0; i < mfrc522.uid.size; ++i) { // read id (in parts)
        Serial.print(mfrc522.uid.uidByte[i], HEX); // print id as hex values
        Serial.print(" "); // add space between hex blocks to increase readability
      }
      Serial.println(); // Print out of id is complete.
    }
  }
}

If the code has been successfully uploaded to the Arduino and an RFID card or tag is in close-range to the RFID reader, the output on the Serial Monitor (Tools->Serial Monitor, Ctrl+Shift+M) should look like this (picture shows position of the RFID card as well as the corresponding serial monitor output):

RFID reader is reading the ID of an RFID card. In addition, the serial monitor output of the program is shown.

Video Tutorial:

How to use the RFID-RC522 module (RFID reader) with the Arduino Uno | UATS A&S #4
Michael Schoeffler
Michael Schoeffler
Let me know in the comments what you think!

6 COMMENTS

  1. I am working on a rfid project and have a rc522 reader and some tags. Reader could read the tags that came along with it, but it is not responding to tags that i bought additionally. These extra card tags have some numbers written on them. If they are blank cards then please help me to program them.

    • You need to be sure they’re at the same frequency there are a few different radio frequencies used for RFID and they aren’t cross compatible, if that isn’t the issue then make sure they aren’t locked. Some RFID cards first need a 4 or more bit code sent from the reader, these are for security of data and obviously if your reader isn’t sending anything then it will act like a brick.

  2. Hi i interfaced RFID-RC522 (13.65MHZ) module it getting data from the card but it want to store the data in card day by day input date through IOT of the card was inserted then send print card number was reading the date and automatically if match card number the wifi send automatic data transform and updated in the computer but i tried this type using if equitation but how to transform the data in bulk please provide example.

  3. Hi i interfaced RFID-RC522 (13.65MHZ) module it getting data from the card but it want to store the data in card day by day input date through IOT of the card was inserted then send print card number was reading the date and automatically if match card number the wifi send automatic data transform and updated in the computer but i tried this type using if equitation but how to transform the data in bulk ides please provide example.

  4. I have a few questions regarding the RFID-RC522 Module.

    1. Does this module have any kind of certifications? i.e. FCC, CE?

    2. How do I code the card that is given with the module?

    3. Can I change the coding of each card? meaning i can change the ID number of the card?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most RECENT

Most Popular

ADVERTISEMENT