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

Arduino UNO-Based Password-Protected Servo Lock with 4x4 Keypad

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Password-Protected Servo Lock with 4x4 Keypad

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a 4x4 Membrane Matrix Keypad and a Servo motor. The Arduino UNO reads inputs from the keypad and controls the position of the Servo motor based on the input sequence, which acts as a password. The circuit is intended to function as a simple security system, where the correct password sequence unlocks the Servo motor, potentially controlling a lock mechanism.

Component List

Arduino UNO

Description: A microcontroller board based on the ATmega328P.
Purpose: Acts as the central processing unit of the circuit, reading keypad inputs, controlling the Servo motor, and managing the locking logic.

4X4 Membrane Matrix Keypad

Description: A 16-button keypad arranged in a 4x4 matrix.
Purpose: Provides user input to the system, allowing the entry of a password sequence.

Servo

Description: A rotary actuator or linear actuator that allows for precise control of angular or linear position.
Purpose: Acts as the locking mechanism, changing position based on the password entered on the keypad.

Wiring Details

Arduino UNO

Digital Pins:

Power Pins:

4X4 Membrane Matrix Keypad

Row Pins:

Column Pins:

Servo

Pins:

Documented Code

#include <Servo.h>
#include <Keypad.h>

Servo ServoMotor;
char* password = "0221"; // You can change the Password

int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// Create two variables for LED Lights
int RedpinLock = 12;
int GreenpinUnlock = 10;

unsigned long lastUnlockedTime = 0; // To store the time when unlocked
bool isUnlocked = false; // To track the current state

void setup()
{
  pinMode(RedpinLock, OUTPUT);
  pinMode(GreenpinUnlock, OUTPUT);
  ServoMotor.attach(11);
  LockedPosition(true);
}

void loop()
{
  char key = keypad.getKey();
  
  // Reset position if '*' or '#' is pressed
  if (key == '*' || key == '#')
  {
    position = 0;
    LockedPosition(true);
  }

  // Check if key matches the password
  if (key == password[position])
  {
    position++;
  }

  // Unlock if password is correct
  if (position == 4)
  {
    LockedPosition(false);
    lastUnlockedTime = millis(); // Store the unlock time
    isUnlocked = true; // Mark as unlocked
    position = 0; // Reset position
  }

  // Auto-lock after 5000ms
  if (isUnlocked && (millis() - lastUnlockedTime >= 20000))
  {
    LockedPosition(true);
    isUnlocked = false; // Mark as locked
  }
  
  delay(100);
}

void LockedPosition(int locked)
{
  if (locked)
  {
    digitalWrite(RedpinLock, HIGH);
    digitalWrite(GreenpinUnlock, LOW);
    ServoMotor.write(11); // Locked position
  }
  else
  {
    digitalWrite(RedpinLock, LOW);
    digitalWrite(GreenpinUnlock, HIGH);
    ServoMotor.write(90); // Unlocked position
  }
}

This code is responsible for initializing the keypad and servo motor, reading the input from the keypad, and controlling the servo motor's position based on the input password. The servo motor is locked or unlocked based on the correct sequence of keys pressed. The code also includes a timeout feature that automatically locks the servo after a certain period of time.