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.

Arduino Code For Password Protected Switch Keypad

Go down

Arduino Code For Password Protected Switch Keypad Empty Arduino Code For Password Protected Switch Keypad

Post by jamied_uk 17th December 2016, 20:38

Vid

Arduino Code

Code:
/*
||  Simple Password Entry Using Matrix Keypad
||  4/5/2012 Updates Nathan Sobieck: Nathan@Sobisource.com
||  Updated 17/12/2016 J~Net
*/

//* is to validate password  
//# is to reset password attempt
/////////////////////////////////////////////////////////////////
#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip

Password password = Password( "5612" );
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(11, OUTPUT);  //green light
  pinMode(12, OUTPUT);  //red light
  Serial.begin(9600);
  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("Authentication Successful: ");
    Serial.println(eKey);
    switch (eKey){
      case '#': checkPassword(); break;
      case '*': password.reset(); break;
      default: password.append(eKey);
     }
  }
}

void software_Reset()
// Restarts program from beginning but
// does not reset the peripherals and registers
{
  asm volatile ("  jmp 0"); 
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Authentication Successful");
    //Add code to run if it works
    digitalWrite(11, HIGH);//turn on
    delay(3000); //wait 3 seconds
    digitalWrite(11, LOW);// turn off
    http://Serial.write("*");    //reset loop here
    http://Serial.println("*");    //reset loop here
    software_Reset();
  }else{
    Serial.println("Authentication Failed!");
    //add code to run if it did not work
  }
}

Download app.box.com/s/8s6xgritvcnecuib17hm


The code above resets the arduino board upon successful Switch so that the user does need to press * the code for this is below in case you don't want this or in case you want to use that function in other projects

Code:

[size=12]void software_Reset()
// Restarts program from beginning but
// does not reset the peripherals and registers
{
  asm volatile ("  jmp 0");  
}[/size]


Last edited by jamied_uk on 17th December 2016, 20:41; edited 1 time in total
jamied_uk
jamied_uk
Admin

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

https://jnet.sytes.net

Back to top Go down

Arduino Code For Password Protected Switch Keypad Empty Re: Arduino Code For Password Protected Switch Keypad

Post by jamied_uk 17th December 2016, 20:39

Other code links

xappsoftware.com/wordpress/2013/06/24/three-ways-to-reset-an-arduino-board-by-code

playground.arduino.cc/Main/InterfacingWithHardware#Output

instructables.com/id/Arduino-door-lock-with-password/step6/CODE
jamied_uk
jamied_uk
Admin

Posts : 2943
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