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:
Component | Quantity |
---|---|
Arduino UNO board | 1 |
Keypad module (4×4 or 3×4) | 1 |
Buzzer 5V | 1 |
IC 7809 | 1 |
16×2 LCD display | 1 |
BC547 Transistor | 1 |
Resistor 1k 1/4 watt | 1 |
Potentiometer 10k | 1 |
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 Pin | Arduino Pin |
---|---|
R1 | 8 |
R2 | 7 |
R3 | 6 |
R4 | 5 |
C1 | 10 |
C2 | 9 |
C3 | A0 |
C4 | A1 |
The LCD connections to the Arduino board:
LCD Pin | Arduino Pin |
---|---|
RS | 12 |
RW | 11 |
EN | 5 |
D4 | 4 |
D5 | 3 |
D6 | 2 |
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.
Leave a Reply