LED Control using for loop in Arduino

LED Control using for loop in Arduino

Simultaneous LED Control - One LED On for 5 Seconds, Another LED Blinking 5 Times in Arduino


If you want both LEDs to operate simultaneously, with the first LED staying on for 5 seconds and the second LED blinking on and off 5 times during that period, you can use this code:


void setup() {
  pinMode(10, OUTPUT); // First LED
  pinMode(11, OUTPUT); // Second LED
}

void loop() {
  // Turn on the first LED for 5 seconds
  digitalWrite(10, HIGH);
  
  // Blink the second LED 5 times
  for (int i = 0; i < 5; i++) {
    digitalWrite(11, HIGH);
    delay(500);
    digitalWrite(11, LOW);
    delay(500);
  }
  
  digitalWrite(10, LOW); // Turn off the first LED
  
  delay(1000); // Optional gap between cycles
}



In this code, the first LED (connected to pin 10) turns on and stays on for 5 seconds, and during that time, the second LED (connected to pin 11) blinks on and off 5 times. After that, the first LED turns off, and the code waits for a second before the cycle repeats.

Ensure that you have connected your LEDs to the correct pins on the Arduino board as specified in the code.