My LED won't blink with if statement

Hey everyone i have encounterd a problem while trying to creat a project in which the user will input the LED color name and the right LED color will blink.
When i'm typing the LED color name it won't blink and im not sure why.
I have checked the components with individual digitalWrite command and they all work.
i'm assuming there is a problem with String reading or with the if statement.
I apolgize in advance for not using the function that makes the code visible as in the arduino coding program - I have simply haven't found here any instructions on how to do so, so I'd be glad if someone would shortly explaing how to do so also.
The code is as following:
String msg1 = "What color you want the LED to turn on?";
String LEDcolorpicked;
int yellowled = 2;
int redled = 3;
int blueled= 4;
void setup() {
// put your setup code here, to run once:
pinMode (yellowled,OUTPUT);
pinMode (redled,OUTPUT);
pinMode (blueled,OUTPUT);
Serial.begin (9600);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println (msg1);
while (Serial.available()==0){

}
LEDcolorpicked= Serial.readString();
Serial.println (LEDcolorpicked);
if (LEDcolorpicked=="yellow"){
digitalWrite (yellowled,HIGH);
digitalWrite (redled, LOW);
digitalWrite (blueled, LOW);
}
if (LEDcolorpicked == "red"){
digitalWrite (yellowled,LOW);
digitalWrite (redled, HIGH);
digitalWrite (blueled, LOW);
}
if (LEDcolorpicked == "blue"){
digitalWrite (yellowled,LOW);
digitalWrite (redled, LOW);
digitalWrite (blueled, HIGH);
}

}

What is the line ending setting on the serial monitor?

Please remember to use code tags when posting code

Works for me. Must be the line ending setting.

arghhh I thought that when I change it once it is pernament you have helped in my previous project with the exact same solution Thank You Very Much! :slight_smile:

By the way how do i use code tags?

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

It does not change unless you change it so in that sense it is permanent

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