Here is an example I wrote a while back to do numeric passwords from keypad.
#include <Keypad.h>
// Combination is "08675309"
// Use any value up to 4 billion
// NOTE: 08675309 is not a valid number and will
// not compile. The leading zero means 'octal
// constant' and the digits 8 and 9 are not valid
// octal digits.
//
// To get leading zeroes, set CombinationLength
// higher than the number of digits
const unsigned long Combination = 8675309;
const byte CombinationLength = 8;
const byte ROWS = 4; // set four rows
const byte COLS = 4; // set four columns
const char keys[ROWS][COLS] = // Define the keymap
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = { 36, 34, 32, 30 };
byte colPins[COLS] = { 28, 26, 24, 22 };
// Create the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long InputValue = 0;
byte InputLength = 0;
void setup() {
Serial.begin(115200);
pinMode(46, OUTPUT); // Set green LED as output
pinMode(48, OUTPUT); // Set red LED as output
}
void loop()
{
char key = keypad.getKey();
switch (key)
{
case '*': // Clear
InputValue = 0;
InputLength = 0;
break;
case '0'...'9':
InputValue *= 10;
InputLength++;
InputValue += key - '0';
break;
case '#': // Enter
if (InputLength == CombinationLength && InputValue == Combination)
{
Serial.println("Success, Come inside"); // If the password is correct
digitalWrite(46, HIGH); // Turn on green LED
delay(500); // Wait 5 seconds
digitalWrite(46, LOW); // Turn off green LED
}
else
{
Serial.println("Access Denied"); // If the password is incorrect
digitalWrite(48, HIGH); // Turn on red LED
delay(500); // Wait 5 seconds
digitalWrite(48, LOW); // Turn off red LED
}
InputValue = 0;
InputLength = 0;
break;
} // switch(key)
} // loop()