# Controlling 10 high power LED with a Raspberry Pi

I'm trying to figure out how to control 10 Luxeon Rebel LED (700mA) from a Raspberry Pi. I want to be able to turn them on and off from code, but I don't need to have two or more LEDs turned on at once, always one LED at a time.

First of all, I don't know much about electronics, so that's why some questions might seems obvious. I did some research and before ordering all the parts I would like to know if I made mistakes.

I plan on using this BuckPuck Driver to drive the LEDs. I though that I could put the LEDs in parrallel, and use a 2N2222 transistor as a switch. Is that the best way to go ?

To find the value of the resistors R2, R4, R6, etc, I used the gain found on the datasheet (30), and the base emitter value (0.6V/1.2V). The GPIO of the Raspberry PI being 3,3V it's 3.3 - 0.7 = 2.6V and 23.3 mA = 111 Ω. Is that correct or do I misunderstand something ?

Do I need a resistor between the LED and the transistor, and if I need one, how do I found the value ?

Finaly, I would like to be able to dim the light using PWM, it seems to be feasible with the CTRL and REF pins of the BuckPuck, but I don't really understand how it works.

Here is a schematics showing only three LEDs (with 10 LEDs the image was too small).

simulate this circuit – Schematic created using CircuitLab

Thank you !

• In your schema you opted for 2N2222 NPN transistor, which won't stand the high current. In such cases I'd use a power transistor such as 2N2102 (Ic max=1A) in a TO-39 case or a BD139 (Ic max=1.5A, even safer) in a TO-126 case. Also note that the gain you selected is the minimal gain. The real gain is somewhere between that and the maximum value. It's usual to have 100 at least with such transistors. In this case, just replace the 100 ohms resistor with a 1K resistor. – user59864 Mar 2 '15 at 14:19
• Thanks, you're right ! If I use a 2N2102, what will be the value of the resistor (R2, R4, R6) ? 1k ? And with a BD139, do I need one ? – oks2024 Mar 2 '15 at 18:44
• I'd say don't care (too much) for that resistor value as it is not the one which will [should be designed to] determine the LED current. Give it a value high enough to limit the base current and low enough to have the transistor in a sustained ON state. 1K should be OK. You always need a resistor to limit current drawn from the digital output (remember the emitter-base junction behaves like a forward-biased diode). – user59864 Mar 3 '15 at 8:34

The BuckPuck is a step-down ("buck") converter. You must provide it with a voltage at least 2.5V above the forward voltage of the LEDs. The LED has a typical Vf of 3.2V, so you want your input voltage to be at least 5.7V. Call it 6V or higher. The BuckPuck will take an input voltage all the way up to 32VDC, although the efficiency drops a bit.

It is regulated to provide constant current. In other words, the BuckPuck will vary its output voltage so that the current remains the same. The buckpuck doesn't care if you have one or three LEDs in series, it will simply create whatever voltage necessary to push 700mA through the circuit. Of course, this output voltage cannot be greater than 2.5V less than the input voltage.

Because of this, you don't need any limiting resistors in the LED paths. This also means that you want to select your FETs (or transistors) to have small resistances when switched on ( $R_{ds-on}$ in the datasheets)

However, this presents a problem in your multiple-path design. If you turn off one of the LEDs before turning on another, then there is nowhere for the current to go. The output voltage will shoot up to the maximum possible, as the BuckPuck tries to keep pushing 700mA.

A solution is to turn on one of the LEDs just before turning off another one. MOSFETs take time to turn on and turn off, so you may need to add a delay in your code to ensure that there is always a current path available.

As for as PWM dimming, basically you just switch the CTRL pin on and off fairly rapidly. The datasheet says that you need to keep the PWM frequency under 10kHz. I would keep it down to around 1kHz, or even slower. What you're doing is turning the LED on and off faster than the eye can detect. What you end up seeing is the average brightness.

However, you can only do this directly if you have 5V logic outputs. The RPi has 3.3V outputs. The datasheet gives the following examples, which won't work for you because you don't have 5V logic:

Read Page 4 of the datasheet very carefully. Also note that the microcontroller ground (the RPi ground) is tied to LED-.

Conveniently, the REF pin provides 5V for your use. You need to switch this 5V into the CTRL pin. One option is to use a small optoisolator (optocoupler), such as the Sharp PC713V0YSZXF.

If you don't know how to use an optoisolator, I would look for answers here :)

Good luck.

• Thanks, I understand more clearly the role of the BuckPuck, and how the PWM works. And for the Rds−on value, it's only for the FETs, right ? I don't find this value on NPN transistors datasheets. I still have trouble to find the right components. I'm glad you point out that it will be an issue if al the light are off at the same time. As you said I'll make sure to turn one on and the turn off the previous one. – oks2024 Mar 3 '15 at 5:01
• @oks2024 Glad it made sense :) Yes, you're right that $R_{dson}$ is for FETs only; sorry I didn't mention that. A FET, when turned on, looks like a small resistor. A BJT ("Bipolar Junction Transistor") has a specific voltage drop, instead. For a NPN, this is called $V_{CE(sat)}$ A FET is much better for power-switching applications. – bitsmack Mar 3 '15 at 5:12
• I did some researches on MOSFET but I'm not sure I fully understand the datasheets yet. Can I use a FDN337N link for example ? – oks2024 Mar 4 '15 at 2:30
• @oks2024 Yes, that would be an excellent FET for your purposes. The $V_{GS}$ of 30V will ensure that the FETs won't fail even if you turn off all the LEDs at once. The low $V_{GS-ON}$ will allow your 3.3V logic to fully activate the FETs. One problem, though, is that this specific FET is really small. If you don't have a lot of soldering experience, it'll be hard to use. A comparable FET in a larger package would be one like this, although there may be preferable ones out there. (This one isn't cheap...) – bitsmack Mar 4 '15 at 7:56

The driver you have is a constant current driver, and checking its datasheet it should work OK for driving individual LEDs provided that you meet the requirement that the input voltage is 2.5V higher than the nominal forward voltage of the LEDs. You don't need a resistor in series with the LEDs in this case.

The datasheet doesn't make it clear whether LED- is the same as ground, and I suspect it isn't quite the same - there will be a small shunt resistor in there measuring the current.

Bipolar transistors aren't ideal for this high level of current, I would choose FETs for this. Possibly with a 3.3V -> 5V high power buffer from the GPIO to act as a FET driver.

Edit: was going to suggest a FET but too much choice. You want something with logic level drive and reasonable current handling. Probably in a TO-251 package.

• Thanks for your answer. Sorry for the beginner's question, but what are the main differences between transistors and FET ? – oks2024 Mar 2 '15 at 18:45
• Bipolar transistors are current amplifiers: you put a current through the base-emitter and get roughly 50-300 times through collector-emitter. FETs are more like a gate-voltage-sensitive resistor where "on" is a few tens miliohms. Either way you need something larger than a 2n2222. – pjc50 Mar 2 '15 at 20:27