Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO RFID Access Control System with LED Indicators and I2C LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO RFID Access Control System with LED Indicators and I2C LCD Display

Circuit Documentation

Summary

This circuit is an RFID-based access control system using an Arduino UNO. It includes an RFID reader, two LEDs (red and green) to indicate access status, a 16x2 I2C LCD for displaying messages, and resistors for current limiting. The system reads RFID tags and grants or denies access based on a predefined authorized UID.

Component List

  1. 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
  2. LED: Two Pin (red)

    • Description: A red LED with two pins (cathode and anode).
    • Pins: cathode, anode
  3. LED: Two Pin (green)

    • Description: A green LED with two pins (cathode and anode).
    • Pins: cathode, anode
  4. RFID-RC522

    • Description: An RFID reader module.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  5. Resistor (220 Ohms)

    • Description: A resistor with a resistance of 220 Ohms.
    • Pins: pin1, pin2
  6. 16x2 I2C LCD

    • Description: A 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL

Wiring Details

Arduino UNO

LED: Two Pin (red)

LED: Two Pin (green)

RFID-RC522

Resistor (220 Ohms)

16x2 I2C LCD

Code Documentation

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

#define SS_PIN 10  // Pin for SS (Slave Select)
#define RST_PIN 1  // Pin for Reset
#define RED_LED_PIN 2
#define GREEN_LED_PIN 3

// Initialize MFRC522 RFID reader
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Initialize the LCD with I2C address 0x27 and a 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Predefined authorized RFID tag UID (you can replace this with your own UID)
byte authorizedUID[4] = {0xDE, 0xAD, 0xBE, 0xEF};  // Example authorized UID

void setup() {
  Serial.begin(9600);  // Start the serial communication
  SPI.begin();         // Start SPI bus for RFID module
  mfrc522.PCD_Init();  // Initialize the MFRC522 RFID module
  lcd.begin(16, 2);    // Initialize LCD (16x2)
  lcd.backlight();     // Turn on the backlight
  
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);

  // Display "TUP_QUEZON" for 2 seconds
  lcd.setCursor(0, 0);
  lcd.print("TUP_QUEZON");
  delay(2000);
  lcd.clear();
}

void loop() {
  // Display "Scan your Card" message
  lcd.setCursor(0, 0);
  lcd.print("Scan your Card");
  
  // Check if a new RFID card is present
  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;  // No card detected, continue checking
  }

  if (!mfrc522.PICC_ReadCardSerial()) {
    return;  // Failed to read card serial
  }

  // If we reach here, an RFID card has been detected and read
  Serial.println("Card detected!");

  // Display the UID of the scanned card for debugging
  Serial.print("ID Number: ");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  // Check if the scanned card matches the authorized UID
  bool isAuthorized = true;
  for (byte i = 0; i < 4; i++) {
    if (mfrc522.uid.uidByte[i] != authorizedUID[i]) {
      isAuthorized = false;  // Card does not match the authorized UID
      break;
    }
  }

  if (isAuthorized) {
    // Access Granted
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Access Granted");
    digitalWrite(GREEN_LED_PIN, HIGH);  // Turn on the green LED
    digitalWrite(RED_LED_PIN, LOW);    // Ensure the red LED is off
  } else {
    // Access Denied
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Access Denied");
    digitalWrite(RED_LED_PIN, HIGH);   // Turn on the red LED
    digitalWrite(GREEN_LED_PIN, LOW);  // Ensure the green LED is off
  }

  delay(1000);  // Wait for 1 second
  lcd.clear();  // Clear the LCD screen
}

This code initializes the RFID reader and the LCD, sets up the pins for the LEDs, and continuously checks for RFID cards. When a card is detected, it compares the card's UID with a predefined authorized UID and grants or denies access accordingly, displaying the result on the LCD and lighting up the appropriate LED.