• 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 29 July 2025 by Admin-Lavi Leave a Comment

Security is important everywhere in world and is more hard in secret places.

This project for Digital Code Lock Circuit using Arduino help make better security.

It use Arduino, small computer to make simple lock.

With Arduino UNO, keypad, buzzer, LCD (16×2), BC547 transistor and resistors it show how digital code lock work.

User must type correct code to unlock device.

If code is right then buzzer makes sound.

If code is wrong then no buzzer will sound and LCD will show error.

This project help only right person uses the password.

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
Resistors
1k 1/4 watt1
Potentiometer 10k1
Semiconductors
Arduino UNO board1
Keypad module (4×4 or 3×4)1
Buzzer 5V1
IC 78091
16×2 LCD display1
BC547 Transistor1

This project is simple and it uses IC 7809, LCD, buzzer, keypad and Arduino.

IC 7809 gives steady 9V power.

It give power to all parts like Arduino, keypad, buzzer, LCD and transistor.

Lock work is good because IC 7809 give stable power.

Arduino control everything and take code from keypad check it, runs the buzzer and show message on LCD.

User type password using keypad.

Arduino read keypad which store code.

Then it check if code is correct.

If code is right then the buzzer sound and LCD say “Access granted.”

If code is wrong then LCD show “Access denied.”

LCD show messages but buzzer gives sound signal.

BC547 transistor is used to power buzzer and 1k resistor is used to control current at transistor base.

How to Build:

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

  • First collect all parts like shown in circuit diagram.
  • Connect IC 7809 to give 9V DC power to Arduino.

Take 10k pot:

  • Connect 1st pin to LCD VCC
  • Connect 2nd pin to LCD contrast pin
  • Connect 3rd pin to LCD GND
  • Connect LCD backlight cathode to Arduino GND.
  • Connect LCD backlight anode to Arduino 5V.

Connect BC547 transistor:

  • Collector goes to one leg of buzzer
  • Base goes to Arduino pin 13 with 1k resistor
  • Emitter goes to GND

Buzzer connection:

  • One leg goes to BC547 collector
  • Other leg goes to 5V VCC.

Keypad Pinout and Arduino Connections:

  • Rows: labeled as R1, R2, R3 and R4 and in diagram it is labeled as 1,2,3,4)
  • Columns: labeled C1, C2, C3 and C4 and 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 for Digital Code Lock Circuit using Arduino and other parts to show simple code lock system.

We can make it better by adding more things like many user codes, check if password is strong and save who access it in real time

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 (31)
  • Amplifier Circuits (67)
  • Arduino Projects (30)
  • Audio Circuits (93)
  • Automobile Circuits (19)
  • Battery Charger Circuits (48)
  • Free Energy (13)
  • Heater and Temperature Controllers (9)
  • High Voltage (1)
  • Indicator Circuits (38)
  • Inverter Circuits (13)
  • LDR Circuits (14)
  • LED and Lamps (114)
  • 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 (74)
  • Solar Circuits (16)
  • Timer Circuits (28)
  • Transistor Circuits (56)
  • Transmitter Circuit (12)
  • Tutorials (4)
  • Water Level Controller (4)

Recent Posts

  • Low Power Led Flasher Circuit using Nand Gate IC
  • Two Star Flasher Circuit with 555 IC
  • Automatic Light Control Switch Circuit using IC 555
  • Ultrasonic Blind Stick Circuit using Arduino
  • Simple Humidity Level Detector Circuit

Recent Comments

  1. Admin-Lavi on Constant Voltage, Constant Current Battery Charger Circuit
  2. Bill on Constant Voltage, Constant Current Battery Charger Circuit
  3. Admin-Lavi on Long Range FM Transmitter Circuit (2km)
  4. Sina on Long Range FM Transmitter Circuit (2km)
  5. Admin-Lavi on Long Range FM Transmitter Circuit (2km)

Copyright © 2025 | New Circuit Ideas