0% found this document useful (0 votes)
22 views5 pages

Code

The document contains an Arduino code for a password-protected door lock system using a keypad, LCD, and servo motor. It includes functions for displaying prompts, unlocking the door upon correct password entry, and indicating incorrect attempts with visual and auditory signals. The system also features a countdown timer for entry after unlocking, and it relocks the door automatically after a set period.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Code

The document contains an Arduino code for a password-protected door lock system using a keypad, LCD, and servo motor. It includes functions for displaying prompts, unlocking the door upon correct password entry, and indicating incorrect attempts with visual and auditory signals. The system also features a countdown timer for entry after unlocking, and it relocks the door automatically after a set period.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <LiquidCrystal.

h>
#include <Servo.h>
#include <Keypad.h>
Servo myservo;
int pos=0;
LiquidCrystal lcd(A4, A5, A3, A2, A1, A0);
const byte rows=4;
const byte cols=3;

char key[rows][cols]={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows]={0,1,2,3};
byte colPins[cols]={4,5,6};
Keypad keypad= Keypad(makeKeymap(key),rowPins,colPins,rows,cols);
char* password="2345";
int currentposition=0;

int red = 13;


int green = 12;

void setup()
{

displayscreen();
//[Link](9600);
[Link](8); //Servo motor connection
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
[Link](16,2);

void loop()
{
if( currentposition==0)
{
displayscreen();

}
int l ;
char code=[Link]();
if(code!=NO_KEY)
{
[Link]();
[Link](0,0);
[Link]("PASSWORD:");
[Link](7,1);
[Link](" ");
[Link](7,1);
for(l=0;l<=currentposition;++l)
{

[Link]("*");
//keypress();
}
if (code==password[currentposition])
{
++currentposition;
if(currentposition==4)
{

unlockdoor();
currentposition=0;

else
{
incorrect();
currentposition=0;

}
}
}

//------------------ Function 1- OPEN THE DOOR--------------//

void unlockdoor()
{
delay(900);

[Link](0,0);
[Link](" ");
[Link](1,0);
[Link]("Access Granted");
[Link](4,1);
[Link]("WELCOME!!");
[Link](15,1);
[Link](" ");
[Link](16,1);
[Link](" ");
[Link](14,1);
[Link](" ");
[Link](13,1);
[Link](" ");

for(pos = 180; pos>=0; pos-=5) // open the door


{
[Link](pos);
delay(5);
}
digitalWrite(green,HIGH);
delay(1000);
digitalWrite(green,LOW);
delay(2000);

delay(1000);
counterbeep();
delay(1000);

for(pos = 0; pos <= 180; pos +=5) // close the door


{ // in steps of 1 degree
[Link](pos);
delay(15);
}
digitalWrite(red,HIGH);
delay(1000);
digitalWrite(red,LOW);
delay(500);
currentposition=0;

[Link]();
displayscreen();
}

//--------------------Function 2- Wrong code--------------//

void incorrect()
{
delay(500);
[Link]();
[Link](1,0);
[Link]("CODE");
[Link](6,0);
[Link]("INCORRECT");
[Link](15,1);
[Link](" ");
[Link](4,1);
[Link]("TRY AGAIN !!!");

[Link](13,1);
[Link](" ");
[Link]("CODE INCORRECT YOU ARE UNAUTHORIZED");
digitalWrite(red,HIGH);
delay(1000);
digitalWrite(red,LOW);
delay(3000);
[Link]();
displayscreen();
}
//-------Function 3 - CLEAR THE SCREEN--------------------/
void clearscreen()
{
[Link](0,0);
[Link](" ");
[Link](0,1);
[Link](" ");
[Link](0,2);
[Link](" ");
[Link](0,3);
[Link](" ");
}

//------------Function 4 - DISPLAY FUNCTION--------------------//


void displayscreen()
{
[Link](0,0);
[Link]("*ENTER THE CODE*");
[Link](1 ,1);

[Link]("TO OPEN DOOR!!");


}

//--------------Function 5 - Count down------------------//


void counterbeep()
{
delay(1200);

[Link]();

[Link](2,15);
[Link](" ");
[Link](2,14);
[Link](" ");
[Link](2,0);
delay(200);
[Link]("GET IN WITHIN:::");

[Link](4,1);
[Link]("5");
delay(200);
[Link]();
[Link](2,0);
[Link]("GET IN WITHIN:");
delay(1000);
[Link](2,0);
[Link]("GET IN WITHIN:");
[Link](4,1); //2
[Link]("4");
delay(100);
[Link]();
[Link](2,0);
[Link]("GET IN WITHIN:");
delay(1000);

[Link](2,0);
[Link]("GET IN WITHIN:");
[Link](4,1);
[Link]("3");
delay(100);
[Link]();
[Link](2,0);
[Link]("GET IN WITHIN:");
delay(1000);

[Link](2,0);
[Link]("GET IN WITHIN:");
[Link](4,1);
[Link]("2");
delay(100);
[Link]();
[Link](2,0);
[Link]("GET IN WITHIN:");
delay(1000);

[Link](4,1);
[Link]("1");
delay(100);
[Link]();
[Link](2,0);
[Link]("GET IN WITHIN::");

delay(1000);
delay(40);
[Link]();
[Link](2,0);
[Link]("RE-LOCKING");
delay(500);
[Link](12,0);
[Link](".");
delay(500);
[Link](13,0);
[Link](".");
delay(500);
[Link](14,0);
[Link](".");
delay(400);
[Link]();
[Link](4,0);
[Link]("LOCKED!");
delay(440);

You might also like