Arduino C++ Turn on LEDs in sequence

  • Create pins array
  • set array’s length
  • add switch functionality inside the for loop
int ledPins[] = {2,3,4};
int arrayLength;

void setup() 
{
  arrayLength = sizeof(ledPins)/sizeof(ledPins[0]);
}

void loop() 
{
  for(int i = 0; i < arrayLength; i++)
  {
    digitalWrite(ledPins[i], 1);
    delay(500);
    digitalWrite(ledPins[i], 0);
    delay(200);
  }
}

How to connect multiple LEDs on breadboard to the Arduino pins?

Scroll to Top