As I said in the title, I'm looking for a transistor that I could use for switching a Raspberry Pi 5v. fan. The Pi is in an unventilated case, which makes it heat up to 70°C while I would prefer maintaining a cooler temperature of ~45°C. So I'm using a small fan that works perfectly, but is quite noisy when at full load. Because the fan is mounted inside the case, I would have to manually open the case then unplug the fan to stop it. That's why I would prefer being able to control it with a GPIO pin (which is completely doable, I've seen a lot of tutorials about that).

The problem is that the GPIO pin aren't powerful enough to drive the fan (plus it would be dangerous for the Pi itself). So I need to have a transistor acting as a switch controlling the fan power.

I actually have some transistors at hand, but I'm not sure if they are suitable for this use, nor which one of them would fit the best. I'dbe glad if you could help me picking the best transistor, preferably within the ones I already have.

The transistors I have (several pieces in each case) :

The fan is a 1.5cm 2 pins fan running on 5V DC, 0.12A. I would like to control it using one GPIO pin, which delivers 3.3V.

Thanks in advance for your help !

[IMPORTANT EDIT] After having searched in my electronical stuff, I discovered that I have a bunch of BC107B transistors (Datasheet), which are NPNs, so the problem is kinda fixed now.

I did some tests with one of them, and at this point, it seems to work perfectly. I can even use PWM to control the speed of the fan. However, before atempting to make anything definitive, I would appreciate if you could tell me if I did everything correctly (ie,i'm not going to damage my Pi).

  • Here is the circuit I made (extremely simple, maybe too much) :


simulate this circuit – Schematic created using CircuitLab

  • Can you confirm that the BC107B is suitable for this use ? (I suppose yes, but anyway, I'm not 100% sure that I'm able to understand correctly all the datasheet)
  • Could I use a small capacitor in parallel with the fan to smooth its power when using PWM ?
  • \$\begingroup\$ While there are NPN transistors that can work for this relatively low current fan, generally load switching is best done using an NFET. The best choices are SMT but the TO-220 packaged irlb8721pbf while far more capable than needed is what DIY project Arduino/Pi vendors like Adafruit chose to offer in this category. You could also consider a fan with a PWM control input. \$\endgroup\$ Jun 13, 2018 at 19:10
  • \$\begingroup\$ Thank you for that really quick answer ! Unfortunately, I would prefer (if possible) using the stuff I already have, unless all of them aren't suitable for that use. But if none of them fits the needs, I might consider buying one of those IRLB8721PBF, or even a S8050 (someone advised me to use S8050s for that). Can you explain me a bit more why the transistors I mentionned in OP aren't best for that use ? Sorry but I'm still a (passionated) newbie in electronics \$\endgroup\$
    – HerrCrazi
    Jun 13, 2018 at 19:17
  • 2
    \$\begingroup\$ These are PNP transistors and small signal JFETs. The PNPs give you a headache because you have to level-shift from +3.3V to +5V and exactly that isn't easy with a PNP (it would be easy from -3.3V to -5V) and the JFETs you have don't allow the needed current. \$\endgroup\$
    – Janka
    Jun 13, 2018 at 19:38
  • \$\begingroup\$ Uhm I see... I'm gonna consider buying an IRLB8721PBF then. Should I mount it exactly like a standard NPN transistor ? Also (I may seem annoying, sry :/) but why is it painful to level-shift from 3.3 to 5V using a PNP transistor ? \$\endgroup\$
    – HerrCrazi
    Jun 13, 2018 at 21:18
  • \$\begingroup\$ Just a remark, 70°C is a perfectly fine temperature for a CPU, and you can probably drop it to 60°C by simply gluing a small patch of copper or aluminium on it. \$\endgroup\$ Jun 15, 2018 at 12:51

1 Answer 1


I thought your question was pretty well-framed. You have PNP BJTs, it seems, but no NPNs? Not so good. But it can be done. At least, I think so. The main worry I have is that a single I/O pin might have to sink some significant current. But I think the Pi can safely handle perhaps \$15\:\text{mA}\$ on a single I/O pin. So perhaps it is okay.

Here's the simple circuit to try:


simulate this circuit – Schematic created using CircuitLab

The basic idea is:

  1. When the I/O pin is LOW, it can sink enough current to include the needed base current for \$Q_1\$ (plus whatever \$R_1\$ is supplying, then.)
  2. When the I/O pin is HIGH, it still sinks some current but only the current needed for \$R_1\$ because there won't be enough voltage for the base-emitter of \$Q_1\$ to activate it.

In general, if the base-emitter voltage falls below about \$V_{\text{BE}_\text{OFF}}\le 500\:\text{mV}\$, \$Q_1\$ will be turned off. So that's the goal for turning off the load. And for the \$120\:\text{mA}\$ you are considering for \$Q_1\$ when turned on, I'd want a base current of at least \$I_{\text{B}_\text{ON}}=6\:\text{mA}\$ and also a base-emitter voltage that is at least \$V_{\text{BE}_\text{ON}}\ge 800\:\text{mV}\$.

(Now, this is a bit of a compromise. I'd prefer still more base current. But, unfortunately, I'm also trapped by some limits for your I/O pin. So this is one of those compromise decisions that are sometimes required to balance competing issues.)

There is another worry to deal with. The I/O pin itself has some resistance. I find that assuming \$100\:\Omega\$ is conservative enough for most circumstances. (You could measure it, too.) Often, it's lower than that, but sometimes it may be a little higher. So that's the number I'm going with.

This provides two equations and two unknowns (the resistors.)

$$\begin{align*} \left(I_{\text{B}_\text{ON}}+\frac{5.0\:\text{V}}{R_1}\right)\cdot\left(R_1\:\vert\vert \:R_2\right)&\le 5.0\:\text{V}-V_{\text{BE}_\text{ON}}\\\\ \frac{3.3\:\text{V}\cdot R_1+5.0\:\text{V}\cdot R_2}{R_1+R_2}&\ge 5.0\:\text{V}-V_{\text{BE}_\text{OFF}} \end{align*}$$

Once I solve for \$R_2\$, I then have to subtract off the I/O pin resistance. So from that fact, I arrived at the given resistor values above. The peak current required from your I/O pin is about \$11\:\text{mA}\$ and all the power dissipation figures work out to reasonable values. So it probably will be fine, as shown.

In case it helps, here are the resulting equations. I'll use \$V_\text{CC}=3.3\:\text{V}\$ and \$V_\text{DD}=5.0\:\text{V}\$ for these purposes. Then, highlighting the common factor on the left:

$$\begin{align*} R_1&=\left\{\frac{V_{\text{BE}_\text{ON}}}{I_{\text{B}_\text{ON}}}\left[V_\text{CC}-V_\text{DD}\left(1-\frac{V_{\text{BE}_\text{OFF}}}{V_{\text{BE}_\text{ON}}}\right)\right]\right\}\cdot\frac{1}{V_\text{DD}-V_\text{CC}-V_{\text{BE}_\text{OFF}}}\\\\ R_2&=\left\{\frac{V_{\text{BE}_\text{ON}}}{I_{\text{B}_\text{ON}}}\left[V_\text{CC}-V_\text{DD}\left(1-\frac{V_{\text{BE}_\text{OFF}}}{V_{\text{BE}_\text{ON}}}\right)\right]\right\}\cdot\frac{1}{V_{\text{BE}_\text{OFF}}} \end{align*}$$

We could take this one more step and add another PNP BJT to the chain and operate it similarly, as above, except that the first BJT (nearest the I/O pin) would serve to short-out the following BJT to turn it off. And this would relieve the I/O pin of some of the drive current requirements above.

Something on the order of this:


simulate this circuit

The earlier equations can be used to compute the values for \$R_3\$ and \$R_4\$ in this new circuit, where this time \$I_{\text{B}_\text{ON}}\approx 500\:\mu\text{A}\$, perhaps? (Because the load now is perhaps at worst under \$10\:\text{mA}\$.) \$R_2\$ then just has to be sufficient to turn \$Q_1\$ on and \$R_1\$ is more of a pull-up now and much less critical in value.

I/O pin current will now be a lot less. Probably under \$1\:\text{mA}\$.

  • \$\begingroup\$ Thank you very much for this great answer ! I'm still trying to understand the maths you did. Must the values of these resistors be exactly as you said, or would it be possible to use only one of them ? There isn't much room into the case, so the smaller the circuit will be, the better it will be. \$\endgroup\$
    – HerrCrazi
    Jun 14, 2018 at 16:56
  • \$\begingroup\$ @HerrCrazi If you use the first circuit, the values are both important. In the second circuit case R2, R3 and R4 are important. But R1 can be most anything that is as large as or larger than 1k or so. The math I chose could use more explanation. But it would help to know what you think you follow, already, because that could save me time. \$\endgroup\$
    – jonk
    Jun 14, 2018 at 17:29
  • \$\begingroup\$ I think at that point I understood almost everything you explained me. Theres still some small details I barely understand, but I'm sure I'll understand them as soon as I'll take the time to retry doing the math on my own (which is actually the best way to understand something). Once again, thanks a lot for you help ! \$\endgroup\$
    – HerrCrazi
    Jun 14, 2018 at 18:19
  • \$\begingroup\$ Edit I just found NPN transistors, so I think I'll be using them instead. I edited the OP. \$\endgroup\$
    – HerrCrazi
    Jun 14, 2018 at 18:44
  • \$\begingroup\$ @HerrCrazi Well, that makes things lots easier. The BC107B, if from ST, may be a very slight worry on thermal: I see 500 C/W. So perhaps 15 C rise over ambient? But that's probably okay. It's max collector current is 200mA, so you are pushing that spec a bit. But it is all worth a try. What's the worst? You buy another one. But I think it will work. You'll need a a lot of base current, so use a base resistor of ... 270 or 330 or 390 Ohms. See how that works out. \$\endgroup\$
    – jonk
    Jun 14, 2018 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.