If you set your Serial Monitor's line ending to "Both NL & CR", then this code will find the word "send". It will NOT find the word "send" in this string, "ssend" or in this string, "sendd".
void setup(){
Serial.begin(9600);
}
void loop(){
while(Serial.available() > 0 ){
String str = Serial.readString();
if(str.substring(0) == "send\r\n"){
Serial.println("identified");}
else{
Serial.println("unknown");
}
}
}
If you want to find the string "send" in "1234send" or "send1234" or "1234send5678" then use indexOf();
void setup(){
Serial.begin(9600);
}
void loop(){
while(Serial.available() > 0 ){
String str = Serial.readString();
if(str.indexOf("send") > -1){
Serial.println("identified");}
else{
Serial.println("unknown");
}
}
}