rfid
This commit is contained in:
parent
0c48406956
commit
68f7e6027c
3
RFID-RC522/README.md
Normal file
3
RFID-RC522/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
## Library
|
||||
|
||||
- [MFRC522](https://github.com/miguelbalboa/rfid)
|
46
RFID-RC522/RFID-RC522.ino
Normal file
46
RFID-RC522/RFID-RC522.ino
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* ...
|
||||
*
|
||||
* Author: Alexander Popov
|
||||
* License: Unlicense
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <MFRC522.h>
|
||||
|
||||
#define SS_PIN 7
|
||||
#define RST_PIN 9
|
||||
|
||||
MFRC522 rfid(SS_PIN, RST_PIN);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
SPI.begin();
|
||||
rfid.PCD_Init();
|
||||
|
||||
Serial.println("Tap RFID/NFC Tag on reader.");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// new tag is available
|
||||
if (rfid.PICC_IsNewCardPresent()) {
|
||||
// NUID has been readed
|
||||
if (rfid.PICC_ReadCardSerial()) {
|
||||
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
|
||||
|
||||
Serial.print("RFID/NFC Tag Type: ");
|
||||
Serial.println(rfid.PICC_GetTypeName(piccType));
|
||||
|
||||
// print NUID in Serial Monitor in the hex format
|
||||
Serial.print("UID:");
|
||||
for (int i = 0; i < rfid.uid.size; i++) {
|
||||
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
|
||||
Serial.print(rfid.uid.uidByte[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
rfid.PICC_HaltA(); // halt PICC
|
||||
rfid.PCD_StopCrypto1(); // stop encryption on PCD
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user