Posts Mood lamp

Mood lamp

Hello World!

In this post, I will show you my RGB LED powered mood lamp. Now for first, let’s see the result:

It was placed into a cheap lamp enclosure from IKEA. I took out the original 230V socket, and placed my panel in.

It is powered by two simple RGB LEDs. In daylight, it hasn’t got so powerful light…

But in the dark, it looks pretty cool :)

The schematic is very simple:

It can be powered from 5V DC at maximum.

The first concept was to make a lamp, which continously changing it’s color components randomly. It was working, but most of the time all the colors were more or less lighting, and because of this, the lamp had always white or almost white color. It was not exactly what I expected. So the second aim was to make an array with the colors I would like to see, and the lamp is fading around these. When it reached a color from the array, it waits some time, then moving to the next color, smoothly. You can customize it to your favorite colors…

The atmega8 is probably too heavy for this project, but I had no attiny controller, when I built it. It has two RGB LED, one was too dark. They are regular RGBs, without diffused lens. That was a little problem, because they had 3 different light and I couldn’t mix them to produce colors. So I got a nail-lile and diffused them manually :). The LEDs are controlled on different AVR pins. The reason is that, I will hopefully write an advanced code to control the two LED differently.

The code is very simple. It is based on a softPWM controlled by a timer. SoftPWM because in this case we can have as many PWM channels as many pin we have on the device. Now we need 6 for the two LEDs.

The algorithm is just a comparison between the PWM data (the brightness of a LED) and a running variable:

//this is the variable to compare with the brightness levels
if(soft_pwm_var == 0) PORTB = 0b00111111; //set on all, when the pwm variable is overflowing
for( unsigned char i=0 ; i<3 ; i++ ) //the core of the soft PWM
   if(soft_pwm_var == bright[i]) PORTB &= ~((1<<i) | (1<<(i+3))); //set off both LED's color component based on it's brightness level

The bright array stores the wanted color intensity for the 3 color component. All of the array members are compared to the soft_pwm_var. When the soft_pwm_var is reached one of the component’s brightness, ot turns off the pin. When the soft_pwm_var is overflowed from 255 to 0, it turns every pin on.

There is a speed variable in the code. You can set it to lower than 30, to make the changing faster.

The final version looks like this:

The LEDs are rounded to light to different places of the lamp.

And finnaly the lamp in action :) :

Unfortunately the colors are not so cool on the video, it’s much better in live.

Here is the complete code with comments.

Have a nice day!

This post is licensed under CC BY 4.0 by the author.