Help please!

Please help ive a code that make a password for the Keypad in the LCD and it is working good
But its only defined as "1234"
how can I add a button when I click it it tell me to add new pass and it store it instead of the "1234"

Please post the code as it is now

it got other scripts in it like Temp and ultrasonic

#include <Password.h>

#include <Keypad.h>

#include <LiquidCrystal.h>

#include <Wire.h>

#include <Servo.h>

Servo myservo;
float tempC;
int reading;
int tempPin = A5;
const int trigPin = 12;
const int echoPin = 11;
// defines variables
long duration;
int distance;
int pos = 0;
int i = 0;
int count = 0;
Password password = Password( “1234” );

LiquidCrystal lcd( A0, A1, A2, A3 , A4, 13);

const byte ROWS = 4;

const byte COLS = 4;

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 to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

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

void setup()

{

myservo.attach(9);

lcd.begin(16, 2);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT);// Sets the echoPin as an Input
pinMode(10, OUTPUT);
analogReference(INTERNAL);
lcd.print(" Enter Password");

Serial.begin(9600);

keypad.addEventListener(keypadEvent);

keypad.setDebounceTime(250);

}

void loop()

{
reading = analogRead(tempPin);
tempC = reading / 9.31;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor

//lcd.setCursor(0, 1);

keypad.getKey();

}

void keypadEvent(KeypadEvent keyPress)

{

switch (keypad.getState())

{

case PRESSED:

lcd.setCursor(i++,1);
lcd.print("*");
switch (keyPress)

{

case ‘#’:

if(count < 4)
{
checkPassword();
}
if(count == 3)
{
i = 0;
lcd.clear();
lcd.print(“wait 10 sec”);
lcd.setCursor(i++, 1);
lcd.print(“and try again”);
digitalWrite(1, HIGH);
delay(10000);
lcd.clear();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Enter Password");
count == 0;
}
i = 0;
break;

case ‘*’:

password.reset();

lcd.clear();
i = 0;
lcd.setCursor(0, 0);

lcd.print(" Enter Password");

break;

case ‘A’:

lcd.clear();
i = 0;
lcd.setCursor(0, 0);

lcd.print(“LASER:ON”);

delay(2000);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(" Enter Password");

break;

case ‘B’:

lcd.clear();
i = 0;
lcd.setCursor(0, 0);

lcd.print(“LASER:OFF”);

delay(2000);

lcd.clear();
i = 0;
lcd.setCursor(0, 0);

lcd.print(" Enter Password");

break;

case ‘C’:

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(“LOCKDOWN”);

delay(2000);

for (pos = 180; pos >= 0; pos -= 1)

{

myservo.write(pos);

delay(3);

}

lcd.clear();
i = 0;
lcd.setCursor(0, 0);

lcd.print(" Enter Password");

break;

default:

password.append(keyPress);

}

}

}

void checkPassword() {

if (password.evaluate())

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(“ACCESS”);

lcd.setCursor(0, 1);

lcd.print("*GRANTED");
count = 0;
delay(100);
lcd.clear();
lcd.print("Distance: ");
i = 0;
lcd.print(distance);
lcd.setCursor(i++, 1);
lcd.print(“Temprature= “);
lcd.print(tempC);
lcd.print(”*C”);

delay(10000);

for (pos = 0; pos < 180; pos += 1)

{

myservo.write(pos);

delay(3);

}

delay(2000);

password.reset();

lcd.clear();

lcd.setCursor(0, 0);
// add distance code and temp code and motor code
lcd.print(" Enter Password");

}

else

{

lcd.setCursor(0, 0);

lcd.print(“ACCESS”);

lcd.setCursor(0, 1);

lcd.print(“DENIED”);
count++;
delay(10);

password.reset();

delay(2000);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(" Enter Password");

}

}

(deleted)

What part is confusing you? Do you know how to read a switch? Can you use an if statement to react to that reading? Do you know what variable stores your password? Do you know how to set that equal to something else?

Sounds like he found a sketch somewhere and wants others to make the changes for him.

cheating == bad

how can I add a button when I click it it tell me to add new pass and it store it instead of the "1234"

This is like asking "how can I drive my car down to the corner store?" I can drive your car for you. I can maybe teach you to drive. But I can't just tell you what sequence of pedal-presses and steering-wheel turns will get you to the store.

guys im newbie
and just learning on this scripts not using it
so if u willing to help me you are welcome or please don't talk

Please read the forum "stickies".

            count == 0;

http://www.gammon.com.au/tips#trap3

Student123:
guys im newbie

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

…R

  1. Connect a button to the arduino, google for help
  2. Check if button is pressed, google for help
  3. If button is pressed, then print some text, request an input, then change password

Need any more help, just post your progress clearly

Okay ive tried this but iam getting error

 #include <Password.h>

#include <Keypad.h>

#include <LiquidCrystal.h>

#include <Wire.h>

#include <Servo.h>

Servo myservo;
float tempC;
int reading;
int tempPin = A5;
bool TEST;
int f = 0;
const int trigPin = 12;
const int echoPin = 11;
// defines variables
long duration;
int distance;
int pos = 0;
int i = 0;
int count = 0;
Password password = Password( "1234" );

LiquidCrystal lcd( A0, A1, A2, A3 , A4, 13);

const byte ROWS = 4;

const byte COLS = 4;
char customKey;
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 to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

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

void setup()

{

  myservo.attach(9);

  lcd.begin(16, 2);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);// Sets the echoPin as an Input
  pinMode(10, OUTPUT);
  analogReference(INTERNAL);
  lcd.print(" Enter Password");

  Serial.begin(9600);

  keypad.addEventListener(keypadEvent);

  keypad.setDebounceTime(250);

}

void loop()

{
 reading = analogRead(tempPin);
  tempC = reading / 9.31;
  digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor

    //lcd.setCursor(0, 1);

  keypad.getKey();

}

void keypadEvent(KeypadEvent keyPress)

{

  switch (keypad.getState())

  {

    case PRESSED:

      
      lcd.setCursor(i++,1);
      lcd.print("*");
      switch (keyPress)

      {

        case '#':
        
          if(count < 4)
          {
          checkPassword();
          }
          if(count == 3)
          {
            i = 0;
            lcd.clear();
            lcd.print("wait 10 sec");
            lcd.setCursor(i++, 1);
            lcd.print("and try again");
            digitalWrite(1, HIGH);
            delay(10000);
            lcd.clear();
            lcd.clear();  
            lcd.setCursor(0, 0);
            lcd.print(" Enter Password");
            count == 0;
          }
          if(TEST == true)
          {
            customKey = keypad.getKey();
            password = Password(char* customKey);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Your password have been changed");
            delay(2000);
            TEST = false;
             lcd.clear();
          i = 0;
          lcd.setCursor(0, 0);

          lcd.print(" Enter Password");
            
          }
          i = 0;
          break;

        case '*':

          password.reset();

          lcd.clear();
          i = 0;
          lcd.setCursor(0, 0);

          lcd.print(" Enter Password");

          break;

        case 'A':

          lcd.clear();
          TEST = true;
          i = 0;
           lcd.setCursor(0, 0);

          lcd.print("Enter new password");

          lcd.setCursor(i++,1);
          lcd.print(keyPress);
          switch (keyPress)
         
          break;

        case 'B':

          lcd.clear();
          i = 0;
          lcd.setCursor(0, 0);

          lcd.print("LASER:OFF");

          delay(2000);

          lcd.clear();
          i = 0;
          lcd.setCursor(0, 0);

          lcd.print(" Enter Password");

          break;

        case 'C':

          lcd.clear();

          lcd.setCursor(0, 0);

          lcd.print("LOCKDOWN");

          delay(2000);

          for (pos = 180; pos >= 0; pos -= 1)

          {

            myservo.write(pos);

            delay(3);

          }

          lcd.clear();
          i = 0;
          lcd.setCursor(0, 0);

          lcd.print(" Enter Password");

          break;

        default:

          password.append(keyPress);

      }

  }

}

void checkPassword() {

  if (password.evaluate())

  {

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print("*****ACCESS*****");

    lcd.setCursor(0, 1);

    lcd.print("*****GRANTED****");
    count = 0;
  delay(100);
  lcd.clear();
    lcd.print("Distance: ");
    i = 0;
  lcd.print(distance);
  lcd.setCursor(i++, 1);
  lcd.print("Temprature= ");
  lcd.print(tempC);
  lcd.print("*C");
  
  
  delay(10000);

    for (pos = 0; pos < 180; pos += 1)

    {

      myservo.write(pos);

      delay(3);

    }

    delay(2000);

    password.reset();

    lcd.clear();

    lcd.setCursor(0, 0);
    // add distance code and temp code and motor code
    lcd.print(" Enter Password");

  }

  else

  {

    lcd.setCursor(0, 0);

    lcd.print("*****ACCESS*****");

    lcd.setCursor(0, 1);

    lcd.print("*****DENIED*****");
    count++;
    delay(10);

    password.reset();

    delay(2000);

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print(" Enter Password");

  }

}

here in this code

  customKey = keypad.getKey();
            password = Password(char* customKey);

I don’t know how to replace the customKey to read what numbers I have entered when I press “#”(ok) so it store it instead of the “1234”

Student123:
I don't know how to replace the customKey to read what numbers I have entered when I press "#"(ok) so it store it instead of the "1234"

What are you trying to do, actually? The initial value of your password, of "1234" I believe is set directly in the code, in the following statement:

Password password = Password( "1234" );

Then some time later you have at hand a variable called customKey which is of type "char".

You somehow convince the compiler that the following is valid code (?) and update the password with a new instance of the Password class.

password = Password(char* customKey);

I'd say the above shouldn't compile, or if it does, that you can not cast a single "char" variable to "char *", without risking very strange results, depending on what follows that variable in memory.

Second, allocating a new Password object like this, consumes memory. Doing so many enough times, depending on what else inner state the Password object has, will eat up all memory.

Finally, your Password class should probably write the password to EEPROM, so that you can restart the Arduino without losing the custom password you have set.

I would do something like this

Password password = Password("1234");
char* customKey = ""; //this must be a global variable, password.set() uses a pointer, not a copy, which is silly to me

void loop(){
  ...
  customKey = keypad.getKey();
  password.set(customKey);
  ...
}

Rupert909:
What are you trying to do, actually?

I think he wants to press a key (eg. #) followed by 4 digits. This becomes the new password.

I think he wants to press a key (eg. #) followed by 4 digits. This becomes the new password.

Then he/she needs to pay attention to what methods are available in the Password class, instead of just whining.

He/she also needs to pay attention to how those methods are implemented, and figure out how to deal with the fact that the new password assigned is not actually replacing the existing password in memory.

Whether the changes should be persisted across resets, or not, has not been made clear.