HELP, problems with Serial.readString()

Hello have very simple code but cant get it to do what i want. I want the serial monitor to print "identified" and not unknown but it doesent happen when i type the word "send". Why is not the condition in the if-sentence true? And is it: if (... == "") or if (... == ' ')? thanks

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

void loop(){
  while(Serial.available() > 0 ){
    str = Serial.readString();
    if(str == "send" or str == 'send'){
      Serial.println("identified");} 
    else{
      Serial.println("unknown");
    }
  }
}

Before you get the usual " do not use String ".
You need to use String function / method to compare them, not just “==” or “!=” .
Then evaluate the return values > < when not compared - and when compared returns zero.
if( ! String method to compare stings )
= 0 they match
< > they do not match

I did not quite understand that, could you perhaps edit my code to work right?

(deleted)

String or string, 'send' is not ever right. Single quotes(') are for single characters ('c'), double quotes (") are for charcter arrays (strings) or String objects.

str = Serial.readString();
If (str.equals(“send”)) print something
Else print something else

Sorry, I forgot that this "forum" has no reference for String
So I used Mrs Google to look for "String in C++"
And here is a link to "compare" function / method.
Study it and then come back for more help.
It is really not that difficult, after you get out of "cut and paste" mode.
Try it.

http://www.cplusplus.com/reference/string/string/compare/

You need to use String function / method to compare them, not just "==" or "!=" .

Rubbish. The String class overloads the == and != operators. The method of comparing Strings is perfectly acceptable.

OP: What is sending the strings to the Arduino? If you are using the Serial Monitor, what line ending do you have? The trim() method might prove useful.

Why does not this work? Tried to use numbers insted
Edit: Sorry it does work;)

if (Serial.available()>0){
    Serial.println("Inni lokke");
    int ch = Serial.read();
    Serial.println(ch);
    if (ch == '1'){aapne();}
    if (ch == '2'){lukke();}
    if (ch == '3'){aapne2();}
    if (ch == '4'){lukke2();}
  }

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

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. Just use cstrings - char arrays terminated with 0.

When using Cstrings you must use strcmp() to compare values rather than ==

...R

Ok, maybe its wrong to use int and i read your post about basic serial inputs but i dont understand what I could replace it with. Is example 6 the wright one to use in my case?

I also have another question: Is it correct to use eeprom.write() to store a number permanently, when the arduino has no power?

I also have another question: Is it correct to use eeprom.write() to store a number permanently, when the arduino has no power?

Yes, that is what EEPROM is for.

ArduinoBeginner01:
Ok, maybe its wrong to use int and i read your post about basic serial inputs but i dont understand what I could replace it with.

I don't understand.

Wrong to use int for what?

Is example 6 the wright one to use in my case?

Why not use Example 2 or 3 and send the data in human readable form? It makes debugging much easier.

...R

on the serial monitor, select "no line ending" option, issue is its sending additional characters.