Doesn't match String from Serial Input

Hi all,

I am trying to read the text which I am sending/typing on the serial monitor. and reading that text or char to match with a letter and then making IR send. But it is not matching. And if it matches it always takes the first condition for turning On only.

Here's my code:

void loop(){
  if (Serial.available()>0){
    delay(50);
    if (Serial.readString() == "on" or 1){
      mySender.send(tv_on,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
      Serial.println(F("TV is ON/OFF"));
    }
    if(Serial.readString() == "up" or 2){ 
      delay(50);
      mySender.send(tv_volume_up,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
      Serial.println(F("TV Volume is UP"));
    }
    if (Serial.readString() == "down" or 3){ 
      delay(50);
      mySender.send(tv_volume_down,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
      Serial.println(F("TV Volume is Down"));
    }
    if (Serial.readString() == "m"){ 
      delay(50);
      for (int i = 50; i > 0 ; i--){
        mySender.send(tv_volume_down,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
        Serial.println(F("TV is Mute"));
        delay(40);
      }
    }
  }
}

Please Help me regarding this.

"or 1" "or 2" .. is the same as "or true". so all your ifs are always true so the first wins.

the Serial Monitor can sends line ending characters. so the read String could be "on\n" not "on".

if you read to a String the recieved characters are 'moved' into String. so the next readString reads nothing

so do

String s = Serial.readStringUntil('\n');
s.trim();

if (s == "on") {
} else if (s == "up") {
}

Juraj:
"or 1" "or 2" .. is the same as "or true". so all your ifs are always true so the first wins.

the Serial Monitor sends line ending characters. so the read String is "on\n" not "on".

if you read to a String the recieved characters are 'moved' into String. so the next readString reads nothing

so do

String s = Serial.readStringUntil('\n');

s.trim();

if (s == "on") {
} else if (s == "up") {
}

ok Sir, Wait I will try.

Thank you so much, Sir. It worked like a charm.