Introduction: Arduino Workshop-LED Chase Effect

Today I will show you how to easily LED Chase Effect this project in just a few steps using Arduino. If you want to complete it, start talking to me. Now we are going to workshop LED Chase Effect We are now going to use a string of LEDs (10 in total) to make an LED chase effect Here are the components we need to complete this workshop

Required Component for Arduino LED Chase Effect
    1. Arduino

2. 5mm LED

3. Resistors

This book will help you to gain more knowledge about Arduino Beginning Arduino

Circuit diagram

First, make sure your Arduino is powered off by unplugging it from the USB cable. Now take your breadboard, LEDs, resistors, and wires, and connect everything up as in Figure :LED Chase Effect . Check your circuit thoroughly before connecting the power back up to the Arduino.

Code

byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Create
array for LED pins
int ledDelay = 65; // delay
between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() {
for (int x=0; x<10; x++) { // set all
pins to output
pinMode(ledPin[x], OUTPUT);
}
changeTime = millis();
}
void loop() {
if ((millis() - changeTime) > ledDelay) { // if it has
been ledDelay ms since last change
changeLED();
changeTime = millis();
}
}
void changeLED() {
for (int x=0; x<10; x++) { // turn off
all LED's
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLED], HIGH); // turn on
the current LED
currentLED += direction; // increment
by the direction value
// change direction if we reach the end
if (currentLED == 9) {direction = -1;}
if (currentLED == 0) {direction = 1;}
}
Now press the Verify button at the top of the IDE to make sure there are no errors in your code. If this is successful, you can now click the Upload button to upload the code to your Arduino. If you have done everything correctly, you should now see the LEDs appear to move along the line, then bounce back to the start. We have not introduced any different hardware in this project, so there is no need to take a look at that. However, we have introduced a new concept in the code of this project in the form of arrays. Let us take a look at the code for Project 5 and see how it works.

Previous Tutorial

  1. Arduino Workshop-LED Flashers
  2. Arduino Workshop-Traffic Lights
  3. Arduino Workshop- Interactive Traffic Lights