MFRC522 RFID reader arduino wiring

MFRC522 RFID Reader With Arduino Tutorial – The Simplest way to read RFID tag

MFRC522 is maybe cheapest RFID Reader that we can found now. It uses 13.56 MHz frequency And it is also easy to use. We can easily interfaced this reader with arduino or raspberry. There are tons of library available out there. And one more, this tutorial can be the simplest tutorial on how to use this RFID reader with arduino.

MFRC522 RFID Reader Specification

Here’s the MFRC522 short specification :

  • 13.56MHz RFID module
  • Operating voltage: 2.5V to 3.3V
  • Communication : SPI, I2C protocol, UART
  • Maximum Data Rate: 10Mbps
  • Read Range: 5cm
  • Current Consumption: 13-26mA
  • Power down mode consumption: 10uA (min)

How to use MFRC522 With Arduino?

It simple, this reader use SPI to interface with arduino and use 3.3V as power source.

MFRC522 With Arduino Wiring Diagram

Connect MFRC522 RFID reader with arduino like in the picture above. And you are ready to start the code.

MFRC522 RFID Reader Arduino Code

Before we start the code, I have to inform you that in this tutorial we will use two libraries. You can download the libraries in the link below.

After download the two libraries above, we can start code. And here’s the example code of how to read the RFID tag and print that to serial monitor.

#include <SPI.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN, RST_PIN);

String rfidCard;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting the RFID Reader...");
  SPI.begin();
  rfid.init();
}

void loop() {
  if (rfid.isCard()) {
    if (rfid.readCardSerial()) {
      rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);
      Serial.println(rfidCard);
    }
    rfid.halt();
  }
}

Upload the code above and you should now see the RFID tag serial number on the serial monitor every time you tap the RFID tag.

And then I want to make an sample code if an serial tag with certain number will make a buzzer blink three times and if the wrong tag tapped it will trigger long sound of buzzer. This will simulate if we want to make for example RFID door lock or another project.

Add a 5V buzzer and connect the positive to pin 8 of arduino and the ground pin to ground of arduino.

In this example, we will use a tag with serial number “119 38 185 95” as the right tag. Or the key. You can edit this serial number in code below.

#include <SPI.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN, RST_PIN);

String rfidCard;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting the RFID Reader...");
  SPI.begin();
  rfid.init();
  pinMode(8, OUTPUT);
}

void loop() {
  if (rfid.isCard()) {
    if (rfid.readCardSerial()) {
      rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);
      Serial.println(rfidCard);
      if (rfidCard == "119 38 185 95") {
        digitalWrite(8, HIGH);
        delay(100);
        digitalWrite(8, LOW);
        delay(100);
        digitalWrite(8, HIGH);
        delay(100);
        digitalWrite(8, LOW);
        delay(100);
        digitalWrite(8, HIGH);
        delay(100);
        digitalWrite(8, LOW);
        delay(100);
      } else {
        digitalWrite(8, HIGH);
        delay(2000);
        digitalWrite(8, LOW);
      }
    }
    rfid.halt();
  }
}

Upload the code, and now you should hear three beeps from the buzzer if you tap the right tag. And will hear long beep if you tap the wrong tag.

And here’s the complete video tutorial on how to use the RC522 RFID Reader with arduino.