In this projects 8 different colors are displayed with the use of a RGB LED. The microcontroller that is used is the ATMega8.

 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. Such a LED costs about 1 Euro. With these three colours you can mix to any colour. When using 8-bit PWM a number of 255 * 255 * 255 (= 16581375) 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 . In this projects 8 different colors are displayed, the colors are controlled by a potmeter. The microcontroller that is used is the ATMega8. See in the below table what colors can be displayed.

mood lamp pic1


Schematic and Build

 mood lamp sch

 

The RGB LED used here has four leads, one for each color and one for the common cathode(ground). The Red LED operates on a voltage of 1.8 V, Green needs 3.8 V, and the Blue LED needs also 3.8 V. Each LED draws 20mA current, so the maximum current consumption is 60mA.

The circuit is very simple.The RGB LED is hooked up to the outputs on PB0, PB1 and PB2 of the ATMega8 microcontroller.

Resistors R1, R2, and R3 act as current-limiting resistors for red, blue, and green LEDs, respectively, and are 150 Ohms each to limit the current to 20mA.

The RGB LED and the resistors are placed on a breadboard and connected to the ATMega328 board. 

A tea light cover can be used for proper mixing and diffusing of the three colors.

mood lamp pic1

part list
amount name value
1 ATMega328 board  
1 Hyperflux RGB LED  
3 resistor 150
1 potmeter 5K

 

You can buy the ATMega328 board at www.bizztronix.net


Software

The code for the fading LED is written in C with the WINAVR C-Compiler. The code runs on a clock source of 16Mhz. You can copy and paste the text file into the WINAVR C-compiler.

// program name: mood lamp
// date: 16-03-2016
// target device: ATMeg8
// purpose: mix RGB LED to 8 colors with potmeter, uses ADC channel 0 input.
// author: www.avrprojects.net
//

#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 16000000UL
#define LEDs PORTB
#define black 0b00000000
#define green 0b00000001
#define blue 0b00000010
#define cyan 0b00000011
#define red 0b00000100
#define purple 0b00000101
#define yellow 0b00000110
#define white 0b00000111 

// main program

int main (void)
{
DDRB = 0xFF; // set port B for output
PORTB = 1;
// infinite loop
while(1)

{
_delay_ms(50);
PORTB ++;
if (PORTB > 7)
PORTB = 1;
}

}

 

 

nr ADC.O value color
0 32 black
1 64 blue
2 96 green
3 128 red
4 160 cyan
5 192 yellow
6 224 purple
7 255 white

Things to Do

  • Use PWM to show more colors.

Video