RGB LED

A great way to add a variety of colors to your project with only one led is with an RGB led. There are two kinds of RGB leds, common cathode and common anode.

RGB LED

They are easy to hookup on a breadboard.  All you need is one resistor per color.

In this example we use a common anode RGB LED, 3 150 Ohm resistors, a trimpot (variable resistor) and an Arduino Uno R3 Microcontroller.

RGB LED Breadboard Setup

For the above setup the rgb LED has the long lead going to +.  The lead on right is connected to the resistor and then the resistor is connected to pin 6.  The left lead is connected to a resistor and then the resistor is connected to pin 3.  The second lead from the left is again connected to a resistor and the resistor to pin 5.

We chose to connect the rgb LED to these pins as they are PWM pins.

Now the trimpot is has three leads.  Left is connected to +,.  Right lead is connected to – and the middle lead is connected to analog pin 0.  Don’t forget to hookup power and ground.  If you are using a full size breadboard you may need to put jumpers for positive and ground in the middle depending on where you put the trimpot.

In the example code, we are using the trimpot to fade the color from blue to green.  You can easily change the code to mix other colors. Copy and paste the below code into a new Arduino sketch and try turning the pot to see the different colors.

/*
The Soldering Station January 2017
Trimpot & rgb led
*/

byte g = 3;
byte r = 5;
byte b = 6;
byte pot = A0;
int val = 0;

void setup() {
Serial.begin(57600);
}

void loop() {
val = analogRead(pot); // read the input pin (0 – 1024)
val=val/4;

Serial.print(“Value = “);
Serial.println(val);
Serial.print(“Green = “);
Serial.print(val);
Serial.print(” Blue = “);
Serial.print(255-val);
Serial.print(” Red = “);
Serial.println(0);

analogWrite(g, val);
analogWrite(r, 0);
analogWrite(b, 255-val);
}