ezhu002
Posts: 3
Joined: Sat Mar 08, 2014 1:50 am

Using 2n2222a as a switch for IR LEDs

Sat Mar 08, 2014 2:38 am

Hello,

I am trying to connect a IR LED to my Raspberry Pi with a 2n2222a transistor as a switch.

Here is the IR LED I have:
http://www.amazon.com/Gino-Round-Board- ... rds=ir+led

Here is the schematic I am thinking of using:
schematic.PNG
schematic.PNG (62.96 KiB) Viewed 7822 times
The IR LED requires a 12 V source and draws 300 mA. I'm not sure what are safe values for R1 and R2. I also read somewhere that I may need a diode to prevent current from flowing backwards, but I'm not sure what kind of diode to use or where to place it.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Using 2n2222a as a switch for IR LEDs

Sat Mar 08, 2014 10:46 am

My reading of that Amazon page is that device is meant to be supplied with 12v - whether it has built-in current-limiting resistors, or something more complicated, isn't obvious.
So in your diagram, R2 isn't necessary

From the data-sheet for the transistor, the current gain at 300mA collector current would be somewhere between 30 and 100.
That means the base current will need to be in the region of 10mA

With the Pi's GPIO giving 3.3v, and the transistor's base-emitter voltage around 0.7v, there'll be ~2.6v across R1
At 10ma and 2.6v, R1 should be 260Ω. Something like 200Ω or 220Ω would work.
...I may need a diode to prevent current from flowing backwards...
That's recommended when you're driving a coil, or similar - something that stores energy in a magnetic field, or in a moving mass such as a motor
When the current through a coil is switched off, the energy has to go somewhere. Without the diode, it usually goes where you don't want it, and destroys something.
The diode allows current to keep flowing, and wastes the energy as heat.

You're not storing energy, so you don't need a diode.

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Using 2n2222a as a switch for IR LEDs

Sat Mar 08, 2014 11:13 am

Wouldn't a pull-down resistor between the base and emitter (say, 100kΩ) be a good idea incase the GPIO pin is running in a floating non-driven state at some point?
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Using 2n2222a as a switch for IR LEDs

Sat Mar 08, 2014 6:25 pm

Possibly. Though 100k may be a bit high.

If the GPIO is set to input, unless pull-ups are enabled, no current can flow from it, so no current can flow into the base, so there should be no collector current.
If the pull-up is enabled, it's equivalent to a 50k resistor. Ohm's law says that will give (2.6/50)mA = 52uA into the base. With a gain of 100, that'll give a collector current of 5mA, so wasting 60mW from the 12v supply.

Actually, I'd put a 10k resistor from base to emitter. That means about 60uA is needed before the transistor begins to turn on. The rest of the 10mA goes into the base.
Putting it from the GPIO pin to ground means 330uA flows through it - an extra 270uA without any benefit.

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Using 2n2222a as a switch for IR LEDs

Sat Mar 08, 2014 7:02 pm

Yes. 10kΩ does sound more sensible under the circumstances. I wasn't aware of the internal pull-up value so took a wild guess. :)
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

ezhu002
Posts: 3
Joined: Sat Mar 08, 2014 1:50 am

Re: Using 2n2222a as a switch for IR LEDs

Mon Mar 10, 2014 5:59 am

Thanks so much!

I will test the setup sometime this week and update with results.

IanH2
Posts: 79
Joined: Tue Dec 18, 2012 10:17 am

Re: Using 2n2222a as a switch for IR LEDs

Thu Mar 13, 2014 11:11 am

I'd be a bit concerned that 10mA from a GPIO pin and 300mA collector current is towards the high end of what the BCM2835 and 2N2222 can take; the transistor in particular is going to get hot and may not live very long.

I would use a power MOSFET instead of a bipolar transistor - e.g. the FQP30N06L or RFP30N06LE (who comes up with these names?) will switch 10A or more with a simple 3V logic signal. Sparkfun and Cool Components both do a simple board with one on. Wiring it up couldn't be easier - see e.g. http://www.elinux.org/RPi_GPIO_Interfac ... sing_a_FET
-----
https://github.com/IanHarvey

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Using 2n2222a as a switch for IR LEDs

Thu Mar 13, 2014 11:24 am

IanH2 wrote:I'd be a bit concerned that 10mA from a GPIO pin and 300mA collector current is towards the high end of what the BCM2835 and 2N2222 can take; the transistor in particular is going to get hot and may not live very long.
It works out at around two-thirds of the maximum safe recommended current for the GPIO pin and around one-third of the maximum rated power dissipation for a typical 2N2222A, so it should be fine. A suitable MOSFET would be the better option though.
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

ezhu002
Posts: 3
Joined: Sat Mar 08, 2014 1:50 am

Re: Using 2n2222a as a switch for IR LEDs

Tue Mar 18, 2014 4:01 am

I finally got to testing out the circuit. Unfortunately, I can only use a 2n2222a because of time constraints of the project, but I'll definitely keep that in mind.

I used a 220 resistor for R1 and got rid of R2. Everything worked as intended.

Thanks all for your help and comments!

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Using 2n2222a as a switch for IR LEDs

Tue Mar 18, 2014 2:20 pm

2N2222 is not suitable. you will need more base current than what the Pi can deliver to drive 300mA load. The base-emitter voltage drop will be about 1V, and you need over 20mA base current to avoid that the transistor overheats because it goes out of saturation.
A better choice is an n-channel MOSFET that has the ON-resistance specified at 2.5V gate voltage. the MOSFET is driven by a voltage instead of a current.

Examples in SOT-23 package:
Si2302CDS, Si2312CDS,PMV16UN,DMG3414U,DMN2075U
use a 1k resistor in series with the gate to reduce current spikes in the GPIO pin because of the gate capacitance.

Return to “Interfacing (DSI, CSI, I2C, etc.)”