-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfid_ID_checker.c
37 lines (30 loc) · 946 Bytes
/
rfid_ID_checker.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Start the serial communication at 9600 baud rate
SPI.begin(); // Start the SPI bus
rfid.PCD_Init(); // Initialize the MFRC522 reader
Serial.println("Scan an RFID card to get its UID...");
}
void loop() {
// Check if a new RFID card is present
if (!rfid.PICC_IsNewCardPresent()) {
return;
}
// Read the card's serial number (UID)
if (!rfid.PICC_ReadCardSerial()) {
return;
}
// Print the UID of the card to the serial monitor
Serial.print("Card UID: ");
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
}
Serial.println(); // Add a new line after the UID
// Halt the card after reading the UID
rfid.PICC_HaltA();
}