This circuit involves an Arduino UNO microcontroller interfaced with an RFID-RC522 module. The Arduino UNO reads RFID tags using the RFID-RC522 module and performs actions based on the detected RFID tag. The circuit is powered by the 3.3V and GND pins of the Arduino UNO.
Arduino UNO
RFID-RC522
Comment
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 6
#define LED_PIN 5
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
pinMode(LED_PIN, OUTPUT);
Serial.println("Place your card on the reader...");
Serial.println();
}
void loop() {
// Look for new cards
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
return;
// Print UID of the card
Serial.print("Card UID: ");
String content = "";
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
content.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(rfid.uid.uidByte[i], HEX));
}
Serial.println();
// Convert content to uppercase
content.toUpperCase();
// Check which UID it is
if (content.substring(1) == "83 3F 02 35") { // Replace with your card's UID
Serial.println("Welcome, Abhishek!");
blinkLED();
}
else if (content.substring(1) == "33 5C 41 1C") { // Replace with your card's UID
Serial.println("Welcome, Yatish!");
blinkLED();
}
else {
Serial.println("Unknown card!");
}
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
void blinkLED() {
digitalWrite(LED_PIN, HIGH);
delay(500); // LED on for 500 ms
digitalWrite(LED_PIN, LOW);
}
This code initializes the RFID reader and continuously checks for new RFID tags. When a tag is detected, it reads the UID and performs actions based on the UID. The LED blinks to indicate a recognized tag.