5085

You wanted to create a simple light-up Christmas tree but you don't have enough PWM pins on your Arduino? It might be time to switch. With the help of this article and a GlowDuino Uno board, you will be able to create a twinkling perf board Christmas tree of your own with 9 PWM controlled LEDs. Something you cannot do with an original Uno board.

To begin, you only need a few things:
-A GlowDuino Uno board to control the LEDs:
https://www.tindie.com/products/glowduino/glowduino-uno-a-better-arduino/
Or at:
https://www.glowduino.com/shop/p/uno
-3mm LEDs:
https://amz.run/7MRK
-Resistors for the LEDs:
https://amz.run/7MRL
-Perf board to mount the components:
https://amz.run/7MRN


1) Cut the Perf Board to Size
The first thing that will shape the outcome of the project is the size and shape of the tree. If you bought bigger LEDs or you put more than one per each output pin you might want to make a bigger tree. For our purposes, the 3mm LEDs and a single LED per pin were enough so a perf board size of 5cm by 11cm was chosen. Pre-made perf boards can usually be cut with a hand saw or a stronger pair of pinch cutters. Just mark the shape beforehand and cut the board out with the tool of your choice.

2) Place the Components

Once your board is cut to shape, you need to place the components in place. With each LED you place you will need a resistor in series to limit the current. To find the resistor you need, you can use this online calculator to find the correct value: Link 
For this, you will need to know the voltage and current of your LEDs and the voltage you will use with your GlowDuino board. In our case, we are using a 3.3V output with an LED voltage of 2V. The green and yellow LEDs draw 6mA and the reds 15. Using these values we got 180 Ohm resistors for the green and yellow LEDs and 75 Ohm resistors for the red ones. On the top of the tree where we connected two yellow LEDs in parallel, the resistors for each LED need to be connected in parallel as well. This way both LEDs will have sufficient current to function.
Place your chosen components in a way that is aesthetic and easy to connect. We recommend placing the LEDs in an orientation where the negative side of them faces outward. This way you can connect them all together later with a single wire. Similarly, you might want to place the resistors close to the positive side of the LEDs so you do not need any extra wire to make the series connection. If you are making this exact same tree, you can follow the layout as shown in the picture.


3) Soldering the Components Together

Once the components are in place, you can go ahead and solder them in place. after they are secured and in position, you can make the necessary connections between the components.

You will need to connect each of the negative pins of the LEDs together, here you can see that a single wire on the outside perimeter of the board works the best.

After connecting all the negative sides, you can make the connections between the resistors and LEDs. Each of the positive sides of the LEDs needs to connect to a resistor. This way the current is limited and the LEDs do not get damaged. In the next step, we will use the other side of the resistors to attach wire to.


4) Wiring the Tree

After soldering the components together the next step is going to require some wire. If you want to use your GlowDuino board as a stand for your tree, you might wanna use solid core wire for this step, if not, then simple flexible hookup wire is good enough.
You need to cut 9 wire pieces with enough slack that it can reach all of the necessary pins on the microcontroller. Once ready, solder a wire to the free end of each resistor and route the excess to the middle. To complete the circuit you will also need to solder a single wire to the common negative wire that connects all the LEDs. If you want to secure your wires to the board, you can also use additional pieces to soldier over the bundle of wires. This way the wiring stays nice and tidy.


5) Program the GlowDuino Board

Before connecting anything, you will need to upload the program to your GlowDuino board. Download the included sketch and using the Arduino IDE program, upload it to your GlowDuino board. Once uploaded, you will be able to see the indicators of the PWM pins on the board start to light up in a random manner. This signals a successful upload.


6) Connecting the Tree

The output pins that we are going to use are marked with a "~" symbol on the board. Each of the output pins marked with this symbol is a PWM-enabled pin. Alternatively, you can also flip the board over and check the pinout diagram on the back of the board. All in all, we are using 9 PWM pins in this project which is why it is necessary to have a GlowDuino board. It has 3 more PWM outputs than a regular uno board, therefore you can control even more LEDs

Once you located the pins, you can bend and trim the wires to fit in place. After trimming the wires you need to strip the insulation off the end of each and plug each of the wires connected to a resistor into a pin marked as a PWM pin. At the end, you need to connect the common negative wire to the GND pin on the GlowDuino board so the circuit can be completed.


7) Your Christmas Tree Is Done

If you've done everything correctly, you just need to plug in the USB to the microcontroller and enjoy the light show. Decorate your desk and windows with LED trees and have a merry Christmas with GlowDuino!


8) But How the Program Works?

The working principles of the program are very simple. There are three things happening in the main loop:-Choosing a random pin to alter-Changing the PWM on a pin over time-Writing the values to the output pins

Choosing a random pin is achieved with the built-in random() function of the GlowDuino. With this, the program generates a random number between 0 and 12 which determines the pin to be altered.

After choosing a pin, there is another random number generated that will decide in which way to alter the pin. If it is above a threshold it will set the target intensity to maximum and if it is lower then it will set the target intensity to minimum. The fading effect will be achieved within the next part based on the values set here.

After altering the target values the program enters a loop for a set amount of time where it increases or decreases the PWM values of each pin based on the target values. This PWM value is written to each pin with a simple analogWrite() function. The delay between each loop will determine the fade time of each LED so you can achieve a faster or slower changing light show.

After the set amount of time, the program exits the loop and starts over from the beginning.

In addition as a bonus, to be able to set the density of the lit-up LEDs, there is a variable that holds the threshold for the random generator. If this number is lower there will be fewer occasions when the generated random number is lower than this, therefore the number of lit LEDs is decreased.