0

I'm working on a project where I want to control a 12V PWM fan with a 4-pin header using a Raspberry Pi.

I am aware that a Raspberry Pi does not require a fan in day to day use cases but the reasoning for doing so is that I have a 5 node kubernetes cluster running a couple of applications that use CPU which can cause the cluster temperature to increase.

However, I want to power the fan using an external 12V power supply instead of drawing power from the Raspberry Pi itself.

My Setup:

Proposed Circuit:

  1. Power Connections:

    • The fan's positive wire is connected to the 12V external power supply.
    • The fan's ground is connected to the collector of an NPN transistor 2N2222.
  2. Transistor Setup:

    • The emitter of the NPN transistor is connected to the negative terminal of the external power supply.
    • A diode (1N4001) is placed across the fan’s power terminals for protection (cathode to positive and anode to ground).
  3. Control Connection:

    • A resistor (1kΩ) is placed between a PWM-capable GPIO pin on the Raspberry Pi and the base of the NPN transistor.
    • A pull-down resistor (10kΩ) is added between the base of the transistor and ground to ensure it turns off when the GPIO is low.
  4. PWM Signal:

    • The Raspberry Pi sends a PWM signal (around 25 kHz) to the fan's PWM pin via the GPIO pin to control fan speed.

Questions:

  1. Does this circuit setup look correct for safely powering the fan externally while controlling it with the Raspberry Pi’s PWM output?

  2. Are there any potential risks or improvements that should be made to this design, especially regarding isolation between the Raspberry Pi and the 12V power supply?

  3. Do I need additional components or considerations to protect the Raspberry Pi from any back EMF or voltage spikes that could occur?

Any feedback or suggestions would be greatly appreciated!

P.S. Full disclosure, I am more of a software guy than a hardware, I understand very basics of circuit design, if i have a circuit i can solder it together and get things rolling. Also, the above circuit is designed by ChatGPT, so I don't trust it 100% but it might give a good starting point

2
  • This makes no sense. Include a circuit diagram in your question (there is a tool in the taskbar). You have only specified 2 fan connections. If it IS a PWM fan what is connected to the PWM control?
    – Milliways
    Commented Sep 4 at 6:42
  • it makes no sense to control the fan power supply when the fan has a control wire
    – jsotola
    Commented Sep 5 at 2:25

1 Answer 1

0

What you appear to be proposing will NOT work. If you REALLY want to use a PWM fan you need to connect it directly to supply voltage and control it via the PWM input.

No extra hardware is needed although YOU will have to write your own software to sense temperature and control the speed as there is no existing code to do this (at least on Pi4 - the Pi5 includes code for its fan).

The fans are overkill - the small fan on the active cooler of the Pi5 is more than adequate.

The Pi4 does need cooling for demanding tasks, but a simple fan (which turns on when needed) would be more suitable. See https://raspberrypi.stackexchange.com/a/105820/8697 (which will also work for a 12V fan).

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.