Driving RGB LEDs with an Arduino

Yes. This is an issue for e.g. switched-mode PSUs, where you may have large MOSFETs with significant gate capacitance, and you're switching at hundreds of kHz.

When using a MOSFET as a switch, the power dissipation is low when it's fully off (low current) or fully on (low voltage drop), but high when it's in between (both current and voltage drop are significant). Consequently, when switching large currents, you want to spend as little time in the linear region as possible, which means charging and discharging the gate capacitance as quickly as possible.

So while an idealised MOSFET has infinite gate resistance (and a practical MOSFET isn't far from that), the combination of significant capacitance and fast switching times mean that power-MOSFET drivers are designed to source/sink pulses of several amps to/from the gate.

However, this isn't something you necessarily need to worry about for driving an LED. Even if you're using PWM to vary the brightness, the switching frequency doesn't need to be more than a few hundred Hz. And a MOSFET designed for less than 1A will have much lower gate capacitance than one rated at 50A or more. Finally, efficiency is less of a consideration; if a 1kW PSU is "only" 95% efficient, that's still 50W of heat which needs to be removed.

The main consideration for using an FET with a microcontroller is that you want one which will saturate (turn fully on) at a sufficiently low gate voltage. These are normally termed "logic level" FETs, meaning that the output from a (nominally) 5V device will be sufficient to drive the gate directly. The data sheet for a device will normally have a graph of channel resistance (Rds(on)) against gate voltage (Vds).

Reply to
Nobody
Loading thread data ...

Now I just need to decide how to power it, connect a microphone for sound sensing, make a prototype on breadboard, do the programming and figure out how to cram the result into little black boxes.

For power I'm leaning towards three batteries and a boost board. I guess the next step is to get hold of one to play with...

Reply to
fungus

I looked at the datasheets for some TO-220s to compare with the surface mount MOSFETs on the little Sparkfun shield. The surface mount MOSFETS switching times are much faster (eg. 140ns->40ns for switch on time)

u

Yes, I saw those.

A 3.3V Arduino would struggle to switch normal FETs because the gate voltage is so high.

Reply to
fungus

Thinking a bit more...

The value for blue at 150mA was a bit lower then I expected. Now I think about it the battery was only putting out 3.88V so there wasn't much left over to play with.

The voltage adjustment on the base of the transistor would have to be very fine for it to work at all...lucky I had my mega-pot!

Reply to
fungus

--
But would have absolutely no problem switching BJT's.
Reply to
John Fields

:-)

I just ordered a couple of booster boards on ebay.

When they arrive I'll need to torture-test them to see how much current I get to play with...

Reply to
fungus

--- That doesn't matter since if you managed to get 150 mA through the LED, the voltage measurement you made across it was valid and the leftover 430 millivolts was dropped across the collector-to-emitter junction of the transistor, and wasted as heat.

Just for grins, how much?

Since the current through the transistor was 150mA and the voltage _not_ dropped across the LED was 0.43 volts, the power dissipated in the collector-to-emitter junction was:

P = IE = 0.15A * 0.43V = 64.5 milliwatts.

Hardly enough to make it flinch.

---

--- That 1k resistor between the wiper and the base of the transistor should have made finding the sweet spot easy.

Did you find any excessive sensitivity or hysteretic issues with the circuit?

-- JF

Reply to
John Fields

Yes, of course.

I'm just surprised that it worked so well down in the very-close-to-cutoff area. I would have expected it to be very sensitive to tiny changes there, but it wasn't.

The red LED is more risky, that was dissipating a quarter of a Watt at 150mA (1.67*0.15). I don't know the specs for a 2N2222 but I don't think it will be much more than that.

(update: I just checked and it's half a Watt so we were OK...!)

Nope.

Some of the adjustments were very fine though, I think it would have been tricky with a normal pot.

One other thought I had is that I should really do this with a couple more LEDs and take the average.

Reply to
fungus

--- Not a bad idea.

BTW, if you use this circuit with 5V from your booster, some interesting numbers come out:

. +5 R G B . | -+----+----+----+- . +---E1 E1,V 5.0 5.0 5.0 . | . [RS] E2,V 2.51 3.58 3.75 . | . +---E2 E3,V 0.3 0.3 0.3 . | . [LED] RS,R 18 9.1 8.2 . | . +---E3 I(RS),mA 138 156 152 . | . R1 C Q1 PD(RS),mW 344 222 183 .PWM>--[270]--B PN2222A . E PD(LED),mW 305 512 524 . | . GND PD(Q1),mW 58 64 63 PD(R1),mW 54 54 54

PD(TOTAL),mW 761 852 824

I used an 18 ohm resistor for the red LED in order to keep the current below 150mA, but 15 ohms would get you a little extra brightness at

166mA and increase the resistor's dissipation to 413 milliwatts.

-- JF

Reply to
John Fields

You ran the numbers? That's useful.

The bad news is it takes 500mA @ 5V to run it if I go with 150mA.

The booster is claimed to be 90% efficient "on average" but we'll see...

If we assume the booster is 80% efficient that's

846mA @ 3.6V - not going to happen according to the Duracell page.

OTOH it's software driven and I don't think all LEDs would ever be on at full power. I could even put a limiter in the code to keep it below a certain output power.

If I do that then rhe only way it would ever go to full power would be a program crash or a faulty Arduino. Maybe I could add a thermistor to the battery pack and cut the power if they overheat.

Reply to
fungus

Logic-level FETs are pretty commonplace. 3.3V isn't a problem.

Reply to
krw

--
500mA * 5V = 2.5 watts
Reply to
John Fields

Only when they're fresh...

The 1.5V from batteries is a bit of a myth. Batteries drop down to about 1.25V very quickly then go down slowly from there.

See graphs on this page:

formatting link

I figure they'll be down to about 3.6V after a few minutes and that puts the current draw on the borderline of what Alkalines can manage. They could overheat and die very quickly...

Reply to
fungus

--
So you're planning on running this thing with old batteries??? ;)
Reply to
John Fields

Yep.

...except that: a) It should never be on full power

b) The current being drawn is really under software control. With an Arduino I could actually measure the battery voltage and dim the LEDs as it drops.

If it turns out that it won't run at full power I can either add a failsafe mechanism (to prevent bad things happening in case of Arduino crashes) or drop the current to 100mA.

With a good failsafe mechanism I could even increase the maximum current per color and get extra brightness when only one LED is lit.

(This is the great thing about software...)

I need to get a boost board and see how efficient it really is under my conditions. Maybe they really are 90% efficient as claimed.

There's a couple in the post as I write this...

Reply to
fungus

Correct. The power rating is what can be dissipated over the full length of the wire in the pot. If you set the pot such that current flows through less than the full length of wire, then less power can be dissipated. For example, say you set the wiper at 1/2 the total resistance: P=I^2*(R/2) instead of P=I^2*R

Ed

Reply to
ehsjr

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.