Circuit Documentation
Summary
This circuit involves an Arduino UNO microcontroller interfaced with an RFID-RC522 module. The RFID module is used to read RFID tags, and the Arduino processes the data and provides feedback via the serial monitor. The circuit is powered by the Arduino's 3.3V supply.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
RFID-RC522
- Description: A low-cost RFID module that uses the MFRC522 IC.
- Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
Wiring Details
Arduino UNO
- 3.3V: Connected to VCC (3.3V) of RFID-RC522
- GND: Connected to GND of RFID-RC522
- D9: Connected to RST of RFID-RC522
- D10: Connected to SDA of RFID-RC522
- D11: Connected to MOSI of RFID-RC522
- D12: Connected to MISO of RFID-RC522
- D13: Connected to SCK of RFID-RC522
RFID-RC522
- VCC (3.3V): Connected to 3.3V of Arduino UNO
- GND: Connected to GND of Arduino UNO
- RST: Connected to D9 of Arduino UNO
- SDA: Connected to D10 of Arduino UNO
- MOSI: Connected to D11 of Arduino UNO
- MISO: Connected to D12 of Arduino UNO
- SCK: Connected to D13 of Arduino UNO
Code Documentation
#include <MFRC522.h>
#include <MFRC522Extended.h>
#include <deprecated.h>
#include <require_cpp11.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup()
{
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();
}
void loop()
{
// 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 :");
String content = "";
byte letter;
for (byte i = 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);
}
}
Code Explanation
- Libraries: The code includes several libraries necessary for interfacing with the MFRC522 RFID module.
- Pin Definitions:
SS_PINandRST_PINare defined for the RFID module's Slave Select and Reset pins, respectively. - Setup Function: Initializes serial communication, SPI bus, and the RFID module.
- Loop Function: Continuously checks for new RFID cards. If a card is detected, it reads the card's UID and prints it to the serial monitor. If the UID matches a predefined value, it grants access; otherwise, it denies access.
