First, I'd suggest that you make the variable to hold the input password an array so as to do the following condition checkPS:
char input_password[6] //I put 6 here assuming that your password is a six-digit password
// rest of the initialisation code (including void setup()) beneath this
void loop(){
int counter = 0
if(Serial.available() & (input_passwrod[5] == NULL)){
input_password[counter] = char(Serial.readString());
counter++;
delay(1000); // a delay of one second to make the flow a bit
// smooth.
/* Reducing the delay may also work, but I put a one-second delay
considering how slow others may type */
}
//rest of the code here
}
Another @lurker's suggestion in the comments :- check the code would run smoothly if you add a delaybaud rate setting in your serial monitor as well at the appropriate places.
PSEDIT: Those who wish to editI admit that the code in the previous version of this answer may editwas foolishly typed out by me due to lack of patience, so I'll make up for my mistake(not in code, but as wella full answer).
First of all, I doubt if the condition input_password[5] == NULL anddidn't understand what you wanted to do with the statement input_password[counter] = char(Serial.readString())Incoming_value were rightly stated.
PS: @lurker's suggestionvariable in your sketch, so I'm not gonna talk about it; I'd suggest adding a sufficiently small delay at the comments - checkend of the baud rate settingcode in yourthe loop. This should provide the serial monitor as wellport some time to handle the incoming data and stop printing the confusing output (perhaps; just because delays make your microcontroller wait for a while to get things done elsewhere , especially where the reception of data is slow and thus avoid collisions)
Also note that I am not a CS student or an electronics geek, but I am speaking from my guesswork. Any correction is accepted.