PROJECT 2: CHASING LED #
Previously, we learned how to control a single LED using Sketch on the control board, and in addition, we gained some basic knowledge of programming.
The aim of the experiment is to make a “chasing LED” (or “LED chaser”) which is a lighting effect where a series of LEDs light up in sequence, one after the other, creating the appearance of movement or “chasing.” Decorative lighting, signs, and electronic projects often use this effect to produce a dynamic visual display.
A microcontroller or circuit arranges the LEDs in a row or pattern and turns them ON and OFF in a specific order.
2. Materials we will use
3. Circuit diagram
Let us use pins 2-9 of the control board to drive LEDs.
Figure: Circuit diagram for LEDs connection to the arduino pins
Figure: Components used to make connection on the board
4. Arduino Code
5. Code knowledge
Firstly, let us define a read-only variable to record the number of LEDs, which will also serve as the number of times the loop runs.
Specifically, the “count” keyword is used to define read-only variables, which are called in the same way as other variables. However, you can assign a value to a read-only variable only once.
Next, we define an array to store the pin numbers connected to the LED bar graph. This way, it becomes more convenient to manipulate the array when modifying pin numbers.
Use loop statements to set the pins to output mode in function setup().
Finally, here we will see flowing water LEDs lights.
6. Results
Here’s what you can expect as the visible output on the LEDs:
Initial State: All LEDs are off when the Arduino starts.
Chasing Right Effect: Each LED turns ON in sequence, starting from the one connected to pin 2, moving to the one connected to pin 9. Each LED stays ON for 300 milliseconds before the next LED lights up. Each time an LED turns ON, it keeps the previous ones ON until all LEDs are lit.
Turning Off LEDs: The circuit turns off the LEDs in sequence, starting from the one connected to pin 2 and moving to pin 9. It then turns off all LEDs almost simultaneously.
Delay: After turning off all the LEDs, the process waits 1 second before repeating.
Visual Effect: You will see a “chasing light” effect from left to right, followed by all LEDs turning off one by one. This pattern will repeat indefinitely.