Arduino Uno and Triple output RGB Led:
Features:
- Forward Voltage (RGB): (2.0, 3.2, 3.2)V
- Max Forward Current (RGB): (20, 20, 20)mA
- Max Luminosity (RGB): (2800, 6500, 1200)mcd
Documents:
You can use either one 4 pin RGB LED or three single color LEDs per port. Be sure to remember that when
you use three single color LEDs you must use the common cathode (negative �-�) for each port. I hope this diagram
helps.
A standard RGB LED has a single anode for all the colors, and three cathodes (one for each color).
1- Controlling an RGB LED with an Arduino.
Hardware Required
1-arduino
1-330ohm resistor
1-common cathode or common anode rgb led
1-breadboard
5-jumper wires
The way an Arduino controls LED brightness is by the frequency at which it pulses electricity on the pin. So, with a standard LED, if you have it set to pulse at a frequency of 255 it will appear to be very bright. If you give it a pulse frequency of 30, it will appear to be very dim.
An RGB LED works in the opposite way, so 30 will be very bright and 255 will be off completely. This is because the RGB LED is actually lit when electricity isn�t being pulsed (and the cathode can reach ground). So, a higher frequency gives it less time being lit, and a lower frequency gives it more time being lit.
- int red = 0; //integer for red brightness
- int blue = 0; //integer for blue brightness
- int green = 0; //integer for green brightness
- int count = 0; //integer for step count
- void setup() {
- pinMode(10, OUTPUT); //sets the analog pin 10 as output
- pinMode(11, OUTPUT); //sets the analog pin 11 as output
- pinMode(12, OUTPUT); //sets the analog pin 12 as output
- }
- void loop() {
- if (count == 0) { //step 1 makes LED red
- red = 0; //red can reach ground
- blue = 255; //blue cannot reach ground
- green = 255; //green cannot reach ground
- }
- if (count == 1) { //step 2 makes LED blue
- red = 255; //red cannot reach ground
- blue = 0; //blue can reach ground
- green = 255; //green cannot reach ground
- }
- if (count == 2) { //step 3 makes LED green
- red = 255; //red cannot reach ground
- blue = 255; //blue cannot reach ground
- green = 0; //green can reach ground
- }
- if (count == 3) { //step 4 mixes colors (purple)
- red = 0; //red can reach ground
- blue = 0; //blue can reach ground
- green = 255; //green cannot reach ground
- }
- analogWrite(12, blue); //writes the blue value to pin 12
- analogWrite(11, green); //writes the green value to pin 11
- analogWrite(10, red); //writes the red value to pin 10
- count = count + 1; //increases count by 1
- if (count > 3) count = 0; //resets count to 0 if it�s over 3
- delay(1000); //pauses for 1 second on each color
- }
This program will make the LED red for a second, then blue, then green, then purple, and then it will repeat. Try changing the values in step four to get different color combinations. The result should be like this video (ignore the random talking in the backround�).
Controlling an RGB LED with an Arduino ( YouTube Video)























