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.

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.

rgb led common cathode


 Schematic and Build

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.

mood lamp sch

 

The circuit is very simple.The RGB LED is hooked up to the PWM outputs on PORTB1, PORTB2 and PORTB3 of the ATTiny2313. There is also a resistor between the LED's and the ATTiny to limit the current to 20mA. The RGB LED is placed on a breadboard and connected to the ATTiny2313 board.

RGB LED color mixer

You can buy the Attiny2313 board at www.bizztronix.eu


Software

The code for the fading LED is written in C with the WINAVR C-Compiler. In this example the LEDs will fade in and out one by one. The PWM timers of the ATTiny2313 are used to let the LED's fade in and out. To use the PWM timers you first need to initialize the timers at the begin of the program code. The speed of the fading in and out can be changed with changing the clock speed of the ATTiny2313. You can copy and paste the textfile into the WINAVR C-compiler. Below you can download the C code and the hex file.

rgb_led_color_mixer.c


Video