/* Door Access Relays System on Arduino
*
* Using Matrix Keypad Membrane access password to enable the relays.
*
*/
#include <Keypad.h> // http://arduino.cc/playground/uploads/Code/Keypad.zip
#include <Password.h> // http://arduino.cc/playground/uploads/Code/Password.zip
int relay1 = 2; // Define Arduino Digital pin 2
int relay2 = 3; // Define Arduino Digital pin 3
int relay3 = 4; // Define Arduino Digital pin 4
int relay4 = 5; // Define Arduino Digital pin 5
int locked = 1;
int passinput = 0;
int ledcurrentvar;
int lockedled = 13; // Define pin 13 for Output LED
int unlockedled = 12; // Define pin 12 for Output LED
long flashvarLED = 0;
long flashtimeLED = 300;
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'}};
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {9, 8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Password password = Password("0000"); // Yo can change the password here
void setup(){
Serial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, 255);
pinMode(relay2, OUTPUT);
digitalWrite(relay2, 255);
pinMode(relay3, OUTPUT);
digitalWrite(relay3, 255);
pinMode(relay4, OUTPUT);
digitalWrite(relay4, 255);
pinMode(lockedled, OUTPUT);
digitalWrite(lockedled, 255);
pinMode(unlockedled, OUTPUT);
digitalWrite(unlockedled, 0);
}
void loop(){
char key = keypad.getKey();
if(locked){
if(passinput){
unsigned long currentvarLED = millis();
if(currentvarLED - flashvarLED > flashtimeLED) {
flashvarLED = ledcurrentvar;
digitalWrite(lockedled, !digitalRead(lockedled));
}
}
else{
digitalWrite(lockedled, 255);
}
digitalWrite(unlockedled, 0);
}
if (key != NO_KEY){
Serial.println(key);
password.append(key);
passinput = 1;
if(key == '*'){
password.reset();
passinput = 0;
locked = 1;
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
}
if(password.evaluate()) {
locked = !locked;
password.reset();
passinput = 0;
}
if(!locked) {
passinput = 0;
digitalWrite(lockedled, 0);
digitalWrite(unlockedled, 255);
switch (key) {
case 'A':
digitalWrite(relay1, !digitalRead(relay1));
break;
case 'B':
digitalWrite(relay2, !digitalRead(relay2));
break;
case 'C':
digitalWrite(relay3, !digitalRead(relay3));
break;
case 'D':
digitalWrite(relay4, !digitalRead(relay4));
break;
}
password.reset();
}
}
}
Just a smiling visitor here to share the love (:, btw outstanding style and design.
I have tried to use the above code but i get errors
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/536009369/build -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -libraries /tmp/536009369/pinned -libraries /tmp/536009369/custom -fqbn arduino:avr:uno -build-cache /tmp -logger humantags -verbose=false /tmp/536009369/sketch_dec3a
/tmp/536009369/sketch_dec3a/sketch_dec3a.ino:26:81: error: too many initializers for ‘char [3][4]’
char keys[ROWS][COLS] = {{‘1′,’2′,’3’},{‘4′,’5′,’6’},{‘7′,’8′,’9’},{‘*’,’0′,’#’}};
^
/tmp/536009369/sketch_dec3a/sketch_dec3a.ino:31:1: error: ‘Password’ does not name a type
Password password = Password(“4008”);} // You can change the password here
^
/tmp/536009369/sketch_dec3a/sketch_dec3a.ino:31:38: error: expected declaration before ‘}’ token
Password password = Password(“4008”);} // You can change the password here
^
exit status 1
Any help would be great
Hi! Rich,,, Code has been updated. issue @ the variables/declarations>(unlockedled, lockedled, ledcurrentvar)
Hi.
How do you add pushbutton to this setup. So you can open the door from inside.
Just add a push button as INPUT then attach to any available pin then create a function that calls the relay channel to release solenoid or magnetic lock. do forget to release or reset the password ones open from inside.