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

Arduino UNO SmartSafe Vault with RFID, IR, and Servo Motor

View and Edit Project In Cirkit DesignerImage of Arduino UNO SmartSafe Vault with RFID, IR, and Servo Motor

Circuit Documentation

Summary

This circuit is a SmartSafe Vault system that utilizes an Arduino UNO microcontroller to control various components including a Servo Motor, an LCD display, an IR Receiver, a Buzzer, and an RFID reader. The system is designed to unlock and lock a safe based on RFID card scans and PIN inputs via an IR remote.

Component List

  1. Servo Motor (SG90)

    • Description: A small servo motor used to lock and unlock the safe.
    • Pins: Pin3, 5V, GND
  2. MKE-M07 LCD1602 I2C

    • Description: An I2C LCD display used to show messages and status.
    • Pins: GND, 5V, SDA, SCL
  3. IR Receiver

    • Description: An infrared receiver used to receive signals from an IR remote.
    • Pins: DATA, VCC, GND
  4. Buzzer

    • Description: A buzzer used to provide audio feedback.
    • Pins: PIN, GND
  5. Arduino UNO

    • Description: The main microcontroller used to control all components.
    • 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
  6. RFID-RC522

    • Description: An RFID reader used to scan RFID cards.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA

Wiring Details

Servo Motor (SG90)

MKE-M07 LCD1602 I2C

IR Receiver

Buzzer

RFID-RC522

Documented Code

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

#define RST_PIN 9  
#define SS_PIN 10
#define RECV_PIN 7 

Servo lockServo;
MFRC522 rfid(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2); 
IRrecv irrecv(RECV_PIN);
decode_results results;

const String correctUID = "21 C9 F7 A";  
const String defaultPIN = "2580"; 
String enteredPIN = "";
bool isUnlocked = false;

int buzzer = 4; 
int failedAttempts = 0;
const int maxAttempts = 5;

void setup() {
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  irrecv.enableIRIn();

  lockServo.attach(3);
  lockServo.write(0);

  lcd.init();
  lcd.backlight();

  digitalWrite(buzzer, HIGH);
  delay(50);
  digitalWrite(buzzer, LOW);

  printCentered("** GROUP 5 **", 0);
  printCentered("SmartSafe Vault", 1);

  delay(3000);
  lcd.clear();

  lockSafe();

  digitalWrite(buzzer, HIGH);
  delay(200);
  digitalWrite(buzzer, LOW);
}

void loop() {
  handleIRInput();

  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
    return;
  }

  String scannedUID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    String hexByte = String(rfid.uid.uidByte[i], HEX);
    hexByte.toUpperCase();
    scannedUID += hexByte;
    if (i < rfid.uid.size - 1) scannedUID += " ";
  }

  lcd.clear();
  printCentered("Scanned card", 0);
  printCentered(scannedUID, 1);

  delay(1000);

  if (scannedUID == correctUID) {
    if (!isUnlocked) {
      unlockSafe();
    } else {
      lockSafe();
    }
    failedAttempts = 0;
  } else {
      if (!isUnlocked) {
        failedAttempts++;
      }
      errCard();

      if (failedAttempts >= maxAttempts) {
        lockout();
        failedAttempts = 0;
      } else {
        displayAttemptsLeft();
      }
      if (isUnlocked) {
        lockSafe();
      }
  }

  rfid.PICC_HaltA();
}

void handleIRInput() {
  if (irrecv.decode(&results)) {
    String key = decodeKey(results.value);
    irrecv.resume();

    if (key != "") {
      if (isUnlocked) {
        lockSafe();
        enteredPIN = "";
        return;
      }

      enteredPIN += key;
      lcd.clear();

      digitalWrite(buzzer, HIGH);
      delay(10);
      digitalWrite(buzzer, LOW);
      printCentered("Entered PIN", 0);
      printCentered("> " + maskPIN(enteredPIN) + " <", 1);

      if (enteredPIN.length() == 4) {
        delay(500);
        if (enteredPIN == defaultPIN) {
          unlockSafe();
          enteredPIN = "";
          failedAttempts = 0;
        } else {
          lcd.clear();
          printCentered("Incorrect PIN", 0);
          printCentered("Try again", 1);
          enteredPIN = "";
          failedAttempts++;

          delay(2000);
          lockSafe();

          if (isUnlocked) {
            lockSafe();
          }

          if (failedAttempts >= maxAttempts) {
            lockout();
            failedAttempts = 0;
          }
        }
      }
    }
  }
}

String decodeKey(unsigned long value) {
  switch (value) {
    case 0xFF4AB5: return "0";
    case 0xFF6897: return "1";
    case 0xFF9867: return "2";
    case 0xFFB04F: return "3";
    case 0xFF30CF: return "4";
    case 0xFF18E7: return "5";
    case 0xFF7A85: return "6";
    case 0xFF10EF: return "7";
    case 0xFF38C7: return "8";
    case 0xFF5AA5: return "9";
    // case 0xFF02FD: return "0000";
    default: return "";
  }
}

String maskPIN(String pin) {
  String masked = "";
  for (int i = 0; i < pin.length(); i++) {
    masked += "*";
  }
  return masked;
}

void unlockSafe() {
  lockServo.write(90);
  isUnlocked = true;
  lcd.clear();
  printCentered("Safe unlocked", 0);
  printCentered("successfully!", 1);
  onBeep();

  delay(2000);
  printCentered("Scan ID or press", 0);
  printCentered("any key to lock.", 1);
}

void lockSafe() {
  lockServo.write(0);
  isUnlocked = false;
  lcd.clear();
  printCentered("Safe locked", 0);
  printCentered("successfully!", 1);
  onBeep();
  delay(2000);
  printCentered("Safe is locked", 0);
  displayAttemptsLeft();
  offBeep();
}

void displayAttemptsLeft() {
  printCentered("Attempts: " + String(maxAttempts - failedAttempts), 1);
}

void errCard() {
  lcd.clear();
  if (isUnlocked) {
    printCentered("Safe locked", 0);
    printCentered("successfully!", 1);
  } else {
    printCentered("Access denied!", 0);
    printCentered("Invalid card",