# LEDs will not Blink

**URL:** <https://forum.arduino.cc/t/leds-will-not-blink/1188686>\
**Category:** LEDs and Multiplexing\
**Created:** [November 13, 2023, 2:38pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686 "2023-11-13T14:38:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 2:38pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/1 "2023-11-13T14:38:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![qubits-us](https://avatars.discourse-cdn.com/v4/letter/q/5daacb/32.png) [@qubits-us](https://forum.arduino.cc/u/qubits-us)\
**Post date:** [November 13, 2023, 2:48pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/2 "2023-11-13T14:48:50Z")

</div>

> [@washamb](#):
>
> myColor = Serial.readString();

try

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

```

have fun.. ~q

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [November 13, 2023, 3:47pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/3 "2023-11-13T15:47:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [November 13, 2023, 3:54pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/4 "2023-11-13T15:54:13Z")

</div>

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 😃

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](https://toptechboy.com/arduino-tutorial-19-reading-strings-from-the-serial-monitor/)

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:

```arduino
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:

> **[LEDs will not Blink - Wokwi ESP32, STM32, Arduino Simulator](https://wokwi.com/projects/381295738042823681)**
>
> Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [November 13, 2023, 4:33pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/5 "2023-11-13T16:33:08Z")

</div>

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:**

```arduino
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);
}

```

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 4:45pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/6 "2023-11-13T16:45:16Z")

</div>

> [@Koepel](#):
>
> ```arduino
> 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);
> }
> }
> 
> ```

Thanks for your suggestion but it still won't work

---

<div class="post-metadata">

**Author:** ![qubits-us](https://avatars.discourse-cdn.com/v4/letter/q/5daacb/32.png) [@qubits-us](https://forum.arduino.cc/u/qubits-us)\
**Post date:** [November 13, 2023, 4:54pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/7 "2023-11-13T16:54:39Z")

</div>

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..](https://wokwi.com/projects/381299349992144897)

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

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 4:54pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/8 "2023-11-13T16:54:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![qubits-us](https://avatars.discourse-cdn.com/v4/letter/q/5daacb/32.png) [@qubits-us](https://forum.arduino.cc/u/qubits-us)\
**Post date:** [November 13, 2023, 5:00pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/9 "2023-11-13T17:00:19Z")

</div>

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

Do they light up for 2 seconds??

~q

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 5:08pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/10 "2023-11-13T17:08:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![qubits-us](https://avatars.discourse-cdn.com/v4/letter/q/5daacb/32.png) [@qubits-us](https://forum.arduino.cc/u/qubits-us)\
**Post date:** [November 13, 2023, 5:26pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/11 "2023-11-13T17:26:28Z")

</div>

what does this do??

```arduino
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

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 5:30pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/12 "2023-11-13T17:30:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 5:37pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/13 "2023-11-13T17:37:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [November 13, 2023, 5:39pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/14 "2023-11-13T17:39:59Z")

</div>

> [@washamb](#):
>
> This is my first post. I apologize

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
```

````

➡ 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](https://wokwi.com/projects/381295738042823681) ) 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 ?

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 5:40pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/15 "2023-11-13T17:40:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 5:57pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/16 "2023-11-13T17:57:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [November 13, 2023, 6:04pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/17 "2023-11-13T18:04:50Z")

</div>

Meanwhile I found the code on Github 😉

Here is tutorial 19 by Paul McWhorter in Wokwi simulation:

> **[Paul McWhorter Arduino Tutorial 19: Reading Strings from the Serial Monitor -...](https://wokwi.com/projects/381302928529615873)**
>
> Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!

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.

---

<div class="post-metadata">

**Author:** ![washamb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/washamb/32/1013044_2.png) [@washamb](https://forum.arduino.cc/u/washamb)\
**Post date:** [November 13, 2023, 6:52pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/18 "2023-11-13T18:52:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 13, 2023, 6:55pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/19 "2023-11-13T18:55:03Z")

</div>

The sketch compiles for me

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

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

char myColor[5];

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

```

---

<div class="post-metadata">

**Author:** ![2112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/2112/32/1129664_2.png) [@2112](https://forum.arduino.cc/u/2112)\
**Post date:** [November 13, 2023, 7:10pm UTC](https://forum.arduino.cc/t/leds-will-not-blink/1188686/20 "2023-11-13T19:10:52Z")

</div>

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?

[Next page](https://forum.arduino.cc/t/leds-will-not-blink/1188686.md?page=2)
