top of page

Scrolling LEDs with Arduino: Illuminate Your World

This article will explore the fascinating world of LEDs and show you how to create a scrolling LED display using an Arduino microcontroller.


If you're looking for an efficient way to control many LEDs, look at this article. It uses additional components but only requires the use of three digital pins.



Understanding LEDs

An LED, short for Light-Emitting Diode, is a semiconductor device that emits light when an electric current passes through it. LEDs have become popular due to their energy efficiency, durability, and versatility in various applications. Looking at a basic, one-colored LED, you'll see two pins. These pins are known as the anode and cathode. The longer "lead" or leg is the anode, and the shorter lead is the cathode. For an LED, the anode is the positive leg, while the cathode is the negative leg.


You'll typically see a resistor wired in series when using LEDs in a project. Why is a resistor needed? When an LED is connected directly to a power source, such as the Arduino board, it can draw excessive current, which can damage the LED or cause it to malfunction. The resistor acts as a current limiter by reducing the current flow through the LED, ensuring it operates within its specified voltage and current range, protecting it from damage.



Getting Started with Scrolling LEDs using an Arduino

Ensure you installed the Arduino Integrated Development Environment (IDE) on your computer, which provides a user-friendly platform for writing and uploading code to the Arduino board. You can download the program here if you don't have it installed, and the installation instructions can be found here.


Required Components:

  • Arduino

  • LEDs x 8

  • 220Ω x 8

  • Jumper wires

  • Breadboard



Wiring LEDs to Arduino

Now that everything is set up and you've gathered the required components, we'll connect the LEDs and resistors to the Arduino using a breadboard and jumper wires.


Step 1

To begin, place the eight LEDs into the breadboard so they're in a straight line. Ensure that the LEDs are also in the same orientation.

Arduino Uno connected to eight LEDs

Step 2

Now, connect the eight 220Ω resistors in series with the LEDs (one resistor for each LED). It does not matter which end you connect the resistor to.

Arduino Uno connected to eight LEDs

Step 3

Then connect the components on the breadboard to the Arduino. I'll use the digital pins 2-9 on the Arduino Uno, but feel free to use different digital pins if needed. Take eight jumper wires and connect them to the Arduino's digital pins. Once connected to the Arduino, connect the jumper wire from the Arduino to the anode (positive side/longer lead) of the LED.

Arduino Uno connected to eight LEDs

Step 4

The last thing to do is connect one last jumper wire from a ground (GND) pin on the Arduino to the cathode of each LED.

Arduino Uno connected to eight LEDs

Writing the Code

With the Arduino IDE set up and the LEDs adequately wired to the Arduino board, we are ready to start writing code for our scrolling LED display. This section will explore the basics of Arduino programming, empowering you to control the LEDs and create stunning scrolling effects.


Here is a table of all the primary functions that will be used to program the Arduino.

Function

What it Does

pinMode

Sets the mode of a specified pin on the Arduino board, determining whether it is an input or output pin.

digitalWrite

Sets the state of a specified pin on the Arduino board to either HIGH (+5V) or LOW (0V)

delay

Pauses the program's execution for a specified time in milliseconds



Setup LED Pins as Outputs

To control the state of the digital pins we wired our LEDs to, we must first set up the pins as either inputs or outputs. Since we would like to set the state of the pin as either HIGH or LOW (+5v or 0v), we'll make them all output pins. We'll use the "pinMode" function to tell the Arduino pins 2-9 are output pins.

I have a for loop written within the setup function in the above code snippet. This loop starts from the integer two and counts up until nine. On each iteration, I pass the variable "ledPin" into the "pinMode" function allowing us to set up each pin as an output with only a few lines of code.



Programming LEDs to Scroll

Now that pins 2-9 are defined as outputs within the program, we can turn anyone on or off (HIGH or LOW). To create a scrolling effect, I'll use a for loop to turn one LED on at a time until we reach the end.

Again, we loop through all eight pins we set up earlier and pass the pin number into the "digitalWrite" function. We first turn the LED on, wait for 50 milliseconds, and then turn the LED off.


You might be curious why there is no delay after turning the LED off. If you've ever blinked an LED, you know we always add a delay after turning the LED off too. We do not use the extra delay because we jump to the next LED after the previous LED goes out. I'd recommend adding in the extra delay to see the difference. One results in a smooth transition from LED to LED, and the other looks choppy.





If you want to scroll the LEDs in the opposite direction from above, you only need to use a for loop that counts down from nine to two.





Here's a bonus animation for you. The following code will scroll back and forth.





Below, I placed the three different animations into functions so you can easily switch between them. Here's the completed program.




FAQs: Scrolling LEDs with Arduino

What if I want to add more LEDs to my scrolling LED display?

This project used up a ton of digital pins on the Arduino, and you can see how you'd quickly run out of digital pins to control the LEDs. Suppose you have no interest in adding additional components to the project (you want to work with LEDs and resistors only). In that case, you'll be limited to the number of digital pins available on your Arduino. If you don't mind adding additional components, look into working with shift registers. This integrated circuit (IC) lets you control hundreds of LEDs with only three pins!

Can I use different types of LEDs for my scrolling LED project?

Can I make the scrolling LED display interactive with external sensors?


181 views0 comments
bottom of page