RGB LED Lighting Effects With Adafruit Trinket

Introduction: RGB LED Lighting Effects With Adafruit Trinket

About: I'm a software architect with an interest in Arduino, Raspberry Pi, electronics, robotics and generally making cool projects with my kids.
More About andygrove »

This instructable is to make programmable light effects using an RGB LED (this is an LED containing individual Red, Green and Blue elements) and the low cost Adafruit Trinket microcontroller. These lights can be used and re-used for multiple projects such as night lights, party lights and pumpkin lights for Halloween. The entire project only costs around $10 fully assembled.

Note that you can use a solderless breadboard instead of soldering this onto a PCB (and you should always do this first to make sure it works before committing to PCB). However, if you want to keep and reuse this project, I definitely recommend using a PCB. The great thing about the Adafruit breadboard PCB is that it is laid out exactly like a regular breadboard with lines of connected pads which makes soldering so much easier in my opinion.

Step 2: Solder the Female Headers Onto the PCB

Because we want to be able to remove the Trinket for programming (and maybe to use in other projects later on) we don't want to solder it directly onto the PCB so we used headers instead. We will solder male headers to the PCB and solder female headers to the trinket so that the trinket can easily be removed.

Insert the female headers on the right hand side of the board in rows D and G so they are spaced correctly to accept the male header pins that we will solder to the Trinket. To keep the board level on the table simply insert some female headers temporarily at the other end of the board but we won't be soldering those ones.

With the board level, go ahead and solder the 5 pins of each header to the PCB. I usually solder one on each side first to provide some support before soldering the rest of them.

Step 3: Soldering the Male Headers to the Trinket

The next step is to insert the male headers that came with the Trinket into the the female headers that are now attached to the PCB. The male headers have longer pins on one side and these longer pins should be inserted into the female headers.

Now the Trinket can be placed on top with the shorter pins holding it in place and the trinket can be soldered to these headers. I recommend using helping hands if you have them as shown in this photo.

Once this step is complete it should be possible to easily remove the trinket.

Step 4: Adding the RGB LED

Next we solder the RGB LED into place. The longest pin is the annode and the other three pins are the R, G and B leads. Make a note of where the annode pin is soldered. In my case it is the third pin from the left in column 4 on the PCB.

Step 5: Final Soldering Steps

The final soldering step is to add three resistors, four wires, and a battery connector as follows:

For each LED lead except the annode, solder a resistor to bridge the gap between the top and bottom half of the breadboard. Then solder a wire to connect the resistor to where the trinket's digital pins #0, #1 and #4 will be located when the trinket is connected. It is important to use these pins since these are the only PWM pins. In the photos below, the green wires are for this step.

Next, add a wire to connect the annode pin of the LED to the 5V pin of the trinket (the red wire in the photo).

Finally, add the battery connector with red connected to the Battery pin of the trinket and black connected to the GND pin.

Step 6: Writing the Code

The first part of the code defines the pins we want to use and provides functions for writing to the LEDs. The main loop simply cycles through a series of colors with a delay between each color change.

It is important to disconnect the trinket from the PCB when uploading code because digital pin #4 is shared with the USB port.

NOTE: After posting this code I found that there was an issue using PWM on pin 4. Adafruit just posted how to make code changes to work around this and I will update the code below when I get a chance. See this link for more information: https://learn.adafruit.com/introducing-trinket/programming-with-arduino-ide#analogwrite

Metalworking Contest

Tiny Home Contest

Fix It! Contest

5 Discussions

Are you able to actually modulate pin #4 on the (blue) with the code above? My understanding is that you need to jump through some hoops to enable PWM on pin #4, as described in this Adafruit tutorial.