PCBX
Published

Creating an Arduino LED Running Light: A Step-by-Step Guide

Learn how to create a dynamic Arduino LED running light with our step-by-step guide.

BeginnerFull instructions provided284

Things used in this project

Story

Read more

Schematics

098432b0ef1d4fa4b72dbe747284ee6c_kGGgbKu8Zw.png

Code

ARDUINO_led running light

Arduino
// Define the pins connected to the LEDs
const int ledPins[] = {3, 4, 5, 6, 7, 8, 9};
const int ledCount = sizeof(ledPins) / sizeof(ledPins[0]);

void setup() {
  // Initialize each pin as an output
  for (int i = 0; i < ledCount; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  // Loop through and light up each LED individually
  for (int i = 0; i < ledCount; i++) {
    digitalWrite(ledPins[i], HIGH); // Turn on the current LED
    delay(100);                     // Wait for 100 milliseconds
    digitalWrite(ledPins[i], LOW);  // Turn off the current LED
  }
  delay(100); // Wait for 100 milliseconds

  // Turn on all LEDs simultaneously
  for (int i = 0; i < ledCount; i++) {
    digitalWrite(ledPins[i], HIGH); // Turn on all LEDs
  }
  delay(1000); // Wait for 1 second

  // Turn off LEDs one by one
  for (int i = 0; i < ledCount; i++) {
    digitalWrite(ledPins[i], LOW); // Turn off the current LED
    delay(100);                    // Wait for 100 milliseconds
  }
  delay(1000); // Wait for 1 second

  // Each LED lights up individually 3 times, with a 500ms interval
  for (int i = 0; i < ledCount; i++) {
    for (int j = 0; j < 3; j++) { // Each LED lights up 3 times
      digitalWrite(ledPins[i], HIGH); // Turn on the current LED
      delay(300);                    // Wait for 300 milliseconds
      digitalWrite(ledPins[i], LOW);  // Turn off the current LED
      delay(300);                    // Wait for 300 milliseconds
    }
  }
  // Ensure there is a delay at the end of the loop to provide enough time before the next loop starts
  delay(1000); // Wait for 1 second
}

Credits

PCBX
33 projects • 9 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.
Contact

Comments

Please log in or sign up to comment.