All tutorials

1 · First steps

5-LED chaser

Intermediate15 min

Goal

Run a light across 5 LEDs using a for loop and an array.

Why it matters

Array + loop avoids copying the same code five times: your first algorithmic building block.

Steps

  1. 01Place 5 LEDs on pins 2 to 6.
  2. 02Declare int leds[5] = {2,3,4,5,6};
  3. 03In setup(), configure them with a for loop.
  4. 04In loop(), light them one after another, then start over.

This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.

Next tutorials