Hi All,
I have a 4x3 keypad and I wanted to make a security system on it, to get started I already have the (red) LED and (green)LED working on the sketch as ARM and DISARM features. I was thinking to add a bit, like making the siren switch On whenever I enter (3) wrong password repeatedly.
I can't figure it out.
Appreciate any inputs, thanks!
#include <Password.h>
#include <Keypad.h>
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//PIN assignments
int alarmSiren = 11;
int redLED = 10;
int greenLED = 9;
void setup(){
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
pinMode(alarmSiren, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop()
{
keypad.getKey();
//######Siren on when 3 wrong repeated PIN entered####
int i;
for(i=0; i<4;i+1);
if(i==3)
{
digitalWrite(alarmSiren, HIGH);
}
}
//########################################
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '*': checkPassword(); break;
case '#': password.reset(); break;
default: password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
Serial.println("Success! System Disarmed");
digitalWrite(greenLED, HIGH);
delay(100);
digitalWrite(greenLED, HIGH);
delay(100);
}else{
Serial.println("Wrong");
}
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, HIGH);
delay(100);
}