LEDs will not Blink

I am new to both coding and microcontrollers. I have just started learning Arduino code by viewing Paul McWhorter’s lessons on YouTube. I have an Arduino Uno R3 board connected to an HP laptop running Windows 10. I have copied Lesson 19. It compiles and uploads with no error messages but will not activate the LEDs when I type the desired color and press enter. The Rx and Tx LEDs on the board activate to indicate that the program is running. I know that the breadboard is set up properly as the LEDs activate when I run a program that directly blinks the LEDs rather than asking for an input from the keyboard.
Paul McWhorter’s YouTube Lesson 19:
int redPin = 12;
int greenPin = 11;
int bluePin = 10;
String myColor;
String msg("What color LED? ");

void setup() {
// put your setup code here, to run once:

Serial.begin(9600);

pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

Serial.println(msg);

while (Serial.available() == 0) {
}

myColor = Serial.readString();

if (myColor == "red" || myColor == "Red") {
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);

digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);

digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);

digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
}
When I run the program, nothing happens. What am I doing wrong?

try

myColor = Serial.readStringUntil('\n');

have fun.. ~q

when posting code read the forum guidelines and use code tags, it makes it much easier to follow.

Welcome to the forum.

I'm sorry that you got into this. We don't use functions such as "Serial.readString()" and we often don't use the "String" with a Arduino Uno. It is completely normal that you encounter these problems, you are still on the right track :smiley:

Do you have programming experience ? (any language)
Is there something that has your special interest ?

This is lesson 19, but I can't find the code: Arduino Tutorial 19: Reading Strings from the Serial Monitor | Technology Tutorials

Serial communication is not straight forward. When you type something in the Serial Monitor, then the baudrate has to be right and sometimes extra characters are added, such as CarriageReturn and LineFeed.
You can trim away those extra characters, and I suggest to use more Serial.println() to show what is going on, and add a delay so you can see the leds.

This might work better:

int redPin = 12;
int greenPin = 11;
int bluePin = 10;
String myColor;
String msg("What color LED? ");

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(msg);

  while (Serial.available() == 0) {
  }

  myColor = Serial.readStringUntil('\n');  // Changed

  myColor.trim();                          // Added

  Serial.print("You typed: ");             // Added
  Serial.println(myColor);                 // Added

  if (myColor == "red" || myColor == "Red") {

    Serial.println("Red activated");       // Added

    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);

    delay(5000);                           // Added

    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
    digitalWrite(bluePin, LOW);

    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);

    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }
}

Try it in Wokwi simulation:

Upload the following sketch (your one with some moderation) with Newline option. Enter RED in the InputBox of Serial Monitor and then click on the Send button; check that only Red LED is On. (It is no good to use String data type in UNO.)
Sketch:

int redPin = 12;
int greenPin = 11;
int bluePin = 10;

char myColor[5];

char msg[] = "What color LED? ";

void setup()
{
  Serial.begin(9600);

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  Serial.println(msg);
}

void loop()
{
  while (Serial.available() == 0)
  {
    ; //wait
  }
  byte m = Serial.readBytesUntil('\n', myColor, sizeof myColor - 1);
  myColor[m] = '\0'; //null charcater is appended at the end of received string 
  if (strcmp (myColor, "RED") == 0) //RED message has arrived from Serial Monitor
  {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }
  else
  {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }
  Serial.println(msg);
}

Thanks for your suggestion but it still won't work

well, they all kind of blink, but that's a wad (working as designed) not a bug..
it does seem read in the word red..
at least in the sim..
Uno Serial Leds..

no delays, so the blink is super fast, i see you've added a delay in there, try adding it in the sim..

fun,fun.. ~q

Thanks for your suggestion but it still won't work. It worked fine for McWhorter in lesson 19 on YouTube but as hard as I have tried I can't it to do anything. I have deleted and reentered the code numerous times without any change in the way it works. No problem for compile or upload.
Again, thanks for your reply.

Did you verify the LEDs??
Just added it into the sim..
Maybe leds are backwards..

Do they light up for 2 seconds??

~q

I verified that the LEDs were good by connecting to the 5v outlet. I then activated them by using a program that activates the LEDs within the program. They all worked as programed. They don't work when the input is from the keyboard.

what does this do??

int redPin = 12;
int greenPin = 11;
int bluePin = 10;
char myColor[20];
char buff[20];
char msg[]={"What color LED? "};
byte recvCount = 0;
bool haveColor= false;
unsigned long lastBlink;
int intervalBlink = 250;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  Serial.println("Ready");

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(2000);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);

  Serial.println(msg);

}

void loop() {
  // put your main code here, to run repeatedly:

if (Serial.available()){
  byte abyte = Serial.read();
  if (abyte != 10){
    buff[recvCount]=abyte;
    recvCount++;
    if (recvCount>=sizeof(buff)) recvCount = 0;//??no!!
  }else {
    memcpy(myColor,buff,sizeof(buff));
    haveColor = true;//set flag
    recvCount = 0;
    memset(buff,0,sizeof(myColor));//empty buff
    Serial.println(msg);
  }
}

  if (strcmp(myColor, "red")==0 || strcmp(myColor, "Red")==0) {
  if (millis()-lastBlink>=intervalBlink){
    lastBlink = millis();
    digitalWrite(redPin, !digitalRead(redPin));
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
  }  
  }

  if (strcmp(myColor, "green")==0 || strcmp(myColor, "Green")==0) {
  if (millis()-lastBlink>=intervalBlink){
    lastBlink = millis();
    digitalWrite(greenPin, !digitalRead(greenPin));
    digitalWrite(redPin, LOW);
    digitalWrite(bluePin, LOW);
  }  
  }

  if (strcmp(myColor, "blue")==0 || strcmp(myColor, "Blue")==0) {
  if (millis()-lastBlink>=intervalBlink){
    lastBlink = millis();
    digitalWrite(bluePin, !digitalRead(bluePin));
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
  }  
  }

  if (strcmp(myColor, "stop")==0 || strcmp(myColor, "Stop")==0) {
    digitalWrite(bluePin,LOW);
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
  }
 }

~q

This is my first post. I apologize that I didn't do everything right. I did read the copy of the Forum but do not understand how to choose the right category or to use code tags. I did Auto Format and Copy for Forum before posting. If you can enlighten me I would appreciate it.

Thanks for your suggestion. I made the changes and it turned on the red LED but not the green or blue. I still can't understand why it works for Paul McWhorter in his lesson 19 on YouTube.

That's okay. We are all Arduino-enthusiasts here.

Some think that Categories are very important, but I don't care.

We use the common "Reply" button at the bottom. That works better on this forum.

There is a button <CODE/>, you can use that to put your sketch between lines of three backslash single quotes:

```
your sketch
```

:arrow_right: If you say that it does not work, then you give us no information. It probably does something different that what you expect, so please tell what you did, what the result was and what you were expecting.

My example in Wokwi simulation ( LEDs will not Blink - Wokwi ESP32, STM32, Arduino Simulator ) turns the red led on for a few seconds when I type "red" followed by enter. If you understand the changes, then you can add the green and blue.

If you mention something, can you give a link to it ? Where can I see the code by Paul McWhorter ?

Thanks for your suggestion but it still won;t work.

I find lesson 19 by going to YouTube videos and entering McWhorter 19 in the Search Window.
Thanks for your other suggestions.

Meanwhile I found the code on Github :wink:

Here is tutorial 19 by Paul McWhorter in Wokwi simulation:

If something does not work with tutorial 19, then blame Paul McWhorter. He has to make a new video with new code.
We would never write such code and we would certainly never bother new users with it.

Thanks for your input. When I compile I get the
Compilation error: 'myColor' does not name a type. I don't understand how to correct this error. I have researched it but do not under stand the answers.

The sketch compiles for me

Do you have these lines at the top of the sketch ?

int redPin = 12;
int greenPin = 11;
int bluePin = 10;

char myColor[5];

char msg[] = "What color LED? ";

Paul says:
"GUYS MAKE SURE YOUR SERIAL MONITOR IS SET TO 'NO LINE ENDING'!!! Otherwise you will have problems with this code."

Did you to that?
Did you set your serial monitor baud to 9600?