An RGB LED is a LED which has three LED's integrated in one packaging. These LED's have the colors Red, Green, and Blue. The RGB LED used here is a hyperflux LED with common cathode, which can draw 20mA current. Such a LED costs about 2€. With these three colours you can mix to any colour.
In this design each colors can be controlled seperately. The technique to control the intensity of each LED is pulse width modulation (PWM). When using 8-bit PWM a number of 256 * 256 * 256 combinations can be made, thus the LED can show 16.777 million colours, and 256 different brightnesses. When all the three LED's are at full brightness the color will be white. When they are all off the color will be 'black' in the dark ;). The LED used here has a common cathode and is an Ultra Brightness type. The intensity of each LED can be varied from minimum to maximum in 256 continuous levels by using the potentiometers. Different intensities of red, green, and blue LEDs produce different colors.
Schematic and Build
Below shows the schematic diagram.of the RGB LED color mixer.The RGB LED used here has four leads, one for each color an one for the common cathode(ground). The Red LED operates on a voltage of 2 V, Green needs 3.5 V, and the Blue LED needs also 3.5 V. Each LED draws 20mA current, so the maximum current consumption is 60mA. The supply for the circuit is 5V DC. The µ-controller reads the value of the potmeters by using the three channels of the ATMega328's analog-to-digital convertor. The corresponding value is reflected to the thrtee LED's by using a eight bit PWM. Each ADV channnel converts the analog voltage output of the potentiometer into a digital value within the range of 0 to 255 which can be converted directly to the intensity level of the coresponding LED.
The circuit is simple.The RGB LED is hooked up to the PWM outputs on PORTB1, PORTB2 and PORTB3 of the ATMega328. The potentiometers are connected to the ACD channel inputs PC0- PC2.There is also a resistor between the LED's and the µ-controller to limit the current to 20mA. The circuit with the RGB LED with the current limiting resistors and the potentiometers is build on a breadboard and connected to the ATMega328 board with jumper wires.
You can buy the ATMega328 board at www.bizztronix.eu.
The code for the RGB LED color mixer is written in C with the WINAVR C-Compiler The hardware PWM timers of the ATMega328 are used to let the LED's light. To use the PWM timers you first need to initialize the timers at the begin of the program code. The value of the potmeters is read by the adc converter and assigned to the corresponding PWM that will light up the LED's. You can copy and paste the textfile into the WINAVR C-compiler. Below you find the C code.
// program name: RGB LED Color Mixer
// this function read the value of the selected ADC channel
// main program
DDRB = 0xFF; //set portB as output
while(1) //infinite loop