char received[4];
char correct[4] = {'Q','W','E','R'};
boolean result;
void setup()
{
pinMode(lock, OUTPUT);
Serial.begin(9600);
digitalWrite(lock, LOW);
}
void loop()
{
int i = 0;
int j = 0;
Serial.println("Enter Password");
while(Serial.available() >= 4)
{
while(i<4)
{
received[i] = Serial.read();
i++;
}
while(j < 4)
{
if(received[j]==correct[j])
{
result = true;
}
else
{
result = false;
break;
}
}
}
if(result == true)
{
digitalWrite(lock, HIGH);
Serial.println("Locked");
}
else
{
digitalWrite(lock, LOW);
Serial.println("Unlocked");
}
}
I am making a small project on door access using Bluetooth.
My problem here is after i receive the message Enter Password on the Serial monitor, it is not allowing me to enter the password and is directly showing the message unlocked.
My aim is to change it in a way such that when i get the message Enter Password on the Serial Monitor, i should enter the password then it must get compared with the correct password and then display locked or unlocked. I have tried different things but I am unable to get it.
I am new to Arduino and C programming. Any help would be appreciated. Thanks in advance.