Arduino mood light

I recently saw the cool mood lamp by Philips and I liked it. What I did not like was the price. I set myself to discover what the industry has to offer in terms of high-power LEDs. It turns out that since the old 20mA red LEDs the market has evolved in such a way that it seems the light appliances of the future might be completely LED-powered.

Now there are 3W and 10W LEDs available. Either monochrome or RGB. I like LEDs as they last forever (I've never seen a LED that stopped working unless it was due to a current overload).

High power LEDs are not cheap but they are very easy to control from a micro-controller using PWM (Pulse Width Modulation). They need DC low voltage power sources.

I did a test with an Arduino board and a protoboard with a ULN2003 that I've used to control a 3W RGB LED.



I programmed a never ending random sequence and this is the source code. Just connect each led (R,G,B) to the outputs 9,10 and 11 of the Arduino. If you need more current then use a Darlington driver.

Let's see the schematic:

R=22 OHM/3W (for 3W RGB LEDs)


Update: I've added a new "candle" effect playing with random changes on color and intensity.



Update2: Several of you asked me for the candle effect code. I'm posting the whole source file that includes other effects too plus a couple of analog inputs that select the effect and the brightness.

Comments

Hiroshi Ikeda said…
Some time ago I built a fake-ambiligth using a simple old-catode ligth you can encounter in eBay for less than 12 euros. The result is so good (a electric blue that don't disturb you to see movies if placed behind the screen and ligthing the wall) that I will buy more for my new house. I didn't take photos because I have my office in a complete mess!!!
You have done my idea, it's more complex and a little bit more expensive but the counter-part is you can build and adapt this kind of ambilight to whatever you need.
Good job!!!
Anonymous said…
Great job.

Are you able to post a schematic of some kind so I can study?

Thanks

SiD
misan said…
Sure, it's now on the post.
Jeremy said…
I see that this post is from early March, so this might be futile, but I have a request. I am a young Industrial Designer, and I am working on a lighting project for which I may be in a little over my head. I am wondering if anyone would be interested in writing some code and creating schematics for me. Compared to what you did on this post I am pretty sure it would be fairly easy but I would rather explain it in full privately. Anyway, I would definitely offer compensation (for which we could negotiate a price) but I can't promise it would be very much. It's not a very lucrative offer, more of a pity or compassion thing. If you are willing to even discuss it, I would really appreciate the help. Or if you know anyone else who might. I'd be grateful for any help.
misan said…
You may get all my help for free.

If you create a nice design I won't reject a sample lamp though :-)

You can contact me by email misan AT disca.upv.es
Dan McCormack said…
That candle mode looks great. Would you be willing to share the Arduino code you came up with for that effect?
ECO said…
Hi Miguel!

Can you tell me a bit about your resistor setup shown in the gallery? I see 7 resistors (can't read the color codes) but they look like 1/4 W ??

Thanks!
misan said…
Hi,

My 22 ohm 1W resistor is made of a set of 180 ohm resistors in parallel.

Please note that depending your voltage you may need a different resistor (i.e. if your power supply is not 12V but 10V then you'll need to recalculate the resistor).

I did not have 1W resistors at home :-)
Anonymous said…
Nice!

I want to make the same, but with 3x 2.5 Watt LEDs.

Can I use the ULN2003?

Thanks!!
misan said…
Floriaan you can do the same with 3 LEDs and ULN2003 but you will need to use one darlington output for each led colors.

3 leds with 3 colors each mean that you need nine outputs, but ULN2003 just has six, so a second one will be needed (our a couple of bipolar transistors like BC338 instead).

You can tie each color darlington input to the same arduino output pin (so all three leds will show exactly the same color).

Cheers,

Miguel
Anonymous said…
Ok, thank you for you fast reaction!
But I said it wrong, I mean 3 LEDs and each are one color, so a Red, a Green and a Blue LED.

The LEDs I have, are 700mA, but I saw that the ULN2003 only works up to 500mA. Do you now an other alternative for that ULN?
misan said…
Simplest thing is to parallel two outputs together. So each led is powered by two outputs. This allows enough current 2x500mA for each led. The problem is this approach does not ensure a good split of the current among outputs..

To improve upon this you need to duplicate LED resistor. If the resistor you are using for a LED is R ohms, then use two R/2 resistors in such a way that each output connects one of these resistors to the LED. This way the current share for each output will be fair.

At any rate, you need to check the total power dissipation won't exceed the ULN's. Total delivered current 2100 mA times the saturation voltage of the outputs (around 1 volt) makes 2.1Watts of total dissipated power. Check the specs to be sure ULN won't convert t into smoke.
hamletbon said…
Hi Miguel,

Thank you so much for the nice documentation. I've just purchase a 10W RGB LED , is it OK to use the same setup as you did? Can you tell me a bit how to come up with the right current and resistor values based on the datasheet of the RGB LED? Thank you so much!
misan said…
10 W wow that's awesome (and dangerous to the naked eye too!). I've seen your LED specs and they are common anode. Not bad but my drive circuit won't work with it (mine needs common anode instead).

Not sure if you're familiar with electronics or not, but three 2A PNP transistors may work for you plus the UNL2003 that will still be used too, but now just as a driver of your PNP transistor bases (that will need close to 12V when off (a voltage no arduino output can provide).

If needed I can provide you the circuit schematic.
hamletbon said…
Thank you so much, I will try to draw the circuit diagram and maybe you can give me some advice? How about the resistor? If I use a 12V supply, is 22Ohm still OK for this 10W LED?
misan said…
Have a look at this

I did not know my cellphone camera was so bad, sorry.

Oops, I can see a resistor is missing from transistor collector and LED in my circuit. Do no forget to add it or LED will be destroyed!! Resistor value will range from 4 to 8 Ohms depending on the color (my advice is to first have it working with 20 Ohhms though).
hamletbon said…
Thanks, I will try it and post the result :)
Anonymous said…
Can you recommend a transistor for the last picture you posted? Great project by the way!

James
misan said…
If you want to use discrete transistors I would use BC338 that can handle enough current for a 3W RGB LED.
Anonymous said…
There are simulated dawn lighting systems that are very good for waking up - very pleasant and very good for the health, but also extremely expensive. They turn on the light gradually over about half an hour, so that you wake up in a natural biological way. It would be good to develop a controller for such a light using the arduino. You couldn't control a fluorescent with PWM I suppose? I suspect the tube would probably not work in that way. Otherwise you could use a high power low energy fluorescent, which would be ideal. For maximum effectiveness the light wants to be pretty bright at maximum power.

Bhante.
misan said…
Dimming fluorescent tubes is possible but more complex than light bulbs. For a light bulb you can use a phase angle control if AC power is used or just the PWM Arduino can do easily if lamp is powered from a DC source.

You may want to check this out.
Peter said…
Hey, is there a schematic?
Anonymous said…
Hi Miguel,

thanks for your descriptions, your code and videos. I did a litte mood lamp with two small rgb leds and my brand new Arduino. It works well, but it needs more power ^^. So I would like to build a amp like yours. For I am new in doing electronic stuff, I would like to know, if this 3W led would fit:

http://www.led1.de/shop/product_info.php?products_id=1032

Does it need a heat sink?

Thanks for your help!
Veit
misan said…
Yes, that led seems ok.

THe one I used was cheaper.

I'm not using a headsink but do not put it inside a closed box (so air can cool it down),
jaume said…
hey, good job
Can I ask you a question?
I've done a lighting system based on your schemathic. But I ordered rgb leds, and they where with common cathode. How do you think I can modify yours for using those leds?
Thank you very much.
Best wishes

jaume
misan said…
@Jaume:

Common cathode means you have to connect the cathode to ground (GND) and then you have to provide a positive drive.

This cannot be done with a ULN2003 but you can use PNP transistors instead (emiter follower configuration).

You can also use a PNP version of UL2003.
jaume said…
wow,
thank you a lot , miguel
So fast answer, so useful!
Supose I can just don't connect the two top pins of the A2981 you told me, and cut the power line (12v) arriving to the led and wire it to ground, all trying to use the printed boards I have done, that are more or less like that: http://4.bp.blogspot.com/_bdWC_nFEbSQ/S93sZHkck0I/AAAAAAAAAB8/Xr79tkVraAI/s400/placa2.gif
The connectors on both sides are: the top one is 12V+, descending ground and the 3 lines of the led colors.
And the four pin in the center
are for the led 3 colors and (suposed) comon anode.

What do you think? I think is that (or similar)or buying some new leds for this project, becouse I have near no time for bigger modifications now.

I also wanted to comment you a modification I thought of your circuit, changing the resistor of the red channel from 22 ohm / 1 watt to 43 ohm / 1 w, becouse that one burned, I suposed it was becouse red line needs less voltage, so that resistor had to dissipate more than what can.

Thank you a lot, you have been very useful for me and my project, and of course you'll be refereed, and this site linked, on it.

regards

jaume
Jarlen said…
Miguel,

Thanks for this excellent post. I bought one of those Phillips lamps and was extremely disappointed when one of the LEDs burned out within a few months of my purchase. To be able to create my own version would be a dream. I tried to download the candle flicker source, but your site seems to be down, could you repost it somewhere else? I'm new to electronics but am very excited to start creating my own versions of electronic design.

Thanks,
Jarlen
misan said…
Code download should be working ok now.
Unknown said…
Thanks for the great project! By far some of the easiest instructions to follow and great code! I do have a question regarding the code though...I am using a hotpot rotary and a plain ceramic 10k pot, but they seem to have no effect. When I press the arduino reset button the pattern changes. Any ideas? Thanks again!!
misan said…
@Vince: Thanks for your kind comments. Please note the values measured from the potentiometers are only measured after reset. That means that any change you do is not reflected in real-time but after the next reset.
Unknown said…
Hi

I have a question.

Port 9, 10, 11 (R,G,B)from the arduino will output 5 volts, which goes into the darlington array, which amplifies the current. Since you are supplying an extra 12 volts to the LED's as well, what is stopping them from being "on" all the time?
misan said…
@Sahir:

Darlington is like a switch. If the arduino pin driving it is 5v then current can flow from the +12v through the resistor and LED. Then LED will be on.

But if the arduino pin is low (0v) then the darlington won't allow current to go through so the LED will be off.
Ori said…
Hi,

Thanks for the explanations.

I would like to know how the ULN2003 (IC) gets it power. Is it throught pin 9.

Thanks.
misan said…
@Ori:

Contrary to many chips, ULN2003 does not "need power" as you word it. This is because it just packs a few (7) [Darlington] transistors.


You may connect pin 9 to the +12V if you want, but this connection is just not needed in our circuit (though it won't harm if you connect it).

Think of each transistor as a switch that can ON or OFF. A small current delivered from each Arduino output is enough to make switch move to the ON state, no other power is needed.
xray911 said…
Dear Miguel,

i'm looking to design an Arduino controled moodlight myself and i was wondering: on one off your picture's you can see your moodlight running while it is on top of the Arduino (like a Shield. but i only see one power input (which is going to the Arduino) so this is 5V. but in your schematic i see 12V for the 3W LED. how does this work? Where do you get the 12V from? and why do you use 12V and not 5V? is this beacause of the Voltage drop across the led?

Great job on your moodlight!

Robin
xray911 said…
Ah That explains a lot! My search for an 12v adapter starts.
I still have one question: at wat current is your adapter rated? Because the 3w led will draw about 1A right? But how about the Arduino it self? I know this depends on the number of things it controls but I will only use 3 Pods and 1 push button.

Robin
misan said…
@Robin: A 12v 1.5A or 2A power supply will do it. I can see you can get one on eBay for $6-%10.
Willem said…
Hello Miquel,

From the datasheets and forums are quite unlcear about the UNL2003.If i understand correctly the UNL2003 is able to output 500ma on each channel up to a total of 2100ma?

And this would enable it to power two 3w RGB leds with a singel UNL2003?

I am planning to use your schema to build a 2x2m 9 segment wall panel controlled with Arduino. The fire effect would be quite nice.

Thanks for your blog it's quite enlightening.

Willem
misan said…
@Willem: Each color led is going to need around 300mA . As a single output of ULN2003 can handle a maximum of 500mA it is not advisable to connect more than one LED to each output.

You can put two inputs together and then each corresponding outputs will act the same and you can connect a LED to each one.

However, for larger display I would use one power MOSFET for each color, like they do in this schematic: http://picprojects.org/projects/bigmosfetrgb/im/rmdschematic.pdf

The STP36NF0 can handle up to 30A (absolute maximum rating, it is better to stay at half of it, and remember to add a heat sink) per color, that would be 50 LEDs!!
Willem said…
Hello Miguel thanks for your comments. I am going to try drive as many as possible colorleds individually using a Arduino ATmega1280. I think that the ULN2003 is the best option for this purpose. The STP36NF0 is a brilliant and cost effective idea for a really big project.

If I have done my calculations correctly a 7,5volt powersupply should be enough to power a single RGB led.

7,5v (supply) - 1,5v(cev max from ULN2003) - 3,5v (led green) leaves 2,5v for the resistor = 7ohm(8,3ohm)

Thanks Willem
misan said…
@Willem: You're welcome.

I reckon 7.5V would be enough. Just remember each color LED as a different forward voltage and it may need a different resistor.
mm said…
Hey Miguel,
I'm very much an amateur and I'm trying to put this together, but using a twitter feed to control the RGB values...

My question is regarding the resistors, right now I have 20ohm-1/4W and 1W resistors, which should I use? and how many?

I would really appreciate your help.

Thanks,
mm
misan said…
@mm: With 20 ohm/1W you can't go wrong :-)

Though it depends on the voltage of your power supply. As a first bet I'd go with that value you already have at hand.

However, if you are using a 3W LED then maximum current will exceed even the 1W power rating of your resistors if you keep each color to its maximum brightness. Though I don't think your resistors will burn they will get pretty hot. If you need to be sure you are out of trouble look for 2W resistors (or wire them as follows: put in parallel two groups of two resistors in series).

---+---R------R----+---
....|.......................|
....+---R------R----+
mm said…
Thanks a lot Miguel!!

It worked, but it's emitting only RED, which means I wired it wrong.

I have a question regarding power,

In this image:

http://s10.postimage.org/ygf320tiv/board.jpg

Are my assumptions correct regarding the power pins?

Again thanks a lot for the help!
misan said…
@mm: yes, if you look at Arduino board socket on the side of the Analog inputs, you will see (left to right) Vin Gnd Gnd 5V 3V3 RESET. So the pins you mark in the picture belong to the two rightmost. Vin and Gnd.

Please remember my drawing calls for common anode LEDs.

Another cause of only the red being lit could be not enough voltage on your power supply (red color is the one that works with a lower voltage).
xray911 said…
Hello Miguel,

i collected all the parts for my arduino mood light. i have the following parts:
1x 12V 2A DC adapter
1x 3W LED Star common anode
1x ULN2003
1x Arduino
1x PCB with holes
male headers.

the only things that remain are the resistors but i cant figure out how to calculate them. i saw on you picture's that you use 7 180 ohm resistors. so that is the same as a 1.75W 25ohm resistor. how did you calculate this? because i have no idea what the voltage drop across my 3W LED is.

hope you can help me out.

Robin
misan said…
@Robin: Exactly, 7 180 resistors in parallel is 180/7 = 25 ohms.

I would try the 25 ohm resistor you have and it will go fine. You are not telling me what voltage you have (12V?).
The simplest approach is to use the same resistor value for each color, the only drawback is this way your are giving red color an extra oomph (as red color is the one that works with less volts), but the difference may not be too significant (maybe when you have all channels to 100% you won't get a perfect white, but this may happen even if you balance de resistor well).

Please note that each manufacturer (and model) is going to have different characteristics even if all are rated 3W.

Good luck with the project,

Miguel
xray911 said…
Hi miguel,

i am using 12V.
okay i will try the 25ohm resistor.
is it possible to measure the voltage drop? because if i am correct the voltage drop across a led is always the same right?.
then i could calculate the resistors to get the maximum light out of the led.

Robin
misan said…
Voltage across a diode changes with the current. Only the specs will tell you the nominal value and current. Take into account that up to 2 volts may be dropped in the ULN darlington.

A sample calculation could use this page:

http://ledcalculator.net/default.aspx?values=10,3.6,300,1,0
xray911 said…
Hello Miguel,

I just got my arduino moodlight working!
i posted a video on youtube:
http://www.youtube.com/watch?v=sn0CJRpfhBQ

Robin
misan said…
@Robin: Good job. Congratulations,

Miguel
Paul said…
Hi!
I wired the circuit with 9V and 15Ohm resistors (I bought some 5W :D). Without Arduino/Darlington everything's fine. However, if I connect the LEDs Arduino->Darlington->LED like in your circuit it DOES work but the LEDs are flickering – I measured current across the LEDs and it's far too low... Any idea why?
Thank you!

Paul
misan said…
Is your power supply capable of delivering the required current?
Paul said…
Yes, I measured the current, it it's about 400 mA if all LEDs are turned on. (I know they could be brighter, but for testing purposes it's ok). My power supply does 500 mA.

If I feed the inputs of the Darlington with 5V directly the LEDs also turn on at full brightness. Only the 5V from the Arduino pins seems to be not enough. Maybe because I'm running that from the USB power supply? The Arduino is doing nothing else apart from setting the three output pins to High.

With the Arduino->Darlington->LED setup I only measure something between 10 and 30 mA which is probably too little for the LED.
misan said…
Paul, please note that there are a couple of potentiometers in the circuit, one selects the type of effect desired, there other controls the maximum brightness of the effect. If the latter has a low value then the LED will not get very bright. Have you checked that?
misan said…
Oops, I've just noticed this detail should be in the schematic of the top but it isn't!!

Please have a look at the comment on the source code that asks for a couple of 10K potentiometers connected to analogs pins 1 and 2.

Alternatively you can connect analog input 1 to +5v to force the maximum brightness.
misan said…
Oops, I've just noticed this detail should be in the schematic of the top but it isn't!!

Please have a look at the comment on the source code that asks for a couple of 10K potentiometers connected to analogs pins 1 and 2.

Alternatively you can connect analog input 1 to +5v to force the maximum brightness.
Paul said…
OK got it, it WAS due to the USB power on the Arduino. I attached the 9V power supply to the Arduino and it works.
Unknown said…
hi there its a good instruction. congrats !!

im designin a mood lamp as well. i added a pot to change the colors with the help of arduino code that i wrote. it worked. but i was using 5mm rgb leds. not 3 watt one.
so anyways now i got my new 3 watt rgb led since it gives much more brightness. but i have a problem about the resistors. i used three 22 ohm 4 watts resistors. before hooking it with arduino i just wanted to try resistors alone with only rgb led and the power supply which i used 12 volts and 1 ampere. the problem is that the resistors heat up so much that i cant even touch them when the power is on. it does not smoke :) but i bet it will if i let it on for some time. so what is the problem here? i mean the resistors i use are really powerful and quaity ones. btw i didnt connect them to uln2003, do you think its because of this? (which i do not think so)
write me if u have the time.
thanks in advance
misan said…
Hi Serkan:

Let's see: If you connect a red LED with a 22ohm resistor to 12V you are missing some the voltage drop the ULN2003 will cause and some of the current limit that will introduce too, meaning more power will be dissipated (and more light will go through the LED).

Back of the envelope calculation will give around 9.5V/22ohm = 0.43A which means 4W of power in the resistor which will keep it hot.

Once you factor in that red LED is the one that will use more current (due lower voltage drop) and you use both ULN and PWM (as you usually are not lighting all the colors full blast) the resistors will not get as hot as your test above, but still will get hot.

If you want to reduce the heat you can change the power source to 5V instead, and adjust the resistor values accordingly, but still remember you'll need around 1.5A for reaching the maximum brightness out of your 3W RGB LED.

Unknown said…
thank you for the fast reply Miguel.
I am thinkin to use this lamp permanently so for instance i want it to work without problem 8 hours a day. I am makin my own arduino and I will put the circuits and the led in a closed plexi glass box. So thats why my concern was these resistors. Since they get so hot I dont think the lamp will work more than couple days. Dont you think so? Or the resistors will endure bein hot?
Another thing is that if I use 5 volts power source, it will be difficult to find a proper resistor since the forward voltage in green and blue are almost 4 volts. So thats why 12 volts is better to give accordin to me.
So what do you say? Shall use 22 ohm 4 wats resistors with uln2003 and arduino for the lamp?
misan said…
Exactly, 5v is a bit short and 12v might be popular but more voltage that strictly needed.

A 4W resistor can handle 4W without destroying itself, but if you keep it in a closed box the thing can get pretty hot, as you have three similar resistors.

As I mentioned the 4W is only a limit case, red color, constant current and not ULN. Even if you reach 80C, which I doubt, plexiglass will not fuse nor be burned.

I'd say you go for it with 12V and 22 ohms, if you later still find it too hot for your taste, try to use 7 or 8V power supply instead.
Unknown said…
Ok thank you Miguel. Great to get such fast answers.
I think Ill use 9 volts and 1A adapter. Since I can also use the same rate of source for my arduino with a 7805 regulator. Ill use the same resistors. Maybe Ill get less brightness but it will be much safer.
Take care till the next time. I think Ill bother you time to time ;)
Unknown said…
Miguel, ill run 3 LED (Non-RGB) 12V 10W (Forward Voltage (VF): DC 9-12V
Forward current (IF): 1050MA) Im thinking in wiring in parallel two outputs (also the imputs for MCU), Do you think i need a Resistor if i power it 12V ?

Regards.
misan said…
Definitely you need two outputs for each 10W load and a resistor too, but in this case maybe 2 ohms/ 3W would be ok. I am not sure the ULN2003 will handle the three channels at full power without giving up the ghost. Replacing it by three Mosfets will be most likely a good idea.
Anonymous said…
What i want to know is

A) What kind of light would do the job?
B) Where should the light be placed to get the best effect so the whole wall is bathed in light?
wifi

Popular posts from this blog

VFD control with Arduino using RS485 link

How to get sinusoidal s-curve for a stepper motor

Stepper motor step signal timing calculation