Created
October 3, 2016 05:47
-
-
Save openopen114/a5903c4880563791775a7f3dcd6538dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SPI.h" | |
#include "MFRC522.h" | |
#define SS_PIN 10 | |
#define RST_PIN 9 | |
#define SP_PIN 8 | |
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() || !rfid.PICC_ReadCardSerial()) | |
return; | |
// Serial.print(F("PICC type: ")); | |
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); | |
// Serial.println(rfid.PICC_GetTypeName(piccType)); | |
// Check is the PICC of Classic MIFARE type | |
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.")); | |
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("Tap card key: "); | |
Serial.println(strID); | |
rfid.PICC_HaltA(); | |
rfid.PCD_StopCrypto1(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment