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

Arduino UNO RFID Door Access Control with Ultrasonic Trigger and I2C LCD Feedback

View and Edit Project In Cirkit DesignerImage of Arduino UNO RFID Door Access Control with Ultrasonic Trigger and I2C LCD Feedback

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a variety of components including LEDs, resistors, an I2C LCD, an RFID-RC522 module, and an ultrasonic sensor. The purpose of the circuit is to create an access control system that authenticates RFID cards and displays messages on an LCD screen. The system also includes visual indicators (LEDs) and an audible alert (buzzer) to signal access granted or denied. The ultrasonic sensor is used to detect the presence of an object or person at a certain distance, prompting the user to scan their RFID card.

Component List

LEDs

Resistors

Arduino UNO

16x2 I2C LCD

RFID-RC522

Ultrasonic Sensor

Wiring Details

Green LED

Red LED

White LED

Arduino UNO

16x2 I2C LCD

RFID-RC522

Ultrasonic Sensor

Documented Code

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

#define RST_PIN         9         
#define SDA_PIN         10
#define echo_Pin        6
#define trig_Pin        7

MFRC522 RFID (SDA_PIN, RST_PIN);  
LiquidCrystal_I2C lcd(0x27, 16, 2);
String authenticatedCard = " 93 B9 B5 29";
bool doorStatus = 0;
int Duration;
int Distance;
int greenLED = 5;
int redLED = 4;
int Light = 3;
const int buzzer = 8; 
int numTones = 3;
int correctTones[] = {262, 294, 330};
int wrongTones[] = {330, 294, 262};

void setup() {
  pinMode(echo_Pin, INPUT);
  pinMode(trig_Pin, OUTPUT);
  Serial.begin(9600);    
  lcd.init(); 
  lcd.backlight();
  lcd.clear();  
  while (!Serial);
  SPI.begin();          
  RFID.PCD_Init();      
  delay(4);  
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(Light, OUTPUT);
  pinMode(buzzer, OUTPUT); 
}

void loop() {
  digitalWrite(trig_Pin, 1);
  delayMicroseconds(10); 
  digitalWrite(trig_Pin, 0);
  Duration = pulseIn(echo_Pin, 1); 
  Distance = Duration * 0.017175;
  if (Distance <= 50){
   lcd.clear();
   lcd.print("Please scan the");
   lcd.setCursor(0, 1);
   lcd.print("card");
   Serial.println(F("Please scan the card"));
   Serial.println(); 
   if ( ! RFID.PICC_IsNewCardPresent()) {
      return;
   }

   if ( ! RFID.PICC_ReadCardSerial()) {
      return;
   }

   String scannedCard = "";     
   Serial.print(F("Card UID:"));
   for (byte i = 0; i < RFID.uid.size; i++) {
    Serial.print(RFID.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(RFID.uid.uidByte[i], HEX);

   if (RFID.uid.uidByte[i] < 0x10) {
         scannedCard += " 0"; 
     } else {
         scannedCard += " "; 
     }
     scannedCard += String(RFID.uid.uidByte[i], HEX); 
  }
  
   if (scannedCard.equalsIgnoreCase(authenticatedCard)){
     if(doorStatus == 0){
       Serial.println();
       Serial.print(F("Scanning....."));
       Serial.println(); 
       lcd.clear();
       lcd.print("Scanning.....");
       delay(2000);
       Serial.print(F("Authenticated"));
       Serial.println(); 
       lcd.clear();
       lcd.print("Authenticated");
       delay(2000);
       lcd.clear();
       lcd.blink();
       delay(2000);
       lcd.noBlink();
       lcd.print("Door is opened");
       delay(2000);
       lcd.clear();
       lcd.blink();
       delay(2000);
       lcd.noBlink();
       lcd.print("VVelcome~~~");
       delay(2000);
       lcd.clear();
       digitalWrite(greenLED, 1);
       for (int j = 0; j <=numTones; j++){
        tone(buzzer, correctTones[j]);
        delay(500);
       }
       noTone(buzzer);
       digitalWrite(greenLED, 0);
       digitalWrite(Light, 1);
       doorStatus = 1;
     }
    
     else { 
       Serial.println();
       Serial.print(F("Scanning....."));
       Serial.println(); 
       lcd.clear();
       lcd.print("Scanning.....");
       delay(2000);
       Serial.print(F("Authenticated"));
       Serial.println(); 
       lcd.clear();
       lcd.print("Authenticated");
       delay(2000);
       lcd.clear();
       lcd.blink();
       delay(2000);
       lcd.noBlink();
       lcd.print("Door is closed");
       delay(2000);
       lcd.clear();
       lcd.blink();
       delay(2000);
       lcd.noBlink();
       lcd.print("Thank you~~~");
       delay(2000);
       lcd.clear();
       digitalWrite(greenLED, 1); // Turn on the green LED
       for (int j = 0; j <=numTones; j++){
        tone(buzzer, correctTones[j]);
        delay(500);
       }
       noTone(buzzer);                   
       digitalWrite(greenLED, 0);   
       digitalWrite(Light, 0);
       doorStatus = 0;              
       }
   }
   else {
     Serial.println();
     Serial.print(F("Scanning....."));
     Serial.println(); 
     lcd.clear();