Arduino doesnt recognize strings

Im trying to make a code where the arduino gets a string from the serial port and then gives back sensor data based on the string it got but i think that the arduino cant recognize the strings it gives me back the string i wrote and then says command not found

void loop() {
  if (Serial.available()) {
  String komut = Serial.readString();
  Serial.print(komut);  
    if (komut=="gyro") {
    getgyro();
    }else if (komut=="altitude") {
    getaltitude();
    }else if (komut=="gps") {
    getgps();
      }else if (komut=="reset"){
     I2Creset();
      }else{
      Serial.println("command not found");
      }
    }
    
}

this is the part where the problem is i made some custom voids and i call them based on the string it gets when i tried the custom voids and they work

Welcome to the forum

Set the Line Ending of the Serial monitor to "no line ending" to prevent extra characters being added to the String when it is read

trim() - Arduino Reference

String length() and trim() Commands | Arduino Documentation | Arduino Documentation

1 Like

Thanks it works now

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.