I am using a mashup of parts though. Have a 4x4 keypad, LCD screen that runs on just 2 wires for signal, 4 relay board and an Uno.
Its works, once. I can't get it to reset for the next password. I was thinking of using a sensor that says the door has been opened to reset it or set off the alarm if the password was not used.
I am looking for just a little guidance. I need to finish out the build and the code. The LCD has an RGB LED in it and I want to use that to indicate some of the status. I only have 2 digital pins left and all the analog. With the door senor on those last two digital pins I'm not sure how to do the RGB LED but I am thinking the analog can run it.
Right now, can anyone help with the reset for the next password?
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Password password = Password( "1234" );
unsigned char WrongAttempts = 0; //global variable to keep the number of wrong attempts done at the code.
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10, 11, 12, 13}; //connect to the column pinouts of the keypad
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//PIN assignments
int r1 = 2; //alarm
int r2 = 3; //green light
int r3 = 4; //Red light
int r4 = 5; //Nothing?
void setup(){
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
lcd.init(); // initialize the lcd
lcd.backlight();
// Print a message to the LCD.
//lcd.setCursor(0, 1);
lcd.print("Security Status");
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(r4, OUTPUT);
}
void loop()
{
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.setCursor(0, 1);
lcd.print("Pressed: ");
lcd.println(eKey);
switch (eKey){
case '*': checkPassword(); break;
case '#': password.reset(); break;
default: password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
lcd.clear();
lcd.println("Success!");
lcd.println("Disarmed!");
digitalWrite(r1, LOW); //DISCONNETC THE SIREN IF THE PASSWORD IS CORRECT
digitalWrite(r2, HIGH);
delay(2000);
digitalWrite(r3, HIGH);
delay(100);
}else{
lcd.clear();
lcd.println("Wrong");
delay(1000);
lcd.clear();
WrongAttempts++;
if (WrongAttempts >= 3) { //UPS....
digitalWrite(r1, HIGH); //START THE SIREN
digitalWrite(r3, HIGH); //START THE REDNESS
lcd.clear();
lcd.print("Alarm Activated");
}
}
digitalWrite(r2, HIGH);
delay(100);
digitalWrite(r2, HIGH);
delay(100);
}