Arduino RC522 RFID TUTORIAL

Posted on

Arduino RC522 RFID TUTORIAL – RFID (Radio Frequency Identification) is a device that utilizes radio waves to identify a code or ID on a particular device without cables. This RFID device consists of tags (labels) and readers. Look at in the picture below. There are two tags or RFID devices (transponders), readers, controllers. This tag contains the chip and antenna inside it, and stores the ID number. Each one and another tag has a different ID number. Reader contains an antenna and a system of reading ID tags.

How can the reader read the ID from the tag, while the tag doesn’t have a battery? how can the tag be active? The working principle is the same as wireless charge on a smartphone. Antenna from Reader will generate and emit radio waves within a certain distance. When the tag approaches the emission wave from the reader, the tag antenna receives radio waves and converts them to electrical voltage, which will turn on the chip. if this chip is active, then this chip will generate radio waves containing data ID. if the reader reads the ID of the tag, the controller will work according to the program ordered.

For example, the partkir system uses cards. If the card (tag) is brought closer to the reader, the controller will order the gate to lift the entrance bar, so that we can enter the parking area.

RFID ARDUINO TUTORIAL

MFRC522 Datasheet

One of the popular RFID Reader is RFID-RC522 Arduino. This RFID Reader uses MFRC522 chips made by NXP Semiconductor. This chip has a communication system without direct contact with a frequency of 13.56 MHz. This RFID RC522 range up to 50mm. To communicate with the controller, RFID-RC522 has features:

  • Working voltage 2.5 – 3.3V
  • Supports ISO / IEC 14443 A / MIFARE and NTAG
  • Supports MF1xxS20, MF1xxS70 and MF1xxS50 encryption in Read / Write mode
  • Supports ISO / IEC 14443 A higher transfer speed communication up to 848 kBd
  • Supports MFIN / MFOUT
  • I2C, SPI and UART serial communication
Read other articles  Making Anti-theft Devices with PIR Sensors

Download MFRC522 Datasheet

 

MFRC522 Library

Now let’s make this device read the ID of the tag. To make it, we use a arduino library. If you don’t use the library on Arduino, programming will be very long. Please download the following RFID-RC522 library:

Download RFID Library RC522

Add library into Arduino IDE by:

  • Open the Arduino IDE
  • Click the Sketch menu > Include Library > Add. ZIP Library
  • Select the downloaded library, called rfid-master.zip
  • Click OK

 

RFID RC522 Schematic

In this Arduino RC522 RFID tutorial, Please use a schematic below:

rfid pinout arduino rfid rc522
Taken in from the README.srt file that is in the rfid-master.zip library

rfid tutorial arduino

 

 

RFID RC522 Program

The program below is a basic program for reading IDs of tags. If this program can be mastered, you can use it as a development for other programs such as turning on lights using this tag ID. Please upload this program to Arduino:

#include <SPI.h> 
#include <MFRC522.h>
 
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); 
 
void setup() 
{

  Serial.begin(9600);   
  SPI.begin();      
  mfrc522.PCD_Init();   
  Serial.println("Bring the RFID Tag (Can be a card or key chain) to the RFID reader");
  Serial.println();

}
void loop() 
{
   if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  delay(2000);
}

After the program is uploaded, open the serial monitor. Bring one of the tags to the Arduino RFID RC522, the ID number will appear from the tag. For example, I bring one RFID tag to the Arduino RC552 and I find the ID of my tag is 5A 86 34 00 as in the following picture:

rfid tutorial

2 thoughts on “Arduino RC522 RFID TUTORIAL

Leave a Reply

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