KEMBAR78
Simple Security | PDF | Computer Programming | Computer Engineering
0% found this document useful (0 votes)
53 views3 pages

Simple Security

This document contains an Arduino sketch for a password-protected door lock system using a keypad and an LCD. The system allows users to enter a password, and if the correct password is entered, it unlocks the door for 9 seconds before locking again. It also includes visual and audio feedback for incorrect password entries.

Uploaded by

Rahul Makwana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Simple Security

This document contains an Arduino sketch for a password-protected door lock system using a keypad and an LCD. The system allows users to enter a password, and if the correct password is entered, it unlocks the door for 9 seconds before locking again. It also includes visual and audio feedback for incorrect password entries.

Uploaded by

Rahul Makwana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <Keypad.

h>
#include <LiquidCrystal.h>

// LCD setup (your connections: 12, 11, 5, 4, 3, 2)


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Keypad setup
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

// Connect keypad rows to Mega pins 22, 23, 24, 25


byte rowPins[ROWS] = {22, 23, 24, 25};
// Connect keypad cols to Mega pins 26, 27, 28, 29
byte colPins[COLS] = {26, 27, 28, 29};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// LED + buzzer (on analog pins)


#define greenLed A0
#define redLed A1
#define buzzer A2

// Password
char password[5] = "1234"; // default password
char entered[10]; // user input buffer
int pos = 0; // input position

void setup() {
lcd.begin(16, 2);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(buzzer, OUTPUT);

digitalWrite(redLed, HIGH); // door locked by default


digitalWrite(greenLed, LOW);
digitalWrite(buzzer, LOW);

lcd.print(" ENTER PASSWORD ");


}

void loop() {
char key = keypad.getKey();

// if buzzer is on, pressing any key stops it


if (digitalRead(buzzer) == HIGH && key) {
digitalWrite(buzzer, LOW);
lcd.clear();
lcd.print(" ENTER PASSWORD ");
pos = 0;
return;
}

if (key) {
// number entered
if (key >= '0' && key <= '9') {
if (pos < 9) {
entered[pos] = key;
lcd.setCursor(pos, 1);
lcd.print('*'); // show star for password
pos++;
}
}

// press # to check password


if (key == '#') {
entered[pos] = '\0'; // end string

if (!strcmp(entered, password)) {
// correct password
lcd.clear();
lcd.print("Door Unlocked");
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);

// 9 second countdown
for (int sec = 9; sec > 0; sec--) {
lcd.setCursor(0, 1);
lcd.print("Locking in: ");
lcd.print(sec);
lcd.print(" "); // clear old digits if <10
delay(1000);
}
// lock door again
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
lcd.clear();
lcd.print("Door Locked");
delay(2000);

} else {
// wrong password
lcd.clear();
lcd.print(" Wrong Password ");
digitalWrite(redLed, HIGH);
digitalWrite(buzzer, HIGH); // buzzer ON until key pressed
}

// reset entry
pos = 0;
delay(1500);
lcd.clear();
lcd.print(" ENTER PASSWORD ");
}
}
}

You might also like