I'm trying to control a dc fan with a Raspberry Pi 3 and I'm using a NPN transistor (BC547) to switch the fan on and off.

The schematics I found called for a PNP transistor with a 1k resistor on the base. I left the resistor but used a NPN transistor instead because that's what I had lying around.

This resembles my setup:

with resistor

The Raspberry outputs 5v (red wire) and 3.3v on the gpio pin (blue wire in picture). (Don't think I need so say this, but ground is black.)

The fan didn't start so I hooked up a multi-meter where the fan should be and I measured 5.6 volts. As a test I then replaced the fan with a 5v led I have and it worked as expected. Still, the fan wouldn't start when I replaced the led with the fan again.

I don't seem to remember using a resistor on the base when I used these years ago (it's been a while since I last messed with these) so I removed the resistor and the fan worked! So now my setup is like this:

without resistor

I'm confused as to why only the fan doesn't work with the resistor on the base of the transistor. Can somebody explain why?

  • 4
    \$\begingroup\$ Draw a proper schematic. I doubt anyone's going to read those mickey mouse drawings and they don't show the transistor pinout anyway. \$\endgroup\$ Dec 30 '17 at 23:49
  • 5
    \$\begingroup\$ 1. Fritzing can produce schematic diagrams. Many people here will vote to close your question since all you have posted is a wiring diagram. 2. You replaced a PNP transistor with an NPN transistor without understanding how it works - and you seem surprised it then doesn't work properly. Fix the diagrams first. That should give you the first hints as to the source of the problem. \$\endgroup\$
    – JRE
    Dec 30 '17 at 23:49
  • \$\begingroup\$ @JRE Thanks, I understand. I've replaced the wiring diagrams with schematics, hope this clears things up. \$\endgroup\$
    – siebz0r
    Dec 31 '17 at 0:32
  • 1
    \$\begingroup\$ Apart from not installing it backwards, you probably want to use a logic-level NFET for this, not a bipolar junction transistor. \$\endgroup\$ Dec 31 '17 at 0:40
  • \$\begingroup\$ @ChrisStratton Unfortunately there are few through-hole logic-level power MOSFETs that are rated at 3.3V Vgs so s/he would be stuck using adapter boards if OP wants to use the plugboard shown initially in the question. \$\endgroup\$ Dec 31 '17 at 1:07

I don't think your unknown PNP in an unknown circuit has anything to do with this.

You did not calculate the value for the base resistor, just guessed or copied, and it is too high so the transistor does not turn on fully. Maybe the transistor is connected correctly or maybe it is connected backward and thus has lower than normal gain, there is no way to know from the information you give. I can say that it appears to be connected backwards if that actually is a BC547 which has C-B-E order of pins.

Replacing it with a short means the base is getting some unknown current from the virtually shorted RPi GPIO, probably tens of mA. So it works, but the RPi GPIO is being abused.

You also should have a diode across the fan.


Thank you for posting the schematic, however it's usually better to add on rather than edit out information which keeps existing responses coherent.

According to the schematic your NPN transistor is being used in reverse mode. It will have very low current gain in that mode- maybe 5 or 10. So you need to supply excessive base current to get it to turn on. Swap emitter and collector. And a (reverse-biased) diode across an inductive load is usually a good idea.

Here is a schematic that illustrates what is happening and where the diode should go:


simulate this circuit – Schematic created using CircuitLab

The left circuit is what you have- the transistor is backwards and is operating similarly to the right-hand circuit functionally, but the current gain is only about 7.5.

The right hand circuit has the transistor saturated and the current is close to the 100mA if the transistor was a dead short.

In general you should reduce the base resistor if the load current is more than about 50mA. For a 100mA fan you might use 470 ohms. That is using a forced beta of 20. The base-emitter junction looks like a diode, so it's about 0.7V drop. The base current is (Vout-0.7)/Rbase. So you can easily calculate the proper approximate resistor value with simple arithmetic.

In your case without the resistor you're forcing the output voltage to be about 0.7 or 0.8V and the current will be above ratings for the RPi.

  • \$\begingroup\$ So because the collector and emitter are reversed the base requires a higher voltage? Also, you're talking about a flyback diode, right? \$\endgroup\$
    – siebz0r
    Dec 31 '17 at 0:38
  • \$\begingroup\$ Current, not voltage. Yes, a flyback diode. I will do a schematic above momentarily. \$\endgroup\$ Dec 31 '17 at 0:55
  • \$\begingroup\$ Thanks a bunch, really appreciate the effort. :) If I understand correctly, not using a resistor on the base is not recommended as that will likely damage the pi? Would it make a difference if I would put the transistor before the load instead? \$\endgroup\$
    – siebz0r
    Jan 1 '18 at 16:08
  • \$\begingroup\$ Can't really parse that, but use a base resistor of the approximate correct value. \$\endgroup\$ Jan 1 '18 at 16:16

To understand the behavior of your circuit you need to know what a transistor does. A Bipolar transistor is basically a current amplifier. That means a small current (going from Base to Emitter) can switch a much larger current (going from Collector to Emitter).

For a BC547 the typical current amplification figure (at 100mA Collector current) is 120, so to switch 100mA the Base needs at least 0.83mA (possibly quite a bit more if your particular transistor has less than typical gain).

But just being able to pass the current is not enough. To ensure that the load gets sufficient voltage to operate, the transistor must also have low voltage drop at that current. Here a is graph from the BC549 datasheet, showing typical Collector-Emitter voltage vs Base current at various Collector currents:-

enter image description here

If Base current is reduced below the amount required to switch the desired Collector current then Collector-Emitter voltage rises sharply, leaving insufficient voltage to operate the load. There is also a minimum voltage drop that cannot be reduced by increasing Base current, called the 'saturation voltage'. For example if the load draws 100mA then the minimum obtainable voltage drop is 0.4V, which requires a Base current of at least 6mA.

But why did the LED work when the fan didn't? Presumably because the fan needed more current than the LED, and Base current was sufficient to switch the lower current LED but not the higher current fan. The reason it worked without the Base resistor then becomes obvious - the resistor was limiting the amount of current going into the Base. Without the resistor, Base current was only limited by the internal circuitry of the Pi's I/O port.

The default current limit on Pi GPIO outputs is 8mA, which should be enough to switch 100mA through a typical BC549. With a 1k resistor the Base current would be less than 3mA, which might not be enough (especially if your fan needs more than 100mA to start up).

If the transistor was installed backwards (Collector and Emitter swapped) it would have very low current gain, and so would not work with anything that needed more than a few milliamps.


A BJT has a base current to collector cuurent enhancement of about 100 (hfe or \$ \beta\$) typically. You need enough base current to start the fan. A 1k resistance is too high, the \$V_{BE}\$ is about 0.7 volts A typical fan needs about 1 A to start and thus we need atleast 10 mA of base current. which means a resistance of (3.3-0.7)/0.01= 260 ohms maximum.

An LED however needs only 20 mA to function => even a (3.3-0.7)/2e-4 ie, even upto a 10 kilo ohm resistor will light an LED.

The schematic below shows the complete picture for a 5 ohm winding motor.


simulate this circuit – Schematic created using CircuitLab


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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