Created
March 6, 2019 08:35
-
-
Save slav123/f5062a588a167eabf3806f49081f6d94 to your computer and use it in GitHub Desktop.
Arduino double relay keypad lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keypad.h> | |
#define PasswordLength 5 | |
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] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad | |
byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad | |
char Data[PasswordLength]; | |
char Master[PasswordLength] = "1234"; | |
char Slave[PasswordLength] = "1235"; | |
byte data_count = 0; | |
int piezoPin = 13; | |
int Relay1 = 10; | |
int Relay2 = 11; | |
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); | |
void setup(){ | |
//Serial.begin(9600); | |
pinMode(Relay1, OUTPUT); | |
pinMode(Relay2, OUTPUT); | |
} | |
void loop(){ | |
char key = keypad.getKey(); | |
if (key){ | |
// Serial.println(key); | |
Data[data_count] = key; | |
data_count++; | |
if (key == '*') { | |
clearData(); | |
} | |
} | |
if (data_count == PasswordLength-1) { | |
if (!strcmp(Data,Master)) { | |
// Serial.println("goood"); | |
tone(piezoPin, 2000, 500); | |
digitalWrite(Relay1, HIGH); | |
delay(3000); | |
digitalWrite(Relay1, LOW); | |
tone(piezoPin, 2000, 500); | |
} else if (!strcmp(Data,Slave)) { | |
tone(piezoPin, 2000, 250); | |
digitalWrite(Relay2, HIGH); | |
delay(30000); | |
digitalWrite(Relay2, LOW); | |
tone(piezoPin, 2000, 250); | |
} | |
else { | |
//Serial.println("fail"); | |
tone(piezoPin, 1000, 500); | |
} | |
//Serial.println(Data); | |
clearData(); | |
} | |
} | |
void clearData(){ | |
while(data_count !=0){ | |
Data[data_count--] = 0; | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment