Arduino LED Ambient Mood Light with Light/Luminosity/LUX Sensor

Finished Cube glowing red


After reading about LED cubes with Arduino doing nothing else than just fading between colors, i decided to build my one, but instead of just fading colors, why not gather information from the surrounding environment ?

Using the Adafruit TSL2561 and some assumptions (more on that later) I build this cube !


Keyes KY-009 3 color RGB SMD LED (It’s very bright and it’s cheap)  – You can find it here, at or at

Adafruit TSL2561

Arduino UNO R3

3 x 220 ohms resistors


I’ve read about color temperatures and Illuminance (since the Adafruit sensor returns LUX values) and came up with a theory for the lightning, based in Astronomy and Star classification ! It’s crazy, but bare with me.

I thought about this because, according with some reading I’ve done, the blue color affects your sleep at night, so, lets start with red color for darker ambiance and the cube can stay in a bedroom.  And now, the Astronomy enters:

A hot  star shines blue and a cooler star shines red. Here’s the Wikipedia entry for stellar classification and One-Minute Astronomer explaining star colors. And, here’s the typical illuminance values for the time of day – Wikipedia entry.  So, why not relate both ?

When it’s mid day, a bluish-white color. As the day progresses, the illuminance is getting lower (the LUX values), so the LED color as to change accordingly – Why not use Stellar classification ? And, the blue light problem gets solved because you’ll have a red light at night !

So, my idea was to “CREATE” a relation between the LUX values and the Kelvin values for the effective temperature of the stars and display the related color in the LED according to the LUX return by the sensor during the day.

Here’s my idea

Effective Temperature K Illuminance LUX Surfaces illuminated by Conventional Color description (and LED color)
>= 30.000 32.000 – 100.000 Direct Sun Light Blue
10.000 – 30.000 10.000 – 25.000 Full daylight Blue white
7.500 – 10.000 1000 Overcast day white
6000 – 7.500 400 Sunrise or Sunset on a clear day yellow white
5.200 – 6.000 320 – 400 Office lightning yellow
3.700 – 5.200 100 Very dark overcast day orange
2.400 – 3.700 <100 hallway, full moon (.027 – 1 LUX) red

This is just an example why i’m using this scheme. If we have a very high value of LUX, it’s like a very bright start – lets show a blue light. If we have a very low LUX value, is like a smaller red star – lets show a red light. Just like this – THERE’S NO RELATION BETWEEN THEM, JUST IN MY MIND !

To fade the LEDs and display the colors we’ll be using, I’ll be using  some code for the example “ColorCrossFade” available at the Arduino Tutorials section. (Don’t know the author – If you’re the author, please let me know. Credit is to be given where credit is due )

The colors will be described as percentages of RGB, from 0 to 100 – Using the text from the ColorCrossFade example:


This will be how the LED will fade between colors.

The Cube

The Cube I’ve made I took it from here – Twitter Mood Light – The World’s Mood in a Box – and here  – LED Cube Night Light

The differences are that my cube is white (my mistake with the supplier) and my measurements are (in metric system):

Bigger cube top (x1): 15cm x 15cm

bigger cube walls  (x4): 14,7cm x 14,7cm

smaller cube base (x1): 14,4cm x 14,4cm

smaller cube walls (x4): 14,1 cm (width) x 2,5cm (height) – a rectangule

smaller cube cover (x1): 14,4 cm x 14,4cm with a 6mm hole in the middle – This cover made of a mirror

The first photo is the smaller cube ( ignore the hole – that was a mistake) and the mirror top – the cover – goes here. The second photo is the bigger cube that goes on top of the smaller one – once more, ignore the hole – that was a mistake from the supplier

The mirror cover will amplify the LED light (or it’s supposed to 😀 )



Connections sensor

LED above the mirror


Here’s the schematic for the cube connections:

Connections for TSL

Every LED connection goes to a 220 Ohm resistor and then to Arduino PINs 9, 10 and 11 – These are PWM PINs that allow the fadding of the LED.


For the sensor to work, we need to download two libraries from Adafruit for the sensor.  The sensor TSL2561 itself and Adafruit’s sensor library.

You can find out more in Adafruit’s TSL2561 page.

Download the both and put them in your Arduino’s library folder.

The code is quite extensive, but many lines are just info

You can get the complete code from my Bitbucket account.

Include some libraries we need

Initialize the sensor

Display some info about the sensor


In the next function, were going to configure the sensor gain and integration time. The sensor gain means light boost in dim or bright situations. Integration time is the time the sensors stays collecting light samples. The driver version 2 has also an option for auto-gain – witch is set. More information can be read in Adafruit’s use page for the TSL2561 sensor.

LED configuration

The color definitions using R G B notation in an array

Setup function for arduino

The rest of the code is well commented

The next function is responsible for defining which color is next in the LED based on the LUX measurement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.