⇧
vadnica-logo
Editor My Blog Password Manager Finance My Services About the Project Telegram O meni O meni

RFID Identification with LED Indicator

Wiring the Components

In this example, we will connect an RFID reader (RC522) and an LED. Via the SPI bus, the reader communicates the card's UID number to the Arduino. If the number matches the one in the code, the Arduino turns on the LED indicator.

Connections:

RFID RC522:

LED Indicator:

IMPORTANT: The RFID RC522 module operates on 3.3V. Connecting it to a 5V pin can permanently damage the module!

Arduino Code

To function, you need the MFRC522 library. Install it in the Arduino IDE: Sketch -> Include Library -> Manage Libraries (search for "MFRC522").


/* * LIBRARY: Install "MFRC522"
 * WIRING: RFID to SPI pins (10, 11, 12, 13, 9), LED to Pin 2
*/

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN 10
#define LED_PIN 2

MFRC522 mfrc522(SS_PIN, RST_PIN);

byte allowedUID[] = {0x70, 0x14, 0xD0, 0x13};

void setup() {
    Serial.begin(9600);
    SPI.begin();
    mfrc522.PCD_Init();
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);
    Serial.println("System ready...");
}

void loop() {
    if (!mfrc522.PICC_IsNewCardPresent()) return;
    if (!mfrc522.PICC_ReadCardSerial()) return;
    
    bool isCorrect = true;
    for (byte i = 0; i < mfrc522.uid.size; i++) {
        if (mfrc522.uid.uidByte[i] != allowedUID[i]) {
            isCorrect = false;
            break;
        }
    }

    if (isCorrect) {
        Serial.println("Recognized: LED ON");
        digitalWrite(LED_PIN, HIGH);
        delay(3000);
        digitalWrite(LED_PIN, LOW);
    } else {
        Serial.println("Unknown card");
    }
    delay(1000);
}

Required Material

  1. Arduino Uno (or compatible board): Microcontroller for circuit management.
  2. RFID-RC522 module: Reader for contactless reading of cards and fobs.
  3. LED diode: Visual indicator for recognition confirmation.
  4. 1k Resistor: Protective resistor for the LED diode.
  5. Protoboard SET: Breadboard for fast wiring without soldering.