Lights and displaysA Colour-Changing Lamp with an RGB LED
An RGB LED holds three small LEDs: red, green and blue. Mix their brightness and you get any colour, while the lamp slowly changes from one colour to the next.
Lights and displaysSix LEDs light up one after another, so a dot of light runs left and right. A neat way to learn the for loop.
Adapted from “For Loop Iteration (aka The Knight Rider)” by Arduino. Licence: CC BY-SA 4.0. This translation is shared under the same licence. The parts list and the tips are RoboHub's.
Choose a variation and the parts list updates.
Place six LEDs in a row on the breadboard. Connect each one's long leg through a 330 Ω resistor to pins 2 to 7, and the short legs to the ground rail.
The first for loop goes through pins 2 to 7, the second from 7 back to 2.
int timer = 100; // the higher the number, the slower the light runs
void setup() {
for (int pin = 2; pin < 8; pin++) {
pinMode(pin, OUTPUT);
}
}
void loop() {
for (int pin = 2; pin < 8; pin++) { // from the lowest pin to the highest
digitalWrite(pin, HIGH);
delay(timer);
digitalWrite(pin, LOW);
}
for (int pin = 7; pin >= 2; pin--) { // and back again
digitalWrite(pin, HIGH);
delay(timer);
digitalWrite(pin, LOW);
}
}timer is in milliseconds: 30 is very fast, 300 is slow.

Illustration, made with AI
Illustration: six red LEDs in a row in the dark, the middle two lit.
Step 3: Change the speed
Lights and displaysAn RGB LED holds three small LEDs: red, green and blue. Mix their brightness and you get any colour, while the lamp slowly changes from one colour to the next.
Lights and displaysEveryone starts here: the LED built into the board turns on and off once a second. You'll learn how to install the Arduino IDE, write code and upload it to the board.
Lights and displaysBuild a small model of a real traffic light: green, flashing green, yellow, red and finally red with yellow, just like on the street.