Flowing lights on pins 2 to 9, on an Arduino Uno
Eight LEDs on pins 2 to 9, each through 220 ohm: a for loop lights them one after another, up the row and back down. The whole build, an Arduino Uno and 16 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Flowing lights: eight LEDs on pins 2 to 9, lit one after another.
//
// pins 2 to 9 -> one 220 ohm resistor and one LED each -> GND
//
// Because the LEDs sit on pins with consecutive numbers, one for loop can walk
// along them: the loop variable is the pin. Up the row, then back down.
const int FIRST = 2;
const int LAST = 9;
const int STEP_MS = 100;
void setup() {
for (int pin = FIRST; pin <= LAST; pin++) pinMode(pin, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: flowing lights on pins 2 to 9");
}
void loop() {
for (int pin = FIRST; pin <= LAST; pin++) {
digitalWrite(pin, HIGH);
delay(STEP_MS);
digitalWrite(pin, LOW);
}
for (int pin = LAST; pin >= FIRST; pin--) {
digitalWrite(pin, HIGH);
delay(STEP_MS);
digitalWrite(pin, LOW);
}
}
Parts list
18 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Full-size breadboard
- 8 × Resistor, 220 Ω
- 8 × LED, red
How it is wired
17 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; LED, red (1) pin C; LED, red (2) pin C; LED, red (3) pin C; LED, red (4) pin C; LED, red (5) pin C; LED, red (6) pin C; LED, red (7) pin C; LED, red (8) pin C
- Arduino Uno R3 pin 9; Resistor, 220 Ω (1) pin 1
- Arduino Uno R3 pin 8; Resistor, 220 Ω (2) pin 1
- Arduino Uno R3 pin 7; Resistor, 220 Ω (3) pin 1
- Arduino Uno R3 pin 6; Resistor, 220 Ω (4) pin 1
- Arduino Uno R3 pin 5; Resistor, 220 Ω (5) pin 1
- Arduino Uno R3 pin 4; Resistor, 220 Ω (6) pin 1
- Arduino Uno R3 pin 3; Resistor, 220 Ω (7) pin 1
- Arduino Uno R3 pin 2; Resistor, 220 Ω (8) pin 1
- Resistor, 220 Ω (1) pin 2; LED, red (1) pin A
- Resistor, 220 Ω (2) pin 2; LED, red (2) pin A
- Resistor, 220 Ω (3) pin 2; LED, red (3) pin A
- Resistor, 220 Ω (4) pin 2; LED, red (4) pin A
- Resistor, 220 Ω (5) pin 2; LED, red (5) pin A
- Resistor, 220 Ω (6) pin 2; LED, red (6) pin A
- Resistor, 220 Ω (7) pin 2; LED, red (7) pin A
- Resistor, 220 Ω (8) pin 2; LED, red (8) pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.