display all characters at once in serial monitor

I'm using this code...

void loop () {
If (btserial.available() > 0 ) {
 char c = btserial.read();
val += c;

if (val == "Faculty") {
Serial.println("ten steps to the right");
}

else {
Serial.println(val)
}
}
}

if the data read is not "Faculty" it will display it in the serial monitor. I try sending "Storage". this must be displayed in the serial monitor but it display like this:

Sststostorstorastoragstorage

I think this must be because it reads one character at a time. What would be the method to display when it reads all the characters?

Several issues. First, Serial.read() only reads one byte at a time. If you want to check for a complete string of characters, take a look at Serial.readBytesUntil(). That allows you to continue reading until some character is read, usually a newline ('\n') character. (Using the Serial monitor, the newline character is sent when the user clicks Send.)

Next, you can't compare string data with a simple if statement. Check out strcmp() instead.

Thanks sir! I will look on to that topic :slight_smile:
Serial.readBytesUntil() and strcmp()

As was pointed out in your other thread you are not clearing the value from the val variable after printing so when you add more characters to it no wonder that you get odd results.

Saludos

Try this:

String val= "";
void loop () {
  if(btserial.available() > 0 ) {
    char c = btserial.read();
    if( c == '\n'){
      if (val == "Faculty") {
        Serial.println("ten steps to the right");
      }
      else {
        Serial.println(val);
        }
      }
    else    
    {
      val += c;  
    }
  }
}

Just remember you need to send a new line command '\n' or 0x0d after the message to check.

Your code won't work if val is a char array.
And it won't work if val is an object of the String class either.

Decide which method you are going to use, and then stick to it.