5
\$\begingroup\$

I have a 12V computer fan that I want to hook up to my Raspberry Pi. It has a 7V sensor, 12V power and ground. I know that the Pi can only supply 5v so I’m just wondering how to hook it up to the Pi and be able to control the fan through GPIO pins.

I do have a 12V Power supply

\$\endgroup\$
  • \$\begingroup\$ If it's a 12 V fan, and you only have 5 V available you're out of luck. Get a boost converter to generate the 12 V for you, and switch the fan with a mosfet. \$\endgroup\$ – Colin May 15 '18 at 8:45
  • \$\begingroup\$ You can use a PNP/NPN transistor pair to switch 12V with 5V \$\endgroup\$ – MCG May 15 '18 at 8:47
  • \$\begingroup\$ @TomHeeley thanks for clarifying the power supply! Means I can keep my answer as it is! Lol \$\endgroup\$ – MCG May 15 '18 at 9:06
7
\$\begingroup\$

If you want to switch 12V with 5V, then you can use a PNP/NPN pair of transistors. A circuit I have used before:

schematic

simulate this circuit – Schematic created using CircuitLab

When you apply 5V to the base of Q2, Q1 will allow the 12V to pass. I left the part numbers as the generic ones in the schematic editor so you will have to make sure you get ones that can handle the current requirements etc.

There are plenty of PNP/NPN switching circuits online you can google if you want a more in depth look or if you want to do something a bit more sophisticated, but this should give you a starting point.

Pretty sure there is a name for this configuration but I can't remember it! If anyone does, feel free to add it in!

\$\endgroup\$
  • \$\begingroup\$ I read the question as though there is only a 5 V supply available. This is a good answer though, if there's a 12 V supply present +1 \$\endgroup\$ – Colin May 15 '18 at 8:59
  • 1
    \$\begingroup\$ Why a pair? In this application a single NPN transistor or an nMOS is perfectly fine (you don't need to switch the high side in this kind of application) \$\endgroup\$ – frarugi87 May 15 '18 at 12:26
  • 1
    \$\begingroup\$ If you have a simpler way of doing it, by all means write your own answer. Always good to have a range of choices, then the OP can make a decision on what would suit his application best \$\endgroup\$ – MCG May 15 '18 at 12:39
  • 1
    \$\begingroup\$ What's wrong with a single NPN with an appropriate base resistor? \$\endgroup\$ – Scott Seidman May 15 '18 at 15:19
  • 1
    \$\begingroup\$ I'm a huge fan of this answer \$\endgroup\$ – Ben Lorantfy May 15 '18 at 19:24
7
\$\begingroup\$

There are circuits where switching the high side of the load is necessary (for instance, when your load has a communication interface, or when you are reading back something from the load like the current).

In this case, however, you don't need any of these features. So I recommend a single transistor solution (cheaper):

schematic

simulate this circuit – Schematic created using CircuitLab

This circuit is fine if the current in the fan is up to let's say 50mA.

If the current is higher, you'll need to either use a "two stages transistor" (aka darlington) or use a power transistor which can handle more current (and in order to provide it the required base current you'll need a smaller transistor):

schematic

simulate this circuit

In the first case you can choose any darlington (I found the 2N6426); in the second the PNP should be one which can handle the required current.

You can also use a single nMOS:

schematic

simulate this circuit

In this case, you will have to choose a MOS transistor with a low Vgs-th; for instance the VN2222 or the 2N7000 can handle some hundreds of mA.

Final note: since the load can have inductive behaviors, please remember to add a freewheeling diode

\$\endgroup\$
  • \$\begingroup\$ Nice solution! And well explained too. +1 from me \$\endgroup\$ – MCG May 15 '18 at 15:10
1
\$\begingroup\$

Here is a solution using a single npn transistor. Q1 should be rated to handle the current drawn by the fan. D1 protects Q1 against voltage spikes when the fan is turned off. Q1 should be rated for V2 (~12V) + 0.7 volts.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
1
\$\begingroup\$

If you have a simpler way of doing it, by all means write your own answer. Always good to have a range of choices, then the OP can make a decision on what would suit his application best

ok @MCG I'm not the best drawer of schematics with these programs,but here it is:

schematic

simulate this circuit – Schematic created using CircuitLab The high gain of the tip122 Darlington transistor with internal dampening diode makes a low parts count solution for driving everything from lamps to solenoid coils. The 120 ohm resistor is the minimum resistance needed for total switch operation, but you can increase this resistance if you need a bias range for varying the speed. depending on the gpio current capacity, you might need to increase this resistance.

\$\endgroup\$
  • \$\begingroup\$ I think this may need an explanation to go with it. @frarugi provided a good one with his answer. \$\endgroup\$ – MCG May 15 '18 at 15:08
  • \$\begingroup\$ ok, I'll add an explanation \$\endgroup\$ – drtechno May 15 '18 at 15:28

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.