Problem with a blinking LED

Hello

I am an Arduno beginner.

I am trying to get 2 LEDs working with different blinking times through for loop

The program is working fine with no problem.

However, when I add the Serial.begin(baud rate) One of the LEDs (yellow) is constantly turned on and not blinking.

When this Serial.begin command is disabled, the LED is blinking as it should

Any reason for that?
Is related to the OS : Windows 10. I also work with the latest Arduino version

I appreciate any help

Thanks

Here is the code:

int redLED = 3;
int yellowLED = 1;

int waitTimeonRed= 100;
int waitTimeoffRed= 1000;

int waitTimeonYellow= 100;
int waitTimeoffYellow= 1000;

int numRedBlink= 3;

int numYellowBlink= 2;

void setup() {
Serial.begin(9600);
pinMode(redLED,OUTPUT);
pinMode(yellowLED,OUTPUT);
}

void loop () {
// put your main code here, to run repeatedly:
Serial.println(" The Red LED is Blinking");
for (int j = 1; j<=numRedBlink; j=j+1) {
Serial.print(" You are in Blink No.: ");
Serial.println(j);
digitalWrite(redLED,HIGH);
delay(waitTimeonRed);
digitalWrite(redLED,LOW);
delay(waitTimeoffRed);
}
Serial.println(" ");
Serial.println(" The yellow LED is Blinking");
for (int j = 1; j<=numYellowBlink; j=j+1) {
Serial.print(" You are in Blink No.: ");
Serial.println(j);
digitalWrite(yellowLED,HIGH);
delay(waitTimeonYellow);
digitalWrite(yellowLED,LOW);
delay(waitTimeoffYellow);
}
Serial.println(" ");
}

That is because Serial use pin 0 and 1. The pin 1 in your code is used for both Serial and LED.
To solve it, change LED pin to other Arduino pin.
You can also use the library to blink multiple LED without delay

On many Arduinos, pins 0 and 1 are used for serial i/o. Sharing can happen but takes special effort. It would be best if you chose a different pin for your yellow LED. You must change BOTH the code and the wiring.

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