• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Circuit Ideas for You

Get free circuit ideas online.

  • Home
  • Privacy Policy
  • About
Home » Digital Code Lock Circuit using Arduino

Digital Code Lock Circuit using Arduino

Last updated on 24 August 2024 by Admin-Lavi Leave a Comment

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:

Digital Code Lock Circuit Diagram using Arduino

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:

  • Gather all the components as shown in the above circuit diagram.
  • Connect a regulated IC1 7809 to provide a regulated 9V DC to the Arduino board.
  • Connect pot 10k 1st pin to VCC pin of LCD display board, 2nd leg of pot 10k to contrast pin of LCD display board and 3rd leg of pot 10k to GND pin of LCD display board.
  • Connect Blacklight cathode on the LCD display with the ground supply on the Arduino
  • Connect Blacklight anode on the LCD display with the 5V power supply on the Arduino
  • Connect transistor BC547 collector to one leg of buzzer, base to pin 13 on Arduino board with 1k resistor, and emitter on ground.
  • Connect buzzer one leg to collector of BC547 and other leg to VCC 5V power supply.

Keypad Pinout and Arduino Connections:

  • Rows: Typically labeled R1, R2, R3 and R4 ( In diagram it is labeled as 1,2,3,4)
  • Columns: Typically labeled C1, C2, C3 and C4 ( In diagram it is labeled as 1,2,3,4)
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

Filed Under: Arduino Projects, Security and Protection

About Admin-Lavi

Lavi is a B.Tech electronics engineer with a passion for designing new electronic circuits. Do you have questions regarding the circuit diagrams presented on this blog? Feel free to comment and solve your queries with quick replies

Previous Post: « Simple Heartbeat Monitor Circuit using Arduino
Next Post: DIY Variable Power Supply Circuit using Arduino »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Categories

  • Alarm Circuits (30)
  • Amplifier Circuits (67)
  • Arduino Projects (29)
  • Audio Circuits (93)
  • Automobile Circuits (19)
  • Battery Charger Circuits (48)
  • Free Energy (13)
  • Heater and Temperature Controllers (9)
  • Indicator Circuits (38)
  • Inverter Circuits (13)
  • LDR Circuits (13)
  • LED and Lamps (111)
  • Meters and Testers (27)
  • Motor Controllers (18)
  • Oscillator Circuits (32)
  • Power Supply Circuits (91)
  • Remote Control Circuits (6)
  • Security and Protection (23)
  • Sensors and Detectors (71)
  • Solar Circuits (16)
  • Timer Circuits (27)
  • Transistor Circuits (56)
  • Transmitter Circuit (12)
  • Tutorials (4)
  • Water Level Controller (4)

Copyright © 2025 | New Circuit Ideas