-
Notifications
You must be signed in to change notification settings - Fork 0
/
bus-station-nfc-reader.ino
46 lines (29 loc) · 1.05 KB
/
bus-station-nfc-reader.ino
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
38
39
40
41
42
43
44
45
46
//source https://www.diyengineers.com/2021/04/15/learn-how-to-read-an-rfid-tag-with-rc522-and-arduino/
#include <SPI.h> //for further details and other examples see: https://github.com/miguelbalboa/rfid
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 5
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init RC522
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! rfid.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
printHex(rfid.uid.uidByte, rfid.uid.size);
rfid.PICC_HaltA(); // Halt PICC
}
//Routine to dump a byte array as hex values to Serial.
void printHex(byte *buffer, byte bufferSize) {
for (int i = 0; i<4; i++)
Serial.write(0xff);
Serial.write(buffer, bufferSize);
}