Go Down

Topic: How to control RBG LED with 1 output? (Read 1 time) previous topic - next topic

corpse

I'm curious how easy/difficult it would be to do something (I'm a novice with electronics and arduino), I'll do my best to explain.

I want to get 2 different colors out of my RGB LED, doesn't matter which colors, but I want to be able to do it with 1 PWM pin, instead of 1 pin per color.

PWM: 50 - Illuminate only blue led (using the full amount of power provided)
PWM: 150 - illuminate blue led with 1/3 the power, and the red led with the remainder.

Or if there's a better way to go about this, I'm all ears :)  Thx

sbright33

You could do this by changing the frequency, and some caps, OR

If you design the matching circuit for red only, not blue, the red will ignore short pulses and only light when they get much longer.  In effect changing the color and the brightness together as you increase the duty cycle.  You just need to choose an appropriate time constant.  I will leave this as an exercise for the reader.

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Grumpy_Mike

Quote
You could do this by changing the frequency, and some caps,

Yes.
But the problem is the peak current into the capacitors will exceed the maximum allowable current from the pin if you are not careful. Remember a discharged capacitor looks like a dead short when you put a logic high signal on it at first.

However changing the duty cycle will have no effect on a capacitor's reactance.

corpse

#3
Apr 13, 2012, 06:49 am Last Edit: Apr 13, 2012, 07:21 am by corpse Reason: 1
I did a little reading on the phases at the Arduino, and at the present time, way over my head.  Trying to think of an easy alternative, and had one idea..

I've got a relay module, and if I understand right, the coil activates at ~3v.  So, maybe it's possible to hook the relay up to just 1 color of the led, this way when the pwm output is at low power, the relay doesn't have enough power to trigger; but at full pwm power, the relay will trigger and both colors on the rgb led will fire, instead of 1.

Before I screw up something though, I should ask, would it be safe to try use the pwm for relay control in this way?

edit: guess that wont' work.. after looking more closely, the rgb led uses all negative leads for the colors, so I can't use the relay to control that, bummer.

Grumpy_Mike

Yes that would work although you have to drive a relay through a transistor.

Quote
rgb led uses all negative leads for the colors

No problem, just connect the anode to +5V, the red cathode through a resistor to the PWM pin. Then connect the relay contacts to the green cathode via a resistor and the other contact to ground.

corpse


Yes that would work although you have to drive a relay through a transistor.


This is the path I'm going down http://www.csgnetwork.com/transistorcalc.html
This is my first time looking/trying to understand this schematic.. I entered values:
VCC=5
R1=100
R2=500

I presume the connections mean (and how I'd use them in my scenario):
VCC -  5v
VB - pin 9 PWM
VEE - GND
VC - first led
VE - second led

As VB increases, once it hits almost 1v is when ve starts to output power (ie: to my second led)

Is that kinda how that circuit works? 

If my understanding is more or less right, how do I know which transistor in this case to get when I head to radio shack?

Grumpy_Mike

Quote
This is the path I'm going down http://www.csgnetwork.com/transistorcalc.html

That is not quite how you want to use it.
R2 should be zero ohms, that is it should not be in the circuit, replace it with a short.
R1 is your load, this is where the relay coil should go.
You need a resistor from the base to your arduino PWM output.

This will explain what PWM actually does.
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

This shows you how to wire up a relay:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html
Any general purpose NPN transistor will do, I am assuming your relay doesn't take current, less that 100mA anyway. If it is more you need a transistor that can handle the current your relay requests.

n1spx


...would it be safe to try use the pwm for relay control in this way?


You'll want to use a capacitor to smooth out the voltage being applied to the relay coil.
Otherwise, the sharp edges of the pulses will cause all sorts of transients on that pin.
I wouldn't be surprised if it caused problems in other parts of the circuit as well.
Depending on the current requirements of the relay, you may not be able to supply it directly from the pin, and would likely need a transistor as well.

Grumpy_Mike

Quote
You'll want to use a capacitor to smooth out the voltage being applied to the relay coil.
Otherwise, the sharp edges of the pulses will cause all sorts of transients on that pin.

No you don't, no it won't.

n1spx


Quote
You'll want to use a capacitor to smooth out the voltage being applied to the relay coil.
Otherwise, the sharp edges of the pulses will cause all sorts of transients on that pin.

No you don't, no it won't.


Mike,
  Are you saying that the rapid on-off of PWM on the relay coil won't cause inductive responses?

Grumpy_Mike

I am saying it will not cause you trouble, there is no need to smooth it. The inductor has its own time constant, so current will not be switching as rapidly as you might think.

n1spx

Where things won't hurt, and may help, I generally prefer to do them unless there are extenuating circumstances.

Grumpy_Mike

Quote
Where things won't hurt, and may help, I generally prefer to do them

Yes but this will hurt and won't help.
The output dissipation of the driver will increase when it is operated in the linear region.

n1spx

Then it comes down to whether the extra heat in the transistor or the noise generated are worse.

Honestly, at low levels, neither is likely to be a problem.

Go Up