Site icon Circuit Ideas for You

Digital Code Lock Circuit using Arduino

Everywhere in the globe, security is crucial and it presents a significant challenge for locations that maintain secrecy.

This initiative contributes to increased security.

This project uses an Arduino, a tiny microcontroller to create a basic lock.

Using an Arduino UNO board, a keypad module, a buzzer, a 16×2 LCD, a BC547 transistor and a few resistors, this project illustrates a basic digital code lock system.

To unlock a gadget a users must input a special code required by the system.

The buzzer will ring when the right code is entered.

The buzzer will not sound and an error message will appear on the LCD if the incorrect code is entered.

This project can assist in ensuring that passwords are only used by authorized individuals.

Coding:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize LCD pins

const int keypadRows = 4; // Number of keypad rows
const int keypadCols = 4; // Number of keypad columns

const int keypadPins[keypadRows][keypadCols] = {
  {8, 7, 6, 5}, // Connect keypad rows to Arduino pins
  {10, 9, A0, A1},
  {A2, A3, A4, A5},
  {A6, A7, A8, A9}
};

const int buzzerPin = 13; // Pin connected to the buzzer

const int correctCode[] = {1, 2, 3, 4}; // Replace with your desired code

void setup() {
  lcd.begin(16, 2); // Initialize LCD display
  pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
}

void loop() {
  char key = getKey(); // Get pressed key from keypad

  if (key != NO_KEY) { // If a key is pressed
    lcd.setCursor(0, 0); // Set cursor position
    lcd.print(key); // Print pressed key on LCD
  }

  if (key == '#') { // If '#' is pressed, check the entered code
    if (checkCode()) {
      lcd.setCursor(0, 1);
      lcd.print("Access granted");
      digitalWrite(buzzerPin, HIGH); // Sound the buzzer
      delay(1000); // Delay for 1 second
      digitalWrite(buzzerPin, LOW);
    } else {
      lcd.setCursor(0, 1);
      lcd.print("Access denied");
    }
  }
}

char getKey() {
  for (int r = 0; r < keypadRows; r++) {
    for (int c = 0; c < keypadCols; c++) {
      pinMode(keypadPins[r][c], OUTPUT);
      digitalWrite(keypadPins[r][c], LOW);

      for (int i = 0; i < keypadCols; i++) {
        pinMode(keypadPins[r][i], INPUT);
        if (digitalRead(keypadPins[r][i]) == HIGH) {
          while (digitalRead(keypadPins[r][i]) == HIGH);
          return keypadMap[r][c];
        }
      }

      pinMode(keypadPins[r][c], INPUT);
    }
  }
  return NO_KEY;
}

bool checkCode() {
  int i = 0;
  while (i < sizeof(correctCode) / sizeof(int)) {
    char key = getKey();
    if (key != correctCode[i]) {
      return false;
    }
    i++;
  }
  return true;
}

Circuit Working:

Parts List:

ComponentQuantity
Arduino UNO board1
Keypad module (4×4 or 3×4)1
Buzzer 5V1
IC 78091
16×2 LCD display1
BC547 Transistor1
Resistor 1k 1/4 watt1
Potentiometer 10k1

This project is a fairly simple that includes an IC 7809, LCD, buzzer, keypad module and Arduino.

The voltage regulator IC 7809 is made to provide a steady 9V.

Its main purpose in the context of the digital code lock project is to give regulated power to the many parts, including the Arduino, keypad, buzzer, LCD and transistor.

The constant operation of the code lock mechanism depends on the 7809s stable and dependable power supply.

Arduino is in charge of all the operations, including driving the buzzer, receiving the password from the keypad module, comparing passwords, and communicating the status to the LCD display.

The user uses the keypad to input a code, passwords are entered using the keypad.

Code processing after reading keypad input, the Arduino buffers it.

Comparing code the right code and the inputted code are compared.

The buzzer sounds and the LCD shows the message “Access granted” if the codes match.

If not, a “Access denied” warning appears.

LCD is utilized to show messages or status updates, while buzzers are employed for signals.

To power the buzzer, an NPN transistor BC547 is used, and resistor 1k is connected in series to the base of transistor BC547 to restrict the base current.

How to Build:

To build a Digital Code Lock Circuit using Arduino following are the connections steps:

Keypad Pinout and Arduino Connections:

Keypad PinArduino Pin
R18
R27
R36
R45
C110
C29
C3A0
C4A1

The LCD connections to the Arduino board:

LCD PinArduino Pin
RS12
RW11
EN5
D44
D53
D62

Conclusion:

This project Digital Code Lock Circuit using Arduino uses an Arduino UNO board along with other parts to illustrate a basic digital code lock mechanism.

Adding features like multiple user codes, password strength checking, and real time access logs can improve it even more.

References:

Electronic Lock System

Exit mobile version