Arduino Project
LED control 1.0
Course Introduction
In this lesson, you will use Arduino together with two buttons and a row of LEDs to create a directional light-flow effect.
Pressing the green button makes the LEDs light up in a forward flowing pattern, while pressing the red button triggers a backward flow.
Each button controls the direction of the LED animation, allowing you to switch between the two lighting modes at any time.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE
Wiring

Common Connections:
LED
Connect the LEDs cathode to the negative power bus on the breadboard, and the LEDs anode to 1kΩ resistor then to 5 to 10 on the Arduino.
Button
Connect to breadboard’s negative power bus.
Connect to 3 , 12 on the Arduino.
Writing the Code
Note
You can copy this code into Arduino IDE.
Don’t forget to select the board(Arduino UNO R4 Minima) and the correct port before clicking the Upload button.
// Pins for buttons
const int buttonGreen = 3; // Green button = forward
const int buttonRed = 12; // Red button = backward
// LED pins from 5 to 10
const int ledPins[] = {5, 6, 7, 8, 9, 10};
const int ledCount = 6;
int delayTime = 80; // Speed of flowing
void setup() {
// LEDs as output
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
// Buttons use internal pull-up
pinMode(buttonGreen, INPUT_PULLUP);
pinMode(buttonRed, INPUT_PULLUP);
}
void loop() {
// Read buttons (LOW = pressed)
bool greenPressed = (digitalRead(buttonGreen) == LOW);
bool redPressed = (digitalRead(buttonRed) == LOW);
// ----- Forward Flow: 5 → 10 -----
if (greenPressed) {
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], HIGH); // Light current LED
delay(delayTime);
if (i > 0) {
digitalWrite(ledPins[i - 1], LOW); // Turn off previous LED
}
}
digitalWrite(ledPins[ledCount - 1], LOW); // Turn off last LED
}
// ----- Backward Flow: 10 → 5 -----
if (redPressed) {
for (int i = ledCount - 1; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH); // Light current LED
delay(delayTime);
if (i < ledCount - 1) {
digitalWrite(ledPins[i + 1], LOW); // Turn off previous LED
}
}
digitalWrite(ledPins[0], LOW); // Turn off last LED
}
}
