password activated garage

Hi Guys

I need help i am building a multilevel garage with acces control. i am fairly new to programming so far i have gotten the the keyboard programmed correct. what i need help with is the garrage is supposed to be controlled by entering your pass word and the front gate opens and if you have a spot underground then the spot is lifted so that you can park. then your supposed to push one button and the spot is lower back down. i have three different spots so need each password to activiate a different motor. can anyone help me out i would really appriciate it .

What do you have so far?

right now i dont have anything i have been trying to tweet this code :

#include <Password.h>
#include <Keypad.h>
#include <Servo.h> //tells to use servo library

Servo myservo; //declares servo
Password password = Password( "your_password" ); //password to unlock box, can be changed

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] = { 5, 4, 3, 2 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6, 9 };

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

void setup(){
Serial.begin(9600);
Serial.print(254, BYTE);
Serial.print(0x01, BYTE);
delay(200);
pinMode(11, OUTPUT); //green light
pinMode(12, OUTPUT); //red light
myservo.attach(13); //servo on digital pin 9 //servo
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
keypad.getKey();
myservo.write(0);
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:

Serial.print("Enter: ");
Serial.println(eKey);
delay(10);

Serial.print(254, BYTE);

switch (eKey){
case 'A': checkPassword(); delay(1); break;

case 'B': password.reset(); delay(1); break;

default: password.append(eKey); delay(1);
}
}
}
void checkPassword(){

if (password.evaluate()){ //if password is right open box

Serial.println("Accepted");
Serial.print(254, BYTE);delay(10);
//Add code to run if it works
myservo.write(5); //160deg

digitalWrite(11, HIGH);//turn on
delay(500); //wait 5 seconds
digitalWrite(11, LOW);// turn off

}else{
Serial.println("Denied"); //if passwords wrong keep box locked
Serial.print(254, BYTE);delay(10);
//add code to run if it did not work
myservo.write(0);
digitalWrite(12, HIGH); //turn on
delay(500); //wait 5 seconds
digitalWrite(12, LOW);//turn off

}
}

but i dont think it is what i need i got it from Access control with Arduino + Keypad 4x4 + Servo on instructable but i cant tweek it to using multiple codes

i have been trying to tweet this code

That's way longer than the character limit for a tweet.

Please use code tags when posting code.

That code look like it contains a password.evaluate() function. Could we see that? If you want to use multiple passwords that might be where you need to go.

I'm unfamiliar with those libraries so forgive me if it is built-in or something.

That code look like it contains a password.evaluate() function. Could we see that?

It's part of the Password library, so, yes you can.

But, OP, that's a clue. You need several instances of the Password class, and you need to call evaluate for each of them. At most, one will return true, and that one causes you to activate one of the motors.

As soon as I made that post, I had the thought that it might be built in and made my edit.

Edit: Yeah, I can see

bool Password::evaluate(){ 
	char pass = target[0];
	char guessed = guess[0];
	for (byte i=1; i<MAX_PASSWORD_LENGTH; i++){ 
etc

where it is going to walk TARGET and GUESS character by character to check them, and I can see that it makes sense not to mess with that part but instead to feed that code pass, pass1, pass2, etc for multiple passwords, but I can also see that is programming above my current level so I am no help here.

If you want, you can check out my password library. It is designed for multiple passwords and users.

Newer version at bottom of page LINK HERE

The code that I provided is not my code I didn't write it I was using it because it was kind of what I was trying to do. I am not sure what code tags are. and I meant I was tweaking it not tweeting it.

Click on the hashtag icon above your post as you are typing it and code tags will surround your code so it appears highlighted in your post. Makes it easier for people to read your code.
Much like quote tags.

Hi guys so i am still have problems trying to get this code written i don;t know exactly what i am doing.. here is one code that i am trying if anyone can help i would appreciate it

#include <Password.h>
 #include <Keypad.h>
 



 Password password = Password( "1103" ); //password to unlock box, can be changed
 Password password2 = Password ("C");
 Password password3 = Password ("1102");
 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] = { 9, 8, 7, 6};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
 byte colPins[COLS] = { 5, 4, 3, 2 };


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

 void setup(){
   Serial.begin(9600);
   Serial.write(254);
   Serial.write(0x01);
   delay(200);

   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("Enter: ");
   Serial.println(eKey);
   delay(10);
  
   Serial.write(254);
  
   switch (eKey){
     case '#': checkPassword(); delay(1); break;
    
     case 'B': password.reset(); delay(1); break;
     
     case 'C': checkPassword(); delay(1); break;
    
    
      default: password.append(eKey); delay(1);
 }
 }
 }
 void checkPassword(){
  
 if (password.evaluate()){  //if password is right open box
    
     Serial.println("Accepted");
     Serial.write(254);delay(1);
     //Add code to run if it works
pinMode(13, OUTPUT);
digitalWrite (13, HIGH);
delay(5000);
digitalWrite (13, LOW);
    
         digitalWrite(11, HIGH);//turn on
     delay(500); //wait 5 seconds
     digitalWrite(11, LOW);// turn off
    
    
 }else{
     Serial.println("Denied"); //if passwords wrong keep box locked
     Serial.write(254);delay(1);
     //add code to run if it did not work

     digitalWrite(12, HIGH); //turn on
     delay(5000); //wait 5 seconds
     digitalWrite(12, LOW);//turn off
    
 }
 }

What i need is for each password to control a different motor. the code i posted with this is a code i found and have been trying to tweak it to do what i need.... my project is due in a couple weeks and this is really kicking my butt, i am extremely new to programming any help or suggestion would be greatly apprieciated

You have 3 passwords yet looking at your code, your only checking the first one.

How do i check for the others.

You first need an array, like so.
Password PWs[ 3 ] = { password, password2, password3 };

Next, instead of putting the password directly into password.append(eKey); , you'll need to make a new char array to hold the password, then put it into the append( ) function.

Finally, you need to evaluate each password and if the password does not match increment the password array.

if (PWs[ idx ].evaluate())  
  // show password is good message

else  idx++;

if( idx == 3 ) // if idx has reached the maximum number of passwords, show password was not found.

thanks
but where exactly in the code would i put that and also where it says password, password2 etc is that where i put my passwords

Password password = Password( "1103" ); //password to unlock box, can be changed
Password password2 = Password ("C");
Password password3 = Password ("1102");

Password PWs[ 3 ] = { password, password2, password3 };
Thats it for that part.

Where you put it is up to you, you can make a new function or put it in the main loop() function.

Ok this is what i have

#include <Password.h>
 #include <Keypad.h>
 


Password PWs[ 3 ] = { "1103", "1102", "1101" };
 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] = { 9, 8, 7, 6};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
 byte colPins[COLS] = { 5, 4, 3, 2 };


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

 void setup(){
   Serial.begin(9600);
   Serial.write(254);
   Serial.write(0x01);
   delay(200);

   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("Enter: ");
   Serial.println(eKey);
   delay(10);
  
   Serial.write(254);
  
   switch (eKey){
     case '#': checkPassword(); delay(1); break;
    
     case 'B': Password.reset(); delay(1); break;
     
     case 'C': checkPassword(); delay(1); break;
    
    
      default: password.append(eKey); delay(1);
 }
 }
 }
 void checkPassword(){
  
 if (password.evaluate()){  //if password is right open box
    
     Serial.println("Accepted");
     Serial.write(254);delay(1);
     //Add code to run if it works
pinMode(13, OUTPUT);
digitalWrite (13, HIGH);
delay(5000);
digitalWrite (13, LOW);
    
         digitalWrite(11, HIGH);//turn on
     delay(500); //wait 5 seconds
     digitalWrite(11, LOW);// turn off
    
    
 }else{
     Serial.println("Denied"); //if passwords wrong keep box locked
     Serial.write(254);delay(1);
     //add code to run if it did not work

     digitalWrite(12, HIGH); //turn on
     delay(5000); //wait 5 seconds
     digitalWrite(12, LOW);//turn off
    
 }
 }

its giving me an error

Expected unqualified-id before ',' token

This is wrong.

Password PWs[ 3 ] = { "1103", "1102", "1101" };

You need this, don't change anything here.

Password password = Password( "1103" ); //password to unlock box, can be changed
Password password2 = Password ("C");
Password password3 = Password ("1102");

Password PWs[ 3 ] = { password, password2, password3 };

Where is the part or function that collects the chars for your password?

you'll need to make a new char array to hold the password, then put it into the append( ) function.

i am not sure but is this correct for the char array

char passwords;
char datatest[number_of_passwords][length_of_password]={
{ 
'1','1','0','3' }
, // Password
{ 
'1','1','0','2' }
, // Password2
{ 
'1','1','0','1' }
, // Password3
{

and thank you so muchI really appreciate all your help

This is what you need.

Note: This is pseudo code.

#define Password_Lenght 4
char Data[Password_Lenght + 1]; // 4 is the number of chars it can hold + 1 for NULL char
byte idx = 0;
.
.
.
  // this could be in your loop() or its own function.
  customKey = customKeypad.getKey(); // my method, but you can use eKey instead
  if (customKey) // check if a key is actually pressed.
  {
      if( currentKey == Password_Lenght  + 1)
      {
          checkPassword( Data );
          currentKey = 0;
      }
      else 
      { 
          Data[ currentKey ] = customKey; // currentKey is first set to 0.
          Data[ currentKey++ ] = '/0';  // Add a null char to the end if needed and increment currentKey every time you enter a new key.
      }
  }
.
.
.
void checkPassword( char * myPass)
{
  PWs[ idx ].append( myPass ); // idx = 0
  if (PWs[ idx ].evaluate())  
    // show password is good message
  else  idx++;

  if( idx == (Password_Lenght - 1) ) // if idx has reached the maximum number of passwords, show message "password was not found".
}

You can also use "idx" to switch case statements for your motors. Once the password is checked either good or not found, and your done with your motors, you need to reset idx back to 0.