Table of Contents

Automatic Door Lock

Author

SEID Jemal Ahmed

Introduction

This project involves creating an automatic door lock system using Arduino, which integrates an RFID sensor and card to operate a mini servo motor connected to a door handle. Additionally, the system includes interactive features such as an LCD, buzzer, and RGB LED to provide feedback to the user regarding the successful reading of the RFID card.

The primary objective of this project is to enhance security and convenience by enabling users to unlock doors using RFID cards, eliminating the need for traditional keys. By incorporating feedback mechanisms like the LCD display, buzzer, and RGB LED, users can easily determine whether their RFID card has been recognized, enhancing the usability of the system.

The project aims to combine practicality with interactivity, offering users a seamless and intuitive experience when accessing doors. Whether it's for home security or office access control, the automatic door lock system provides a modern and efficient solution to traditional locking mechanisms.

General Description

Hardware Design

1. Component List

2. Price Table

Component Distributor Quantity Price
Arduino Uno Board Optimusdigital 1 40 RON
LCD 1602 Optimusdigital 1 17 RON
Micro Servo 9g Optimusdigital 1 35 RON
Active Buzzer Optimusdigital 1 5 RON
RFID-RC522 Module Optimusdigital 1 10 RON
Breadboard Optimusdigital 1 10 RON
9v Battery Optimusdigital 1 10 RON
Total _ __ 127 RON

Obs: The prices are rounded to the nearest decimal.

3. Electrical Schematics

Software Design

I tried to design a system to control a servo motor based on RFID authentication, displaying an interactive feedback on an LCD screen. Key components include a servo motor, an LCD screen, an RFID reader, LEDs, and a buzzer.

Components and Libraries
Operation
Algorithm

Scanning Code

I have used the code below in order to read the tags unique ID and register it in to the UID variable in my main program.

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

    #define RST_PIN 9
    #define SS_PIN  10
    byte readCard[4];
    byte a = 0;

    LiquidCrystal_I2C lcd(0x27, 16, 2);//
    MFRC522 mfrc522(SS_PIN, RST_PIN);

    void setup() {
      Serial.begin(9600);
      lcd.init();
      lcd.backlight();
    while (!Serial);
      SPI.begin();
      mfrc522.PCD_Init();
      delay(4);
      mfrc522.PCD_DumpVersionToSerial();
      lcd.setCursor(2, 0);
      lcd.print("Put your card");
    }

    void loop() {
      if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return 0;
      }
      if ( ! mfrc522.PICC_ReadCardSerial()) {
        return 0;
      }
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Scanned UID");
      a = 0;
      Serial.println(F("Scanned PICC's UID:"));
      for ( uint8_t i = 0; i < 4; i++) {  //
        readCard[i] = mfrc522.uid.uidByte[i];
        Serial.print(readCard[i], HEX);
        Serial.print(" ");
        lcd.setCursor(a, 1);
        lcd.print(readCard[i], HEX);
        lcd.print(" ");
        delay(500);
        a += 3;
      }
      Serial.println("");
      mfrc522.PICC_HaltA();
    }

Source Code

The following is the main program which implements the algorithm described above.

    #include <Servo.h>
    #include <LiquidCrystal_I2C.h>
    #include <SPI.h>
    #include <MFRC522.h>
    #define SS_PIN 10
    #define RST_PIN 9
    #define GREEN 6
    #define RED 5
    #define BUZZER 7

    String UID = "C0 41 22 30";

    Servo servo;
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    MFRC522 rfid(SS_PIN, RST_PIN);

    void setup() {
      Serial.begin(9600);
      servo.write(0);
      lcd.init();
      lcd.backlight();
      servo.attach(3);
      SPI.begin();
      rfid.PCD_Init();

      // pins 
      pinMode(RED, OUTPUT);
      pinMode(GREEN, OUTPUT);
      pinMode(BUZZER, OUTPUT);
    }

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

      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();

      if (ID.substring(1) == UID) {
        servo.write(70);
        lcd.clear();
        lcd.setCursor(0, 0);
        analogWrite(GREEN, 255);
        lcd.print("Door is locked");
        delay(1500);
        lcd.clear();
        analogWrite(GREEN, 0);
        lock = 1;
        delay(1500);
        servo.write(160);
      } 
      else {
        lcd.clear();
        lcd.setCursor(0, 0);
        analogWrite(RED, 255);
        tone(BUZZER, 100);
        lcd.print("Wrong card!");
        delay(1500);
        analogWrite(RED, 0);
        noTone(BUZZER);
        lcd.clear();
      }
    }

Conclusion

In this project I have got a first hand experience on how to work with arduino uno, protocols like I2C and SPI, sensors like RFID-RC522 and servo motor. Above all, I've managed to realize an arduino project which works and has a real life application for the first time.

References