Hi there,
Like the title says: i need help with a password lock project.
Problem 1:
Everytime i press the 4,5,6 or the 7 everything on the lcd disappears.
Problem 2:
When i enter my code the lcd has to say: Acces Granted, Welcome. Instead of that it all disappears again. Just like when i enter the wrong code.Than it has to say: Acces Denied. But it don’t.
Problem 3:
When i start up my arduino and i enter my code the servo does what is has to do and the green led blinks.
But when i enter my code for the second time (or more) it says my code is wrong.
Who can help me?
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
Servo myservo;
//constants for LEDs
int greenLED = 22;
int redLED = 23;
LiquidCrystal lcd(13, 12, 11, 5, 4, 3, 2);
Password password = Password( "5144" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3','A', }
,
{
'4','5','6','B', }
,
{
'7','8','9','C', }
,
{
'*','0','#','D', }
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
39, 38, 37, 36}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
43, 42, 41, 40}; //connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
keypad.setDebounceTime(50);
displayCodeEntryScreen();
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
myservo.attach(53);
myservo.write(180);
//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
void displayCodeEntryScreen()
{
lcd.clear();
Serial.begin(9600);
lcd.setCursor(2, 0);
lcd.print("Enter Code:");
lcd.setCursor(0,1);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
//setup and turn off both LEDs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
void loop(){
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case '#':
checkPassword();
break;
case '*':
displayCodeEntryScreen(); break;
default:
password.append(eKey);
}
switch (keypad.getState()){
case PRESSED:
switch (eKey){
case 'D': myservo.write(180);
}
}
}
}
void checkPassword(){
if (password.evaluate()){
digitalWrite(greenLED, HIGH);
lcd.clear();
delay(30);
lcd.setCursor(1, 0);
lcd.print("Acces Granted");
lcd.setCursor(4, 1);
lcd.print("Welcome");
delay(2500);
unlockdoor();
displayCodeEntryScreen();
}
else{
digitalWrite(redLED, HIGH);
lcd.clear();
delay(10);
lcd.setCursor(2, 0);
lcd.print("Acces Denied");
delay(2500);
lcd.clear();
displayCodeEntryScreen();
}
}
void unlockdoor(){ //controls servo that locks the door
myservo.write(90);
digitalWrite(greenLED, HIGH);
delay(5000);
}