• 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 11 June 2026 by Admin-Lavi Leave a Comment

Nowadays, security is important everywhere in the world, and it becomes even more critical in sensitive or restricted areas.

Therefore, this Digital Code Lock Circuit using Arduino helps improve security by providing controlled access.

Also, it use Arduino, small computer to make simple lock and with Arduino UNO, keypad, buzzer, LCD (16×2), BC547 transistor and resistors it show how digital code lock work.

Hence, user must type correct code to unlock device and if code is right then buzzer makes sound and if code is wrong then no buzzer will sound and LCD will show error; therefore, this project help only right person using the password.

Arduino Code:

#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:

ComponentsQuantity
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, as IC 7809 gives steady 9V power and it also give power to all parts like Arduino, keypad, buzzer, LCD and transistor.

Furthermore, lock work is good because IC 7809 give stable power.

Then Arduino control everything and take code from keypad check it, runs the buzzer and show message on LCD, after that user type password using keypad.

Now Arduino read keypad which store code and then it check if code is correct and if code is right then the buzzer sound and LCD say “Access granted.” and if code is wrong then LCD show “Access denied.”

Moreover, the LCD displays messages, while the buzzer provides an audible signal;

Finally, the BC547 transistor drives the buzzer, and the 1 kΩ resistor limits the current flowing into the transistors 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.
  • Next, Connect IC 7809 to give 9V DC power to Arduino.

Take 10k pot:

  • Then 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 and then connect LCD backlight anode to Arduino 5V.

Connect BC547 transistor:

  • Now collector goes to one leg of buzzer, base goes to Arduino pin 13 with 1k resistor and then emitter goes to GND

Buzzer connection:

  • Also, one leg goes to BC547 collector and then other leg goes to 5V VCC.

Keypad Pinout and Arduino Connections:

  • Rows: We label the rows as R1, R2, R3 and R4 and in the diagram, we label them as 1, 2, 3 and 4.
  • Columns: We label the columns as C1, C2, C3 and C4 and in the diagram, we label them as 1, 2, 3 and 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:

To conclude, this Digital Code Lock Circuit using Arduino is simple security project.

First, user enter correct code, then lock open, however, if user enter wrong code, system not allow access and give warning.

Therefore, this project help make security better in home, office and secret place, furthermore, we can add more features like RFID, fingerprint and mobile control in future for more security.

Filed Under: Arduino Projects, Automation Circuits, Hobby Circuits, 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

  • 555 Timer Projects (80)
  • Alarm Circuits (71)
  • Amplifier Circuits (91)
  • Arduino Projects (103)
  • Audio Circuits (181)
  • Automation Circuits (60)
  • Automobile Circuits (29)
  • Battery Charger Circuits (85)
  • DIY Projects (257)
  • Free Energy (12)
  • Heater and Temperature Controllers (31)
  • High Voltage (23)
  • Hobby Circuits (128)
  • Indicator Circuits (59)
  • Inverter Circuits (18)
  • IoT projects (1)
  • LDR Circuits (39)
  • LED and Lamps (188)
  • Meters and Testers (40)
  • Mini Projects (188)
  • Motor Controllers (24)
  • Oscillator Circuits (58)
  • Power Supply Circuits (205)
  • Radio Frequency (1)
  • Remote Control Circuits (11)
  • Renewable energy (4)
  • Security and Protection (87)
  • Sensors and Detectors (202)
  • Solar Circuits (31)
  • Timer Circuits (58)
  • Transistor Circuits (156)
  • Transmitter Circuit (21)
  • Tutorials (9)
  • Voltage Regulator (20)
  • Water Level Controller (10)

Recent Posts

  • Low Current Controlled Battery Charger Circuit using LM723 IC
  • 741 Op-Amp Treble Booster Circuit
  • Simple Diode and Transistor Based Audio Limiter Circuit
  • Simple 500mW Speaker Driver Circuit
  • Easy DIY LM386 Audio Amplifier Circuit

Recent Comments

  1. Tony Gallegos on NTC Thermistor Based Temperature to Voltage Converter Circuit
  2. colin on Simple Single Transistor Audio Amplifier Circuit
  3. How to Make a Bird Chirping Noise Easily on Chirping Bird Sound Generator Circuit
  4. Transistor Based Medium Impedance Preamplifier Circuit - Circuit Ideas for You on Low Impedance Input Transistor Preamplifier Circuit
  5. Admin-Lavi on Alternate Red Green LED Flasher Circuit

Copyright © 2026 | New Circuit Ideas