Dưới đây là các thư viện cần thiết cho dự án này:
Ghim | Dây để Arduino Uno |
SDA | số 10 |
SCK | số 13 |
MOSI | số 11 |
SÚP MISO | số 12 |
IRQ | không dùng |
GND | GND |
RST | số 9 |
3.3V | 3.3V |
Chú ý: điện áp hoạt động của MFRC522 là 3.3V!
Sau khi các mạch đã sẵn sàng, hãy vào File> Ví dụ> MFRC522> DumpInfo và tải lên arduino. Mã này sẽ có sẵn trong IDE Arduino của bạn (sau khi cài đặt các thư viện RFID).
Sau đó, mở màn hình nối tiếp. Bạn sẽ thấy như hình bên dưới:
Đây là thông tin mà bạn có thể đọc từ thẻ, bao gồm UID thẻ được đánh dấu màu vàng.Các thông tin được lưu trữ trong bộ nhớ được chia thành các phân đoạn và khối như bạn có thể thấy trong hình ảnh trước đó.
Bạn đã 1024 byte dung lượng lưu trữ dữ liệu chia thành 16 ngành, từng lĩnh vực được bảo vệ bởi hai khóa khác nhau, A và B.
Viết xuống UID của thẻ , vì bạn sẽ cần nó sau này.
Tải lên các mã sau đây.
/*
*
* All the resources for this project: http://randomnerdtutorials.com/
* Modified by Rui Santos
*
* Created by FILIPEFLOP
*
*/
#include
#include
#defineSS_PIN10
#defineRST_PIN9
MFRC522 mfrc522(SS_PIN,RST_PIN); // Create MFRC522 instance.
voidsetup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
}
voidloop()
{
// Look for new cards
if(!mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if(!mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
Stringcontent="";
byteletter;
for(bytei=0;i<mfrc522.uid.size;i++)
{
Serial.print(mfrc522.uid.uidByte[i]<0x10?" 0":" ");
Serial.print(mfrc522.uid.uidByte[i],HEX);
content.concat(String(mfrc522.uid.uidByte[i]<0x10?" 0":" "));
content.concat(String(mfrc522.uid.uidByte[i],HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if(content.substring(1)=="BD 31 15 2B")//change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
delay(3000);
}
else {
Serial.println(" Access denied");
delay(3000);
}
}
↑