Keypad Entry with Multiple PIN Numbers


hi.

i'm quite new hope can me please?

i making basic keypad entry system.

the code below:

code: [select]

/*

       this sketch takes input keypad pin code. 
       
       if code entered correctly, turns on green led simulate access granted.                                         
                                                                                     
       if invalid code entered, red led lit.                                                         

*/


#include <keypad.h>          // include keypad library.


#define greenled 10    // define green led digital pin 10.
#define redled 11      // define red led digital pin 11.


char* ourcode = "1974";      // set required pin code.
int currentposition = 0;     // keeps track of position of code entered.



const byte rows = 4;          // define amount of rows , columns keypad.
const byte cols = 4;

char keys[rows][cols] = {      // define characters of keypad.
  {'1','2','3','a'},
  {'4','5','6','b'},
  {'7','8','9','c'},
  {'*','0','#','d'}
};

byte rowpins[rows] = {2,3,4,5};    // define pins connected keypad.
byte colpins[cols] = {6,7,8,9};

keypad keypad = keypad(makekeymap(keys), rowpins, colpins, rows, cols);      // initialize keypad.



void setup()
{
    pinmode(redled, output);        // set led pins outputs.
    pinmode(greenled, output);
    digitalwrite(redled, low);      // turn leds off.
    digitalwrite(greenled, low);
 
   
       
}

void loop()
{
   int l;
 
   char key = keypad.getkey();      // key press keypad.
 
   if (int(key) != 0) {                    // check see if there value present.
     
     for (l=0; l<=currentposition; ++l)
    { }
   
    if (key == ourcode[currentposition])        // if value correct, increase code position one.
      {
        ++currentposition;
       
        if (currentposition == 4)                // if 4 parts of code correct, unlock door.
        {
          unlockdoor();
          currentposition = 0;
        }
      }
     
     else {
        invalidcode();                           // if parts of code wrong, not open door.
        currentposition = 0;
      }
   
   
  }
}

void invalidcode()
{
  digitalwrite(redled, high);          // code run when incorrect code entered.
  delay(5000);
  digitalwrite(redled, low);
 
}


void unlockdoor()
{
  digitalwrite(greenled, high);        // code simulate unlocking door.
  delay(5000);
  digitalwrite(greenled, low);
 
}





this works fine now.

what able though, have more 1 pin number.
i people able have own pin number.
is possible?
would sketch able check more 1 pin number?

the reason this, on leonardo , log time , person pc.


thanks in advance help.

it's possible, requires fundamental change way validate pins. validate each input against pin , allow user enter endless sequence of numbers until 4 consecutive numbers match expected value. that's unsecure, , in case won't work when need support multiple pins.

instead suggest separate out entering pin validating it. require user enter pin of expected length before validate it. suggest apply timeout between key presses if incomplete pin entered system clear down after little while. store entered pin null-terminated char array.

store valid pins in array of strings (null terminated char arrays).

when whole pin has been entered can validate looping through each of valid pins , using strcmp() test whether entered pin matches entry.

it sensible introduce minimum inter-key delay, , lock keypad out while after each failed attempt, increase time needed 'brute force' attack.

you should consider how going configure , maintain set of pins. in opinion more sensible pin validation , logging on attached pc , use arduino interface keypad , display etc; approach, valid pins defined on pc (where easy display , change) , arduino part can relatively dumb.


Arduino Forum > Using Arduino > Project Guidance > Keypad Entry with Multiple PIN Numbers


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support