password check with 4x4 keyboard

hi,
tnx in advance for your help :wink:
Im building some security system, I use:
keypad.h
password.h
libraries

in the next example (from password librarie),
http://www.arduino.cc/playground/Code/Password

I get the next error just out of examples, PasswordKeypad.pde

error: no matching function for call to 'Keypad::Keypad(byte [4], byte [4], byte&, byte&)'/windows/LinuxProgramas/arduino-0017/hardware/libraries/Keypad/Keypad.h:63: note: candidates are: Keypad::Keypad(char*, byte*, byte*, byte, byte)

/windows/LinuxProgramas/arduino-0017/hardware/libraries/Keypad/Keypad.h:57: note: Keypad::Keypad(const Keypad&)

if I fix it for working with the keyboard, it compiles, but not working, I will need as well some messages for serial to know if it got the right password???

here is the code that compiles, but how does it work??
the led just goes off if I press *

sorry if its a stupid question but I only see the loop calling the keypad.getkey(), how does it compare the password?

tnx

/*
||
|| @file PasswordKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | A simple password application that uses a keypad as input source.
|| #
||
*/

//Arduino Playground - HomePage
#include <Password.h>
//Arduino Playground - HomePage
#include <Keypad.h>

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'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledPin 13

void setup(){

digitalWrite(ledPin, HIGH); // sets the LED on
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 (eKey){
case '*': guessPassword(); break;
case '#': password.reset(); break;
default:
password.append(eKey);
}
}

void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH);
Serial.print("bien");
}else{
digitalWrite(ledPin,LOW);
}
}

tnx

hi,
tnx in advance for your help :wink:
Im building some security system, I use:
keypad.h
password.h
libraries

in the next example (from password librarie),
Arduino Playground - Password Library

I get the next error just out of examples, PasswordKeypad.pde

error: no matching function for call to 'Keypad::Keypad(byte [4], byte [4], byte&, byte&)'/windows/LinuxProgramas/arduino-0017/hardware/libraries/Keypad/Keypad.h:63: note: candidates are: Keypad::Keypad(char*, byte*, byte*, byte, byte)

/windows/LinuxProgramas/arduino-0017/hardware/libraries/Keypad/Keypad.h:57: note: Keypad::Keypad(const Keypad&)

The reason for the first error is that the code is old. And I guess it misses the makeKeyboard macro.

Every time you press a key, you trigger an event, and thus the keypadEvent is called.
If you press anything other than # or * that char gets appended to the 'current' guessed password.

The LED should stay on if you press this sequence:

1 2 3 4 *

If not, post here again, and I'll test the libraries.

Try this code:

//http://www.arduino.cc/playground/uploads/Code/Password.zip

#include <Password.h>
//Arduino Playground - HomePage
#include <Keypad.h>

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'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledPin 13

void setup(){
 
 digitalWrite(ledPin, HIGH);   // sets the LED on
 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){
 Serial.print("Pressed: ");
 Serial.println(eKey);
 switch (eKey){
   case '*': guessPassword(); break;
   case '#': password.reset(); break;
    default:
          password.append(eKey);
 }
}

void guessPassword(){
    Serial.print("Guessing password... ");
    if (password.evaluate()){
          digitalWrite(ledPin,HIGH);
          Serial.print("bien");
    }else{
          digitalWrite(ledPin,LOW);
          Serial.print("n'est bien");
    }
}




Upload that code, press the sequence (1,2,3,4,*) and copy the serial monitor, paste into a post here for me to see :)

hello,
I´ve uploaded the code,

this is the serial answer, after presing #,*, passwrd *

Pressed: #
Pressed: #
Pressed: *
Guessing password... n'est bienPressed: *
Guessing password... n'est bienPressed: 1
Pressed: 1
Pressed: 2
Pressed: 2
Pressed: 3
Pressed: 3
Pressed: 4
Pressed: 4
Pressed: *
Guessing password... n'est bienPressed: *
Guessing password... n'est bien

gracias

Ahh.
Sorry.

This is what happens: The password gets appended the button twice for each press (PRESS and RELEASE)

Try this keypadEvent

void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
      Serial.print("Pressed: ");
      Serial.println(eKey);
      switch (eKey){
        case '*': guessPassword(); break;
        case '#': password.reset(); break;
         default:
               password.append(eKey);
     }
  }
}

Try again with the new keypadEvent and let me know what happens :slight_smile:

THANK YOU
gracias,
great job,
:wink:

I just wanted to thank both of you for your input I am using the Arduino combined with a 3x4 keypad to activate my garage door. Without your help I may have had to delay this project until I gained more experience as I am new to this. I have made a few changes to get the password to reset after the password is accepted or rejected. Also changed it so the # key is used to ENTER the password. As well as debounce because my homemade key pad double entered numbers all the time. I had such a hard time with getting this working until I found this post.

Thanks
Kenny

/#include <Password.h>

#include <Keypad.h>

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3',},
  {'4','5','6',},
  {'7','8','9',},
  {'*','0','#',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledPin 13

void setup(){

  digitalWrite(ledPin, LOW);   // sets the LED on
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  keypad.setDebounceTime(250);
}

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 '#': guessPassword(); break;
         default:
               password.append(eKey);
  }
}}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
           digitalWrite(ledPin,HIGH); //activates garaged door relay
             delay(500);                
             digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
           Serial.println("VALID PASSWORD "); //
              password.reset(); //resets password after correct entry
     }else{
           digitalWrite(ledPin,LOW);
           Serial.println("INVALID PASSWORD ");
              password.reset(); //resets password after INCORRECT entry
     }
}