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

Arduino UNO-Based Smart Door Lock System with RFID, Ultrasonic Sensor, and LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Door Lock System with RFID, Ultrasonic Sensor, and LCD Display

Circuit Documentation

Summary

This circuit is designed to control a door lock system using an Arduino UNO microcontroller. The system includes an RFID reader for authentication, an ultrasonic sensor for object detection, a servo motor for locking and unlocking the door, an LCD display for user interaction, and LEDs for status indication. Additionally, a piezo buzzer provides audible feedback.

Component List

  1. Arduino UNO

    • Description: 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. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  3. Micro servo 9G

    • Description: Small servo motor.
    • Pins: GND, +5V, PWM
  4. 16x2 I2C LCD

    • Description: 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  5. RFID-RC522

    • Description: RFID reader module.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  6. Piezo Buzzer

    • Description: Simple piezoelectric buzzer.
    • Pins: pin 1, pin 2
  7. Resistor (220 Ohms)

    • Description: Resistor with 220 Ohms resistance.
    • Pins: pin1, pin2
  8. LED: Two Pin (green)

    • Description: Green LED.
    • Pins: cathode, anode
  9. LED: Two Pin (yellow)

    • Description: Yellow LED.
    • Pins: cathode, anode
  10. LED: Two Pin (red)

    • Description: Red LED.
    • Pins: cathode, anode

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

Micro servo 9G

16x2 I2C LCD

RFID-RC522

Piezo Buzzer

Resistor (220 Ohms)

Resistor (220 Ohms)

Resistor (220 Ohms)

LED: Two Pin (green)

LED: Two Pin (yellow)

LED: Two Pin (red)

Code Documentation

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

#define SS_PIN 10
#define RST_PIN 9
#define buzzer 8
#define servoPin 3
#define echoPin 6
#define trigPin 7

String UID = "2D 94 B5 02";  // UID of RFID card
byte lock = 1;               // status of door lock

Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 rfid(SS_PIN, RST_PIN);
int Y = 2;
int G = 4;
int R = 5;
int duration = 0;
int distanceCM = 0;

void setup()
{
  pinMode(G, OUTPUT);
  pinMode(R, OUTPUT);
  pinMode(Y, OUTPUT);
  pinMode(echoPin, INPUT_PULLUP);
  pinMode(trigPin, OUTPUT);
  Serial.begin(9600);
  servo.write(0);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  servo.attach(servoPin);
  SPI.begin();
  rfid.PCD_Init();
}

void loop()
{
  lcd.setCursor(4, 0);
  lcd.print("Welcome!");
  lcd.setCursor(1, 1);
  lcd.print("Put your card");

  checkDistance();

  if (distanceCM < 5)
  {
    digitalWrite(Y, 1);
    Serial.println("Object detected!");
  }
  else
    digitalWrite(Y, 0);

  checkRFID();
}

void checkDistance()
{
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);  // need to delay to split the packet
                          // 100000 packets (1000000/10)
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH); //time difference
  distanceCM = duration * 0.017175;
}

void checkRFID()
{
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scanning");
  Serial.print("NUID tag is :");
  String ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    lcd.print(".");
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
    delay(300);
  }
  ID.toUpperCase();
  Serial.println(ID);

  if (ID.substring(1) == UID && lock == 0)
  {
    // ring once
    digitalWrite