I have a project, where a raspberry-pi shall measure temperature, and regulate a 12V non-pwm fan by modifying voltage throughput to the fan between 5V and 12V. The fan has a separate power-supply. Temp-measurement works fine already, but I need help building the circuit (being a beginner, I read tons of howtos and I think I got the idea, but I want to be a bit more safe, to not damage components)

As far as I understood, I have to achieve the following: Switch a Transistor (which is capable of handling the fan voltage & current) with a specific pulse, generated by a Raspberry GPIO-Pin configured as PWM-Pin and driven e.g. by python-scripts. => Smoothen the pwm-generated voltage output. The consumer in the circuit shall be a 12V Fan that uses only 0.125A peak.

Could anybody be so kind to explain how the circuit has to look like exactly and help me out calculating the correct values for those components ? Of course any ideas are welcome. I just need to achieve analog voltage regulation for that dc fan somehow. If I could read the fan speed in addition (from 3rd-pin, no pwm-fan), this would be additional benefit... Thanks a lot in advance, Oliver

PS : What software do you use to design circuit-graphics ? Are there any recommendations for open-source electronics-layouting ?!

  • \$\begingroup\$ Hello and welcome. How long have you researched this? i find plenty of answers on the raspi website. (for your software, i'd go whith kicad) \$\endgroup\$
    – Sclrx
    Jul 19, 2018 at 14:32
  • \$\begingroup\$ I have been looking for an example that does exactly what I want to do and found none. Most of them are working with the power supplied by the raspberry, or 3V/5V Fans or PWN controlled fans. I couldn`t find an example doing what I want to do (regulate the fanspeed by modifying the analog voltage, NOT just switch the Fan on/off). Thanks for the hint with KiCad \$\endgroup\$
    – Oliver
    Jul 19, 2018 at 14:35
  • \$\begingroup\$ I second the decision on KiCAD because it's open source but it'll take a long time to download haha. I believe your objective for your project is clear. Unfortunately, your layout and implementation, is not and I feel like you're asking us to do house design and that's not really the purpose of this website. If you post your own design, we could help you evaluate it. \$\endgroup\$
    – user103380
    Jul 19, 2018 at 14:39
  • \$\begingroup\$ actually this is not house design at all. I stated, that I would like to switch an external circuits power using rpi-pwm using a transistor. this is pretty much exact, everybody can image the layout, since it consists of 1 component only. the external voltage shall be smoothened, since its pulse modulated, so I need an R/C combo. The only thing I am unaware of, are the values to choose for those mentioned components. Anyone with more experience than me, could easily calculate them, maybe with a sentence of explanation on what to obey. I found howtos but didnt quite understand them. \$\endgroup\$
    – Oliver
    Jul 19, 2018 at 16:02

2 Answers 2


What you ask is easy to do:

Something needs to produce the PWM pulses in the 25 to 50 kHz range. I don't know if a RPi has PWM built in. If not, have it drive a external PWM chip. This is NOT something suitable to do in software, especially on a general purpose machine running a operating system, like the RPi.

Q1 is switched on and off according to the digital logic PWM signal. D1 is NOT optional. It protects the transistor from large inductive kickback voltages when it switches off. It also allows the existing current to continue circulating during the off phase. That reduces ripple, which minimizes the AC current that doesn't go to driving the motor but heats the windings.

There should be no need for any explicit "smoothing" of the voltage. You haven't given any reason why you want to do that anyway. The inductance of the motor windings will smooth the current themselves.

  • \$\begingroup\$ Thank you soo much for your detailed answer !! Yes, the RPi has GPIOs that can be configured to be "native" PWM Pins. And yes, I have seen this diode parallel to the fan before and I will care for it thanks. I read in HowTos, that the generated "pulsed" voltage could be bad for the fan, thats why I stated I need smoothing. If u say, the fan does it itself anyhow, then I can leave that out. Just one more tiny question : What characteristics do I have to obey for the transistor ? I ordered a whole sortiment of transistors, I hope one of them will fit.. \$\endgroup\$
    – Oliver
    Jul 23, 2018 at 14:12
  • \$\begingroup\$ @Oliver: The transistor has to be able to handle the voltage and current, and in the case of a FET, has be turned on sufficiently with 3.3 V on the gate. The IRLML2502 I show meets these criteria. \$\endgroup\$ Jul 23, 2018 at 14:32

enter image description hereI did not manage myself to get a steady control via pwm/transistor, so I used a digital potentiometer (X9C103) to control a LM317 (via a BC547).

Anyway, if you want a steady control you need a fan with 3 pins. Use the signal on the yellow wire to read the rpm and use that in the program to control it. The nice thing about it is that you can detect if the fan has failed or not.

If you are interested, I can add a picture of the components I used.

I believe also that there must be a simpler way via pwm/transistor directly, but I wanted to use my digital pot :)

  • \$\begingroup\$ I was thinking about this method too, using a digital pot ic. Could you maybe describe your layout a bit more detailed please =) ? Am I wrong, that the digital pot just has to be placed in series with a resistor with a value equal to max of the digital pot, and then grab resulting-voltate before and between resistors? \$\endgroup\$
    – Oliver
    Jul 19, 2018 at 15:54

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.