keypad password arduino code!
Page 1 of 1
keypad password arduino code!
Here is the actual code!
- Code:
#include <Keypad.h>
#include <Password.h>
int door = 12; // door
int led = 13; // led
//* is to reset password attempt 2nd time in a row you use this it will fail...
// unless you reset 1st with *
//# is to validate password
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3','A' }
,
{
'4','5','6','B' }
,
{
'7','8','9','C' }
,
{
'*','0','#','D' }
};
byte rowPins[ROWS] = {
9,8,7,6 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = {
5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(led, OUTPUT);
pinMode(door, OUTPUT);
digitalWrite(door, HIGH);
Serial.begin(9600);
// pinMode(door, OUTPUT);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
void loop(){
keypad.getKey();
}
//take care of some special events
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");
Serial.println("Authorized & Door Unlocked!");
// do unlock here
digitalWrite(door, LOW); // turn the door on (HIGH is the voltage level)
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(8000);
digitalWrite(door, HIGH); // wait for 8 seconds
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
// end of door unlock
}
else{
Serial.println("Wrong Password!");
//add code to run if it did not work
delay(8000);
}
}
The full download code is in attachments the library files need to be put in your libraries folder!
Also can be found here
https://app.box.com/s/8s6xgritvcnecuib17hm
- Attachments
Similar topics
» SMS GSM ARDUINO MODULES
» RFID Cloner Code Arduino
» Arduino Voice Control and code
» Good projects for the arduino
» php code website base full of open source code
» RFID Cloner Code Arduino
» Arduino Voice Control and code
» Good projects for the arduino
» php code website base full of open source code
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum