# Using 25 IR LEDs with Raspberry Pi and Transistor

Using a Raspberry Pi and 5V I want to use 25 IR LEDs (5mm LED, 940nm wavelength, 20 degree beam width, 100 mA continuous, 1000 mA pulse, Approx 1.6V forward voltage; http://www.exp-tech.de/super-bright-5mm-ir-led-25-pack) in parallel using 8 pairs of 3 LEDs each pair with a 2 ohm resistor and one single LED with a 36 ohm resistor.

This tutorial is my basis: https://www.sparkfun.com/news/1396

You can see that in this tutorial a npn transistor is used with a resistor R6 of 330 ohm.

I've ordered this PN2222 transistor (http://www.exp-tech.de/npn-bipolar-transistors-pn2222-10-pack).

My question is, once I have all LEDs and their resistors (2 and 36 ohm) in place, how would I need to install the transistor(s) and how would I calculate the R6 resistor for my example?

Update 1:
Here is the LED datahseet: http://www.adafruit.com/datasheets/IR333_A_datasheet.pdf They are just turning on/off all at once. For my project I would need to get enough IR light in order to brighten up a whole room of 15 and up to 35 square meters, if less LEDs will produce enough IR light, I'm happy with it. For video recording a Raspberry Pi NoIR Camera will be used. The system will be time-controlled, the LEDs are supposed to run probably 4-5 hours for each time-frame. @KyranF: You're right that I was not aware fo this as this is acutally my first project including more than one LED.

Here is a first try to visualize the solution.

Does this setup with the mentioned LEDs and a MOSFET sense? Do you think 14 LEDs of this kind would be enough in order to brighten up a whole room?

Update 2:
This is my current set-up, which seems to be wrong as well. I'm not getting the IR LEDs to lighten up.

Important hint: I'm using 33 ohm resistors for the LEDs as the LEDs I've finally bought are using 50mA instead of 100mA as the ones listed before. Here is the new Datasheet

My Python code looks like this:

import RPi.GPIO as GPIO ## Import GPIO library
import time ## Import 'time' library. Allows us to use 'sleep'
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO 4 Pin 7 to OUT
GPIO.output(7,True) ## Turn on GPIO 4 pin 7
time.sleep(5)## Wait
GPIO.output(7,False)## Switch off pin 7


The wiring looks like this:

Here is an overview of the GPIO setup:

• Are they just turning on/off? All at once? or individual control? I guess i'll read the tutorial quickly too.. – KyranF Dec 19 '14 at 8:33
• The tutorial shown runs 13 IR LEDs with only 10mA current on each, using 5 chains. That's only 50mA. You are trying to do 8 chains of 3, with one extra making a total of 25 LEDs? at 100mA each string? That's almost 1A, that is ridiculously powerful in comparison. Your transistor as Andy pointed out is not rated for that, especially that tiny TO-92 package. – KyranF Dec 19 '14 at 8:43

## 2 Answers

I suggest you get a better current rated transistor, or even a good old MOSFET (much better, you don't have enough voltage headroom to use the transistor properly anyway.. who knows how the sparkfun guy got stuff to work at all). For what you want to do, get a 2-3A rated MOSFET, or at the very least a 1.5A+ rated NPN transistor.

It is not a good idea to operate 3 LEDs at 1.6-1.8V on 5V, and expect a 2Ohm resistor to regulate current properly. The variation in forward voltage is too much, and having such a small resistance (also with poor tolerance) you will not get very good results.

I suggest you use 2 LEDs in series on each chain, and use a larger resistor. To get 100mA out of 1.4V spare (3.6V out of 5V is taken up by 2 LED in series) you need about 14 Ohms, which is surely better than 2 in terms of leeway for tolerance. The other thing is, both 2 and 14 ohms are unusual/non standard values, you might need to find a nearest standard value. Also remember your LEDs should only be on for the picture, for a short period of time, so it's not actually that bad if your LEDs run slightly over-current.

The LEDs used by the Sparkfun tutorial are 1.6-1.8V x 10mA, meaning they are only really 18mW each, and there are 13 LEDs. That is 13 x 18mW = 234mW total of IR light. You are trying to do 25 LEDs at 1.6-1.8V x 100mA, meaning your IR light output will be a ridiculous 4.5 Watts. Do you really want x20 more IR light than the tutorial guy had? I don't think you really thought about any of this..

The basics for calculating R6 in your case is if you do end up using a NPN transistor, the base current into the transistor is determines how much current flows through it. Your LEDs do the current limiting, so there is no real reason to even use a transistor (which effectively act as current-amplifying switches). The correct component for this digital on/off functionality is an N Channel MOSFET. Both should have a base/gate resistor though, but the MOSFET one is almost not needed, rather it's recommended. It can be something simple like 100 Ohms.

The base resistor for a transistor allows you to control current through the collector-emitter using the DC current gain/beta factor of the transistor, usually shown on the datasheet. If you have a gain of 100, it means 1ma into the base will allow 100mA through the emitter-collector. Problem is, as the base current approaches saturation, the current gain drops dramatically until it is quite low, like 10 or so. This is different for each transistor however. If you put 40mA into the base, it will probably saturate, causing the transistor to act more like a switch with minimal forward voltage drop, which is what you would want to happen in this LED driving application.

UPDATE: based on the feedback from OP, I have provided the below diagram to show the correct way to hook up the IR LEDs, with a low-side NFET power switch. Note the FET should have a "logic level" gate drive voltage, around 2V threshold should be good for 3.3V control. The FET should also be rated for 3+ Amps. I believe it was worked out to be about 800-900mA continuous, for 4-5 hours in this user-case scenario.

simulate this circuit – Schematic created using CircuitLab

• A quibble : multiplying volts times amps gives you electrical power, not IR power. For that you need to multiply by the efficiency (technically, the luminous efficacy). For LEDs running continuously that's usually in the 20 - 35% range. So the proposed illuminator might be expect to put out ~ 1 watt of IR. And while the thrust of your criticism about relative powers is certainly valid, without knowing the relative efficiencies of the two LED types, your relative number could be off by nearly a factor of 2 either way. Just a quibble. – WhatRoughBeast Dec 19 '14 at 9:24
• @WhatRoughBeast my specialty is LEDs, I understand all that. The difference in "power" is still huge, even if the irradiance may not be the same per watt (aka, efficacy), because the LEDs are different products. The difference is huge, the number of LEDs is close to doubled, and the power power of each LED is x5 more than those used in the tutorial. It seems the OP does not recognize this, so they may be in for a shock when their IR picture comes out completely white/overexposed/huge specular reflection from the plants. – KyranF Dec 19 '14 at 9:27
• whoops "power power" haha, typo. And the power of the LEDs are pretty much x10 not just x5, seeing as the resistors used in the tutorial allow for 10mA through the LED chain, whereas the OP wants 100mA through their chain - and the LEDs have similar forward voltage drops (basically all IR LEDs have approximately the same) – KyranF Dec 19 '14 at 9:43
• @KyranF: I've updated my post. Do you think this solution is feasable? – Daniel Dec 22 '14 at 10:54
• @Daniel ok, so you will do video recording not single-shot timelapse recordings. This is an issue, as your power supply must be a good one (preferablly wall/mains powered, not battery operated). Your schematic is wrong too, as your LED's do not actually show a supply input. You've wired up the NFET wrong, because of this. I will update my answer to show a simplified diagram, that only shows 1 chain of LED, you just 'copy paste' to add more in parallel, if you know what I mean. – KyranF Dec 22 '14 at 21:17

6 banks of 3 series LEDs is 6 x 100mA and the extra led takes another 100mA and you are already in excess of the absolute maximum current that is specified for the PN2222 transistor you have ordered.

There's also another problem - you can't rely on the forward volt drop of the LEDs being exactly 1.6 volts - some might be 1.5 volts and some might be 1.7 volts - I didn't see any link to a data sheet so I suggest you do some more homework on this and find out how the forward volt drop of the LEDs is affected when they get warmer (due to the 100mA current).

You probably will need a better circuit of higher voltage power supply with more LEDs in series.