Arduino Programming: Creating an LED Firework Effect

LEDs have many purposes, from traffic lights on the streets to the bulbs in your home. They also come in handy when working with embedded, IoT, or any other extra-curricular project you might be doing. It is not uncommon for a maker project or IoT project to need to control a number of different LEDs. In a recent project I was involved with, an array of LEDs was used to create a firework effect, as shown in Figure 1. An Arduino board was used to control the display.

The LED firework display
Figure 1: The LED firework display

In this article, I’ll describe how our LED display was built and also include the code that was used on an Arduino to simulate the fireworks. By using what is presented, you should be able to create your own project for controlling LEDs, whether it is for simulating fireworks, a holiday scene, or simply feedback on your own Maker or IoT project.

Building the Firework LED Project

There weren’t many materials used to complete this project. The project primarily contained:

  • A lot of LEDs—over 400
  • A 4×8 foot piece of composite board
  • Several 2″ x 4″ wood boards to line the composite board and use as a stand
  • Wire for the LEDs
  • Solder
  • An Arduino Mega board

The composite board is where you start by drawing in the firework pattern. We drew lines for the initial pattern, and then replaced them with dots approximately two inches apart from each other to indicate where the LEDs will be placed. A 5 mm drill bit should be used to create a hole where each of the LEDs will be placed.

If your project is using a wood frame as well, before placing the LEDs, it is important to sand down the front to get rid of the excess composite board from the drilling. Before placing the LEDs, they need to be sectioned off by areas. Each segment will be connected to the Arduino. In the case of the firework display, there were 53 segments identified and created.

Once the LEDs are placed, it is always beneficial to hot glue them in. This step can be completed before or after you solder.

Choosing an Arduino Board

An Arduino board is a miniature programmable circuit board that allows you to control a multitude of projects. In this case, an Arduino Mega board was used to control the LED firework effect. This project code was written in a simple C format. There are many types of Arduino boards. The Arduino Uno has 14 digital ports, the Due has 54 digital ports, the Mega has 54 digital ports, and the Leonardo has 20 digital ports. With the LED firework effect, the Arduino Mega was used for the maximum amount of digital and analogue ports.

As mentioned earlier, the LEDs were divided into sections in the firework display. The lights had to be sectioned because on the Arduino Mega board supports only 54 ports, and there were well over 54 LEDs in the display.

For the fireworks that you can see in Figure 1, there are straight beams and three “bursts.” The beams were sectioned in lines of 4 LEDs while the bursts were sectioned in rings. A total of only 53 sections were used because, on the Arduino board, the digital port 1 is technically not considered a port. As such, you always begin with the digital port number 2.

Wiring the LEDs

Now that the sections have been identified and placed on the board, the soldering can began. Every single light is connected to a negative wire that can go to the port on the Arduino and to the battery to supply power through the display. All of the LEDs need to be linked with the same negative wire so they will receive power. An on/off switch can also be added onto the negative wire so that when the switch is off, it cuts all power to each LED.

Each of the 53 sections on the display received their own positive wire, which was the wire that linked that segment to the Arduino. The positive wire is more complex. The positive wire has to hit each LED in the section and go to the corresponding port on the Arduino.

For the firework project, each LED was connected using the wire and solder. The soldering of the lights can be complex or difficult if you are someone who is just beginning! In Figure 2, you can see the back of the firework display showing the wiring.

The wiring of the firework display
Figure 2: The wiring of the firework display

Lessons Learned when Using LEDs

There are many problems you can run into when working through this project or other projects that use LEDs. One issue is that red colored LEDs are overpowering without resistors. They will suck the power out of the other colored lights, making only themselves bright (how selfish).

A second issue is that it is very easy to miss a light, receive an ineffective light, or solder in the wrong place. You should make sure to constantly test your previous work. With so many LEDs so close together, the work can become very tedious. It is important to not get frustrated when you make a mistake; stay steady and slow! In Figure 3, you can see the complex result of connecting the wires in the firework display to the Arduino board.

The Arduino covered by all of the wires
Figure 3: The Arduino covered by all of the wires

Coding the LED Display

Everything physical has been completed, so the coding begins.

Once everything is soldered and connected with the Arduino, you begin writing your code. This code for the Firework Effect is simple on/off controls using digitalWrite and delays.

To begin using the Arduino software, you must tell the Arduino board which ports you will be using. In the “void setup” section of a default Arduino project, you would type in the following for each port that is being utilized:

pinMode (port#, OUTPUT);"

In the “void loop” section, you will turn each light on and off for a custom amount of time. The following sequence turns the LED pattern in port 2 on, keeps it on for 50 milliseconds, and then turns it off:

digitalWrite (2, HIGH);
delay (50);
digitalWrite (2, LOW);

There are many rules or formats that need to be followed when writing code because one tiny mistake can cause a malfunction. All code needs to be written in a digitalWrite format when you’re using the digital ports. When using the analogue ports, it is written in an analogueWrite format. After each line, there needs to be a semicolon to tell the Arduino that is the end of that line of code. Also, it is important to be cautious of the amount of time you are inserting into your delay because everything is in milliseconds.

Each section of code, void setup, and void loop sections, needs to be closed with brackets. The following is a section of the code from the LED firework effect. Because of the overall length of the code, this listing is only controlling the first five ports:

void setup() {
   // Put your setup code here, to run once:
   pinMode (2, OUTPUT);
   pinMode (3, OUTPUT);
   pinMode (4, OUTPUT);
   pinMode (5, OUTPUT);
void loop() {
   // Put your main code here, to run repeatedly:
   digitalWrite (2, HIGH);
   delay (50);
   digitalWrite (2, LOW);
   digitalWrite (3, HIGH);
   delay (50);
   digitalWrite (3, LOW);
   digitalWrite (4, HIGH);
   delay (50);
   digitalWrite (4, LOW);
   digitalWrite (5, HIGH);
   delay (50);
   digitalWrite (5, LOW);

As you can see, overall the coding to this project and the use of the Arduino was relatively simple.


Overall, the uses for LEDs are endless. Along with everyday materials like headlights and home bulbs, LEDs can be used for fun and decoration. In this case, LEDs were used for an extracurricular project that was entertaining in the making as well.

Additionally, there are many more projects that can you do with an Arduino that require different materials and a little extra knowledge on how the code works, but all of this information can obtained. It is never too late for you to expand your knowledge, and it is never too early. I began this journey with electronics in the sixth grade, and I am now going to be a junior in high school. The experience has assisted my career choices immensely.

More by Author

Must Read