0
\$\begingroup\$

I want to use a fan for my raspberry pi and want to switch it on and off. I have found a tutorial online which I want to summarize below:

Components:

  • the 5V fan (DC motor in the image)
  • 680Ω resistor
  • NPN transistor (2N2222)

So the Pi's 5V pin are connected to the positive lead on the fan and the ground is connect to the transistor collector. The transistor emitter is connected to the ground.The transistor base is connected to the BCM 17 with a 680Ω resistor in between.

I'm a complete newbie, so please forgive me for the following question, but I just don't get it... maybe I'm just too stupid.

Why do I need this resistor? I need an exact explanation of what is going on in this circuit and why which component is needed.

circuit

\$\endgroup\$
2
  • \$\begingroup\$ Note that you should be aware to "overcurrent" at starting ... So, use PWM if needed. \$\endgroup\$
    – Antonio51
    Mar 18, 2022 at 14:19
  • \$\begingroup\$ I would also suggest adding an anti-parallel diode or some sort of snubber network across the DC motor to prevent its inductive kickback from blowing up your driver transistor or the raspi! \$\endgroup\$ Mar 18, 2022 at 15:22

2 Answers 2

4
\$\begingroup\$

A transistor behaves in some ways, much like two diodes: Diode equivalent
[Image Source]

If you connect a voltage on the base, there is nothing stopping the current flowing from the base to the emitter. There is a typical voltage drop of 0.6 V, but as soon as the voltage is higher than that, the current will be indefinitely high.

To solve this, you add a base resistor to limit the current.

To calculate the value of this resistor, you need to calculate the needed base current. The base current needed is the Collector current divided by Hfe (which is found in the datasheet for the transistor).

Explanation of entire circuit:
Motor is connected to a power supply, and its ground connection is switched on/off by the transistor. When voltage is applied to the base (through the resistor), current will flow into the base of the transistor. When that happens, the transistor will "open up", allowing current to flow from the Collector to the Emitter which is grounded.

When current starts flowing into the Collector, the motor will start running.

\$\endgroup\$
2
  • \$\begingroup\$ Hello, thank you first of all for your detailed answer! :) The current transfer rate of the transistor is 100 hFE. Now how do I calculate the base current? How do I know what the collector current is? \$\endgroup\$ Mar 18, 2022 at 15:00
  • \$\begingroup\$ @SharePointNewbie The current transfer ratio you mention (100) isn't applicable. It's to be used only for active mode cases, and even then only with skepticism, and not for saturated mode. \$\endgroup\$
    – jonk
    Mar 18, 2022 at 20:15
0
\$\begingroup\$

This resistor prevents the transistor from pulling down the power supply when it turns on. It also limits the base current.

Overcurrent in this scenario can do two things. It could damage the GPIO pin, and will almost certainly destroy the transistor.

By the way, I would recommend you use an external power source for the motor, since the raspberry pi may not have enough power for it.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ "transistor pulling down the power supply"? I don't think, and the base resistor would not exactly prevent that. \$\endgroup\$ Mar 18, 2022 at 15:17

Your Answer

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

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