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

Arduino-Based Smart Lock System with RFID, Keypad, and Servo Motor

View and Edit Project In Cirkit DesignerImage of Arduino-Based Smart Lock System with RFID, Keypad, and Servo Motor

Circuit Documentation

Summary

This circuit is designed to control a locking mechanism using a combination of a 4x4 membrane keypad, an RFID reader, a push button, a micro servo, an LCD screen, and a buzzer. The system is managed by an Arduino UNO microcontroller. The user can unlock the mechanism by entering a correct password on the keypad, tapping an authorized RFID card, or pressing the push button. The LCD screen provides feedback to the user, and the buzzer emits sounds to indicate different states.

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. Micro Servo 9G

    • Description: Small servo motor for precise control of angular position.
    • Pins: GND, +5V, PWM
  3. 4x4 Membrane Matrix Keypad

    • Description: Keypad with 16 keys arranged in a 4x4 matrix.
    • Pins: R1, R2, R3, R4, C1, C2, C3, C4
  4. Buzzer

    • Description: Simple piezoelectric buzzer for sound output.
    • Pins: PIN, GND
  5. Push Button Round

    • Description: Simple push button for user input.
    • Pins: leg0, leg1
  6. LCD Screen 16x2 I2C

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

    • Description: RFID reader module for reading RFID tags.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA

Wiring Details

Arduino UNO

Micro Servo 9G

4x4 Membrane Matrix Keypad

Buzzer

Push Button Round

LCD Screen 16x2 I2C

RFID-RC522

Code Documentation

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

#define buzzer_pin 7

// I2C LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define keypad layout
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  { 'D', '#', '0', '*' },
  { 'C', '9', '8', '7' },
  { 'B', '6', '5', '4' },
  { 'A', '3', '2', '1' }
};
byte colPins[ROWS] = { 2, 3, 4, 5 };
byte rowPins[COLS] = { A3, A2, A1, A0 };

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);  //deklarasi keypad manggil fungsi

// Password setup
String password = "1234";
String inputCode = "";  // buffer/ penyimpanan tiap kode yg diinput
String secret_key;

// Servo setup
Servo myServo; // deklarasi servo
int lockPosition = 90; //sudut servo saat mengunci
int unlockPosition = 0;

// Push button setup
const int buttonPin = 8;
bool buttonState = LOW; //variabel penyimpanan pembacaan tombol 
bool lastButtonState = LOW; //variabel penyimpanan pembacaan terakhir tombol

// RFID setup
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Authorized RFID UID
byte authorizedUID[] = { 0x31, 0x55, 0x60, 0x2E };
// 31 55 60 2E

void setup() {
  // Initialize serial communication
  Serial.begin(9600); //kecepatan baudrate 
  pinMode(buzzer_pin, OUTPUT);// set buzzer sebagai output

  // Initialize LCD
  lcd.init();// inisialisasi lcd
  lcd.backlight();// menyalakan lampu lcd
  lcd.setCursor(0, 0);// cursor lcd
  lcd.print("Enter Password:");

  // Initialize servo
  myServo.attach(6); // pin servo
  myServo.write(lockPosition); // set sudut servo

  // Initialize push button
  pinMode(buttonPin, INPUT_PULLUP); //tombol sebagi input

  // Initialize RFID
  SPI.begin();
  mfrc522.PCD_Init();
  lcd.setCursor(0, 1);
  lcd.print("RFID Ready");
  lockAction(); // langsung kunci saat awal kali menyala
}

void lockAction() {
  myServo.write(lockPosition);
  lcd.setCursor(0, 1);
  lcd.print("Locked          ");
}

void unlockAction() {
  myServo.write