#include SPI.h #include MFRC522.h #define SS_PIN 10 #define RST_PIN 9 int flag=0; int op=8; char UID[] = XXXXXXXX;            Place your UID of your tag here. MFRC522 rfid(SS_PIN, RST_PIN); MFRC522MIFARE_Key key; void setup() { Serial.begin(9600); SPI.begin(); rfid.PCD_Init(); pinMode(op,OUTPUT); } void loop() { if ( ! rfid.PICC_IsNewCardPresent()) return; if ( ! rfid.PICC_ReadCardSerial()) return; MFRC522PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); if(piccType != MFRC522PICC_TYPE_MIFARE_MINI && piccType != MFRC522PICC_TYPE_MIFARE_1K && piccType != MFRC522PICC_TYPE_MIFARE_4K) { Serial.println(F(Your tag is not of type MIFARE Classic, your tag can't be read ()); return; } String StrID = ; for (byte i = 0; i 4; i ++) { StrID += (rfid.uid.uidByte[i]0x10 0 )+ String(rfid.uid.uidByte[i],HEX)+ (i!=3 ); } StrID.toUpperCase(); if(StrID!=UID) { Serial.println(This is an invalid tag (); Serial.println(); delay(2000); } if (StrID==UID && flag==0) { flag=1; digitalWrite(op,HIGH); Serial.println(This is a vaild tag )); Serial.println(Status ON); Serial.println(); delay(2000); } else if(StrID==UID && flag==1) { flag=0; digitalWrite(op,LOW); Serial.println(This is a vaild tag )); Serial.println(Status OFF); Serial.println(); delay(2000); } rfid.PICC_HaltA (); rfid.PCD_StopCrypto1 (); }