#include #include #define SS_PIN 10 #define RST_PIN 9 MFRC522 rfid(SS_PIN, RST_PIN); MFRC522::MIFARE_Key key; void setup() { Serial.begin(9600); SPI.begin(); rfid.PCD_Init(); } void loop() { if ( ! rfid.PICC_IsNewCardPresent()) return; if ( ! rfid.PICC_ReadCardSerial()) return; MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); if(piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) { Serial.println(F("Your tag is not of type MIFARE Classic, your card/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(); Serial.print("Your card's UID: "); Serial.println(StrID); rfid.PICC_HaltA (); rfid.PCD_StopCrypto1 (); }