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 an RFID reader, a keypad, a push button, and a micro servo. The system also includes an LCD screen for user interaction and a buzzer for audio feedback. The core of the circuit is an Arduino UNO microcontroller, which interfaces with all the components.

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 audio feedback.
    • 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 screen 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

Documented Code

#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(unlockPosition); // set sudut servo
  lcd.setCursor(0, 1);
  lcd.print("Unlocked        ");
}

void wrongPassword() {
  lcd.setCursor(0, 1);
  lcd.print("Access Denied   ");