Maker Pro
Maker Pro

How do I choose a power transitor to switch a PC fan on?

apples

Jul 1, 2012
97
Joined
Jul 1, 2012
Messages
97
I have just started playing with my arduino for the first time. I want to switch on a pc fan with it.

The arduino output pin is 5V and can supply 40ma.

My PC fan runs off 12V and needs 0.24A

So a transitor has C,B,E

I need to flow from C to E 12volts at 240ma to run the fan.

The B to E I have available only 5v at 40ma.

Are these the only two things I need to consider for using a transistor in this example?

So would I need to find a transistor that does not draw more than 40ma through it's BE circuit? otherwise it will blow the output pin on the arduino?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
You're close. You need to LIMIT the current that the transistor's base-emitter junction draws from the Arduino, using a current limiting resistor between the Arduino output and the base.

Beyond that, you need to use an NPN transistor with its emitter grounded - connected to the Arduino's ground AND the negative side of the 12V power source you're using for your fan.

The fan connects between the positive side of the fan's power supply and the collector of the transistor. When the Arduino drives its output electrically HIGH, this will cause current flow through the current limiting resistor and the transistor's base-emitter junction, which will turn the transistor ON.

When you turn the transistor ON, current can flow from its collector to its emitter, completing the circuit from the fan power supply positive, through the fan, through the transistor, and back to the fan power supply negative.

For general purpose switching applications, when the transistor is ON, it should be SATURATED, which means that there is a lot more base current than you would calculate by dividing the collector current by the current gain of the transistor. This ensures the transistor is fully switched ON regardless of component variations, and forces it to pull its collector down hard, so there will be little voltage (typically around 0.2~0.5V) across the transistor's collector-emitter, leaving almost all of the 12V available for the fan.

A typical NPN rated around 500 mA (e.g. the 2N4401, BC337, MPSA/PN2222) has a current gain of at least 100, so a 240 mA collector current requires 2.4 mA base current, but to saturate the transistor you multiply that by AT LEAST 2, often as much as 5. So the base current needs to be 4.8~12 mA.

The base current is set by the current limiting resistor. You first need to calculate the voltage across this resistor when the Arduino output is HIGH. Assuming the Arduino is running at 5V, the resistor will have close to 5V on one end. The other end will have the forward voltage of the transistor's base-emitter junction on it, which can be estimated as around 0.7V for a silicon, non-Darlington transistor.

So the voltage across the resistor will be around 4V. You use Ohm's law, I = V / R rearranged to R = V / I to calculate the resistance. V is 4V and I is 0.0048~0.012 amps, so R is somewhere between 333 and 833 ohms. Lower value gives a more saturated transistor, which is desirable, but wastes a bit of current. I would go for a 470 ohm resistor, or choose a suitable value that's used elsewhere in the circuit if applicable.

Edit:

The current gain of a bipolar transistor actually depends significantly on the temperature, and the amount of collector current. Data sheets for transistors that are designed for this application should have graphs showing how the typical current gain varies with these parameters, from which you can estimate the base current required, or you can just play it safe and drive the base with ten or more times the calculated current. But when the collector current is 240 mA that could be quite a lot of base current.

A more general solution is to use an N-channel MOSFET, connected the same way as the transistor. These don't draw any (significant) current from the Arduino, although a series resistor is still recommended for several reasons. No voltage is dropped across this resistor, so the MOSFET gate sees the full voltage from the Arduino.

MOSFETs are saturated by gate voltage, not by current. 5V is not enough to fully saturate most MOSFETs, except for types with "logic-level gate threshold". These often have an L at the end of the part number. The BS170 is a common low-power switching MOSFET rated for 500 mA drain current and would be a good choice, except that at 5V gate voltage it is not sufficiently saturated. You would have to use a MOSFET with a logic threshold and/or a higher current capability.

I found one - the Fairchild FQPF13N06L. It's rated at 10 amps maximum drain current and comes in a TO220 package so it's overkill, but at USD 1.30 for one-off quantity, still cheap enough if you're not doing a production run. MOSFETs are static-sensitive though, so you need to handle them properly. Its drain-source resistance is around 0.1 ohms, so at 240 mA it will only drop 24 mV across it, instead of 200~500 mV for a transistor.

If your Arduino is running at less than 5V (for example 3.3V) then you're less likely to find a MOSFET that will do what you want.

Another possibility is a Darlington transistor. This consists of two normal bipolar transistors connected together such that their current gains multiply together. A typical example is the MPSA14 which is rated for 500 mA collector current and has so much gain that your current limiting resistor can be as high as 10 kilohms, so very little current is wasted that way. The drawback with Darlingtons is that the collector-emitter voltage is higher - typically around 1V for your application, so your load will only see 11V of the 12V available.

These are all the simple alternatives, using a single device that is driven directly from the Arduino. There are other options using more than one active device, that will eliminate all of these problems. For example you can use a transistor or small MOSFET to translate your 0V/5V signal from the Arduino into a 0V/12V swing, which can drive the gate of a MOSFET and fully saturate it. Ask if you want more information.
 
Last edited:

CocaCola

Apr 7, 2012
3,635
Joined
Apr 7, 2012
Messages
3,635
Kris I just want to point out that, that one one of the better explanations of how to calculate the limiting resistor I have come across... A nice straight forward and simple explanation...

BTW

or choose a suitable value that's used elsewhere in the circuit if applicable.

That is how I usually choose :) I even have a tendency to tweak circuits so that I can stick to nice resistor groups...
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Thanks :)

That is how I usually choose :) I even have a tendency to tweak circuits so that I can stick to nice resistor groups...

Likewise. It's helpful to do this when you're designing circuits for manufacture, since every extra reel of SMD resistors is an extra thing to be loaded into the placement machine.

With the circuits I've designed since I've been posting here, I've been trying to stick with multiples of 10 and 33, or 10/22/47. At least for resistors and capacitors.
 

apples

Jul 1, 2012
97
Joined
Jul 1, 2012
Messages
97
Transistor and pull down resistor?

Just confirming something here.

I was connecting up a transistor as a switch to control a 12v fan. As I was hooking it up and the 12 v was connected, the fan started spinning. I thought that I had done something wrong. But think that the base connection was floating. As when I touched the pcb and the solder joints the fan speed would change erratically.

So I put a 10k resistor between the base and ground, which seems to have stopped the issue.

Does all this sound about right?
 

CocaCola

Apr 7, 2012
3,635
Joined
Apr 7, 2012
Messages
3,635
First off there is no reason to start a new topic for the same project... [threads have been merged -- (*Steve*)]

https://www.electronicspoint.com/do-choose-power-transitor-switch-pc-fan-t252464.html

Second have you double checked to make sure the emitter/collector are not reversed? With the base floating and the emitter/collector reversed you can expect it to behave like this more so than if it's connected properly... But, the short of it is yes, this leak can happen when the base is floating...
 
Last edited by a moderator:

apples

Jul 1, 2012
97
Joined
Jul 1, 2012
Messages
97
The Collector to Emitter looks good. So It must have been just that floating base. Just goes to show how important those pull down or pull up resistors are hey. Quite happy that this happened in such a visual way where I could see it happen.
 
Top