Ikea hack moodlight – part 2

It has been too long since I started writing about my Ikea hack moodlight.

The idea is simple – take an ordinary, cheap, Ikea table lamp and make it better.

In the first part, I described the project and mentioned something about programming the WS2811 LED strip. I started with an Arduino and ran a couple of sketches to make patterns such as the rainbow, Larson scanner, dripping water, and other interesting things. What I didn’t mention was that I put two strips of 10 LEDs in parallel – so that each strip shows the same pattern.

Part 2 – driving the white LEDs

The second challenge was to illuminate a pair of strips of warm white LEDs. The challenge here is that they are 12V rather than 5V, so I need some way of making the microcontroller digital pin switch the LED strips. For extra credits, this can use pulse width modulation (PWM) to control the brightness. The starting point was to examine the circuitry of an RGB shield – the one I used was created by Phenoptix but is no longer in stock, however you can see the schematic on the re-innovation.co.uk website and it may still be available somewhere.

The important part of the circuit is how a pair of transistors (PNP and NPN) and a few resistors do the switching of relatively high current 12v from a low current 5v pin.


I say relatively high current because the white LED strip can draw a fair amount of current depending on the length of the strip. Typically there are 3 LEDs in series in each segment of the strip and I am using three segments on each of two strips (so that is 18 LEDs). If I drive each LED at 20mA, then I need to source or sink 360mA – way above the 40mA max that the ATTiny or ATMega chips can handle on any I/O pin. This is well within the 1500mA that the BD135 can handle and we should not even need a heat sink on the transistor.

Many people have written tutorials about how to use the PWM pins on an Arduino to control the brightness of an LED, basically you need to write a value between 0 and 255 using AnalogWrite() to the appropriate pin. The problem is that the apparent brightness is not linear – when you are near 0, small changes produce a large change in brightness (and you can easily see the steps in brightness), but when you are near 255, you need to make large changes to see any difference. Also, I tend to think of brightness in terms of percentage – 0% is off, 100% is full brightness, 50% is half bright.

The first thing is to create a lookup-up table (LUT) that has an entry for each of the 256 possible values. Each entry is the brightness for that particular value.

Here’s an example from the Adafruit learning system:

Access this using a statement like  result = pgm_read_byte(&gamma[input]); to translate an input value to the value you will write to the LED PWM pin. I wrote a preprocessor macro to do this, for reasons I will explain in another part.

Of course, you could easily make the table have just 101 elements (corresponding to 0-100% – notice that I’ve added an extra element)

Power supply

Just a note here about the power supply. Initially I was using an Arduino for development with the RGB LED shield, and a 9-12V power supply to the shield provided power to the Arduino too. The final design uses an ATTiny85 microcontroller, so I needed a suitable power supply.

Given that I didn’t need to drive too much current I thought a simple 7805 regulator would do the job. However I found that although the Arduino didn’t take too much current ,the RGB LED strips needed a good amount of current (10 RGB LEDs x 2 strips = 60 LEDs). If the LEDs were on full brightness, then 1500mA or more would be drawn. The regulator did get rather warm and I used a heat sink. In practice, none of the patterns runs all of the RGB LEDs at full brightness, however worth being aware of the worst case. The diodes (which are general purpose 1N2001/2/4 diodes) are to protect the circuit from reverse connection and also to isolate the +5V power when the programmer is connected.


Although I show an input of 12V I have found that this will work at 9V, but the white LEDs area bit dimmer. A 2A  (2000mA) 12V DC power adapter provides enough power.

Comments are closed.