This commit is contained in:
Alexander Popov 2023-06-04 18:27:50 +03:00
parent 0c48406956
commit 68f7e6027c
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
2 changed files with 49 additions and 0 deletions

3
RFID-RC522/README.md Normal file
View File

@ -0,0 +1,3 @@
## Library
- [MFRC522](https://github.com/miguelbalboa/rfid)

46
RFID-RC522/RFID-RC522.ino Normal file
View 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
}
}
}