PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

keypad password arduino code!

Go down

keypad password arduino code! Empty keypad password arduino code!

Post by jamied_uk 17th September 2014, 15:23



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
keypad password arduino code! Attachment
keypad_pass_door_unlocker.zip 3 Files zipped upYou don't have permission to download attachments.(26 Kb) Downloaded 0 times
jamied_uk
jamied_uk
Admin

Posts : 2942
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum