Driving RGB LEDs with an Arduino

The next project I have in my head is to make a small gizmo with a big RGB LED which responds to sound.

It has to be battery powered and SMALL. I'm thinking of having two 3xAA battery boxes joined by a wire, one with batteries and the other with the control circuitry and a LED fixed to it.

It also has to be programmable so you can select colors, brightness, etc. on the fly. I'm thinking of using an Arduino Pro with add-on FET board to switch the LEDs with Arduino PWM output:

formatting link

The question is how to drive the LEDs?

I'm probably not going to run them at full power because of cooling and limitations on how much current the batteries can supply (I doubt they can supply an amp!)

If I can get 100-125mA per color that's probably enough.

If needed I could put in a little DC boost board to get an accurate starting voltage for driving the LED (eg. 5V).

So...

The datasheet for the LED I'm looking at is here:

formatting link

Would it be OK to rely on pure PWM to control the LED power? That's what the LED controller boards seem to be doing.

It says "max voltage 2.8" for red but I figure that's max continuous voltage. The example circuits they show with the LED in them are 12V with a controller board to limit the current. The boards seem to be using PWM.

nb. I'm more of a programmer then an electronics guy...

Reply to
fungus
Loading thread data ...

--
Yes, but with current limiting.
Reply to
John Fields

I was thinking a bit more about that...what if the Arduino crashes and switches everything on. Without any resistors it'll burn out, possibly overloading the batteries (I think battery current will be the limiting factor...)

Ok, that makes sense. I'm still getting my mind around this electronics thing... :-)

To drive it directly from the battery you'd probably need four AAs - depending on the voltage needed after the final calculation.

The other option is to put something like this in the box:

formatting link

Yep. That looks good, thanks!

I don't think there's any way to put the 330 ohm resistors into the Sparkfun board but I assume it just works as-is for switching things on/off.

The schematic for the board is on the product page:

formatting link

So ... hook one up with a potentiometer, dial "100mA" (carefully, don't fry the pot) and measure the voltage drop across the LED. Got it.

Reply to
fungus

--
That's why you use resistors in series with the LEDs to limit current.
Reply to
John Fields

Go here

formatting link
to determine how long your choice of batteries will last at the current loads you're talking about.

I don't think AA's will be adequate for very long.

John

Reply to
news

Yes, I understood that. At least you have a constant voltage to work with so you can calculate the current limiting LEDs properly.

No, I understood that. The 330 ohm resistor is to limit the current going from the Arduino output to the transistor.

(I'm unsure how you calculate the 330 ohms but I know why it's there...)

It would probably be bigger though...I need this to fit in a very small space (it has to go inside a musical instrument). The Arduino Pro Mini with one of those boards is *very* small.

If I start off with a high resistance and use my ten-turn wire pot I bet I can do it...it goes down to single Ohms.

I've got a multimeter and a very old (1970s) 'scope

Reply to
fungus

So...MOSFETS have high resistance from gate to source?

A BJT needs the resistor because from base to emitter it's basically a diode. Once you pass the breakdown voltage the resistance from base to emitter is more or less zero and things will get hot without a limiting resistor.

Reply to
fungus

The required collector current divided by the transistor's minimum current gain will dictate the required base current, which determines the maximum value for the base resistor. Above this value, you may not be able to obtain the required collector current.

The output voltage and maximum output current from the uC's logic pins will dictate the minimum value for the base resistor.

If the calculated minimum value ends up greater than the maximum, you need to use a transistor with more current gain or a FET.

Reply to
Nobody

t

I've been trying to educate myself on this today. This is the bit I was missing: A transistor needs a minimum amount of current to flow between base/emitter for it to work. I thought it was just voltage...

Best links:

formatting link
formatting link

MOSFETs seem to work like my previous idea of a transitor - only the voltage counts.

I didn't find a good "MOSFETS for dummies" page yet... they all launch off into substrate types and formulas before the end of the second sentence.

Reply to
fungus

--
Essentially infinite once you charge up the gate capacitance.
Reply to
John Fields

--
Oops...

Hit the send key too soon, please disregard.
Reply to
John Fields

--
OK.

Generally, in a common emitter switching circuit, one forces a beta of
ten in order to swamp out the vagaries between transistors.

That means that for every 100mA of collector-to-emitter current drawn
from the supply there will be 10mA through the base-to-emitter
junction.

Then, for 150mA of collector current there should be 15 mA of base
current.

With a 150mA load on the collector of the LED driver, and assuming the
Arduino outputs can get pretty close to the 5V rail when they go hot
means that with 15mA into the base of the driver, and with about a
0.5V drop across the b-e junction the base current limiting resistor
should be:

         5V - 0.5V
    R = ----------- = 300 ohms
           0.015A
Reply to
John Fields

Yes. I've been reading up some more and the thing people seem to worry about with MOSFETS is gate capacitance (the gate acts like a capacitor).

Seems that to get it to switch quickly you have to fill/drain the gate as fast as possible.

Reply to
fungus

An Arduino can source/sink 40mA on any pin.

In theory I don't even need the perfboard, the Mini Arduino has holes in the PCB for soldering wires to it.

formatting link

The transistors and resistors could go directly onto to the Arduino.

One other thing I was wondering: Is the actual transistor inside a TO-220 bigger than a (eg.) TO-92 or is it all just extra packaging to absorb heat?

Lifetime...if it can go for an hour that's probably enough. Colors will mostly be saturated (not white) so that's a maximum of two LEDs lit up, call it 250-300mA power draw for the whole thing. A 2500mA/h battery should be able to power it for quite a few hours.

OTOH the LEDs will only be at full power for short pulses. Most of the time they'll be under PWM control so that could easily double/triple the battery life (assuming the circuit is reasonably efficient).

It's 5K, 2W, one of these:

formatting link

I would have thought it could survive 100mA with no problems (hey it's MIL-spec!). Maybe I don't understand how the "2W" is calculated.

I looked in my box and I've got a few 2N2222s left over from something else I did.

I think the thing I understand _least_ about transistors is that there's so many different parts.

Seems to me that half a dozen well chosen variations should cover everything.

Reply to
fungus

--
Any I/O pin, I think, but why use more than necessary?
Reply to
John Fields

So the 2W is end-to end, not what can come out of the wiper thingy?

Yeah, but:

  • One which is really good at switching on/off
  • One which is quite linear
  • One which is more exponential
  • ...what else?

After that it's just maximum ratings and changing the external resistors.

I'll give it a go...

Reply to
fungus

D
l

ent

um

v=3Dw9cd7B5QRRo

If you like electronics, you should buy a copy of "The Art of Electronics" by Horowitz and Hill.

George H.

- Hide quoted text -

Reply to
George Herold

In general you don't want to push much current through the wiper of a pot. Though when used as a variable resistor you don't have a lot of choice.

George H.

Reply to
George Herold

The results are in, all components seem to have survived...

I measured the voltage drop on each color at three different currents, 100mA, 125mA and 150mA because I'm not sure what the final current will be yet.

\ 100mA 125mA 150mA

R 2.10V 2.16V 2.21V

G 3.04V 3.13V 3.28V

B 2.81V 3.23V 3.45V

The results fit the LED specs quite well. The rest of the math is easy now I have these numbers.

Thanks for the help!

Reply to
fungus

--
My pleasure! :-)
Reply to
John Fields

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.