Issue with String.equals after reading value from serial UART

I'm reading from a HC 08 hooked up to the serial monitor and trying to prove I can use the bluetooth to receive a message and trigger an action using the android app "Bluetooth Serial Monitor" and the code below:

String str;
void setup() {
Serial.begin(9600);
}

void loop() {
str = "";

if(Serial.available())
{
str = Serial.readString();
Serial.print(str);
if(str.equals("Go")){
Serial.print("Tis True");
}
}

}

If I send "Go", it prints properly in the serial monitor, but the if condition doesn't kick off. If I change the condition to str.equals(str), the condition works. Am I missing something with my compare? A hidden newline or something similar?

use

if (  str.indexOf("Go") >= 0  )

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Got rid of Strings in the code and swapped to Serial.find and I have what I need. Apparently Strings are bad news. Thnx!

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

Serial.print("Start");
if(Serial.find("Go")){
Serial.print("Tis True");
}
Serial.print("Stop");
}

Please read the tutorial referenced in reply #2. I think you are headed in the wrong direction with Serial. find().

It is better approach to read in an entire message, and then analyse it to find out what information it contains.