MFRC522 RFID Tutorial

In this Project, we will see about how to interface MFRC522 RFID with Arduino .

Circuit Diagram:

Arduino Code:
rfid_code.ino
#include <SPI.h>
#include <MFRC522.h>

const int myLED = 2;
MFRC522 mfrc522(10, 9);   //SS_PIN,RST_PIN

void setup() {
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  
  pinMode(myLED, OUTPUT);
  digitalWrite(myLED,LOW);
  Serial.println("Ready...");
}

void loop() {
  if ( ! mfrc522.PICC_IsNewCardPresent()){
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()){
    return;
  }

  Serial.print("UID tag    :");
  String content= "";
  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();
  Serial.print("LED Status : ");
  content.toUpperCase();
  if (content.substring(1) == "22 42 AE 34"){           //Change Your UID here
    digitalWrite(myLED, HIGH);
    Serial.println("LED ON");
    Serial.println("");    
  }
  
  else if (content.substring(1) == "B9 80 09 BA"){      //Change Your UID here
    digitalWrite(myLED, LOW);
    Serial.println("LED OFF");
    Serial.println("");
  }
}

Library Used:

Youtube Video Tutorial:




Download our official Android App in PlayStore. Click Here
You can get the all the required files (like Circuit Diagram, Arduino.ino file, Libraries Used, and others) for the project  in ZIP format and much more...

1 comment:

  1. Hey bro, I don't understand what is this : content.substring(1) ?????

    ReplyDelete