Incandescent light bulbs are slowly becoming a thing of the past with LEDs kicking in, especially RGB LEDs. So, why not learn how to control your RGB LEDs the way you want? In this tutorial we’ll be setting our RGB LED to any color we want with the help of a potentiometer. Let’s go!
List of things you’ll need:
- Arduino Uno
- Breadboard wires
- RGB LED
- 3x 220 Ohm resistors
- USB-B cable (or something else to power your Arduino)
Once you’ve got all of them, connect them like this:
Like with every LED, we need a resistor to keep it from frying. You’re going to need 3 in this case for each color (red, green and blue).
Once that’s done, connect your Arduino to your PC and upload this sketch below.
To do what you require you will need to crossfade between red, green and blue. At zero potentiometer setting red is fully on. Green and blue are off. As you adjust the potentiometer over the first 1/6th the green fades up to 100%. On the next 1/6th the red fades out until you only have green. The pattern repeats for green to blue transition and finally for blue to red ending at the start point of full red.
You can see in the code above how we managed to do it with this theory.