killwater
Posts: 22
Joined: Sat Jan 13, 2018 11:05 pm

Controlling 5V fan from GPIO pin with PWM

Sat Jun 12, 2021 9:51 pm

Hello,
I am trying to control a 5V 3pin fan from GPIO with PWM control. It works at full speed if I connect it directly to 5V pin and ground. However if I try to control it from GPIO 12 it does not work.
I am using a Bi-directional 4 channel logic level shifter from ebay.
Capture.PNG
Capture.PNG (27.62 KiB) Viewed 741 times
I get 5V on fan terminal if the fan is disconnected. When I connect it to the fan it will only move a tiny bit and stop. At the moment I am trying to run it at full speed without the PWM control.

I am working under assumption that GPIO12 only provides a control signal to the logic shifter and it turns on/off current flow from 5V pin so cannot understand what mistake am I making.

The connections look like the below:

GPIO12 --------------- LV2 LOGIC SHIFTER HV2 ----------------- FAN +
GROUND--------------GND LOGIC SHIFTER GND ----------------- FAN -
3V3----------------------LV LOGIC SHIFTER HV-----------]
5V-----------------------------------------------------------------------]

Thank you in advance
Michal

vffgaston
Posts: 28
Joined: Wed May 13, 2020 3:33 pm

Re: Controlling 5V fan from GPIO pin with PWM

Sun Jun 13, 2021 6:27 am

The chip you are using just shifts logic levels: it does not provide an output current big enough as to move your fan.

What you need is a "driver", perhaps a npn transistor or similar.

killwater
Posts: 22
Joined: Sat Jan 13, 2018 11:05 pm

Re: Controlling 5V fan from GPIO pin with PWM

Sun Jun 13, 2021 8:13 am

I thought I am limited to the smaller of 5V pin max current or the chip rating as it works as a high frequency switch. What is the maximum current I can draw? The fan is rated at 0.15A.


pcmanbob
Posts: 11325
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling 5V fan from GPIO pin with PWM

Mon Jun 14, 2021 2:49 pm

To control you fan you need to use a transistor like this.

Image

it assumes the 3rd wire is just for speed output.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

killwater
Posts: 22
Joined: Sat Jan 13, 2018 11:05 pm

Re: Controlling 5V fan from GPIO pin with PWM

Tue Jun 15, 2021 6:20 pm

Thank you very much, both of you.

killwater
Posts: 22
Joined: Sat Jan 13, 2018 11:05 pm

Re: Controlling 5V fan from GPIO pin with PWM

Sun Jun 20, 2021 11:43 pm

Jsut one more question - can I use S8050 instead of 2n2222? Would 1k resistor still be sufficient?

User avatar
Imperf3kt
Posts: 4563
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia
Contact: Twitter

Re: Controlling 5V fan from GPIO pin with PWM

Mon Jun 21, 2021 12:29 am

Note that the third wire is an output from the fan, not an input. Do not connect it to your Pi.
55:55:44:44:4C
52:4C:52:42:41

Rose tinted glasses are difficult to see through.

pcmanbob
Posts: 11325
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling 5V fan from GPIO pin with PWM

Mon Jun 21, 2021 10:20 am

killwater wrote:
Sun Jun 20, 2021 11:43 pm
Jsut one more question - can I use S8050 instead of 2n2222? Would 1k resistor still be sufficient?
The transistor will carry the load of the fan but you may have to lower the resistor value to obtain full voltage/current to the fan.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

killwater
Posts: 22
Joined: Sat Jan 13, 2018 11:05 pm

Re: Controlling 5V fan from GPIO pin with PWM

Mon Jun 21, 2021 11:01 pm

Works well. i managed to get it change the speed and I got full power as far as I can tell. Thank you.
The only problem I have now is it makes a lot of high pitched noise if it deos not work at 100%. I expected a little bit of humming but it can be heard from adjacent room. Is it because I used the S8050 instead of 2N2222?

pcmanbob
Posts: 11325
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling 5V fan from GPIO pin with PWM

Tue Jun 22, 2021 7:03 am

What frequency did you set the pwm to ?

Try changing it to some thing else 50 or 100 are what people tend to use.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

vffgaston
Posts: 28
Joined: Wed May 13, 2020 3:33 pm

Re: Controlling 5V fan from GPIO pin with PWM

Tue Jun 22, 2021 7:07 am

killwater wrote:
Mon Jun 21, 2021 11:01 pm
Works well. i managed to get it change the speed and I got full power as far as I can tell. Thank you.
The only problem I have now is it makes a lot of high pitched noise if it deos not work at 100%. I expected a little bit of humming but it can be heard from adjacent room. Is it because I used the S8050 instead of 2N2222?
Absolutely no. The main problem the transistor may produce is a noticeable (use your fingers) auto-heating. I guess the problem comes from the very fact that you are using a PWM audible frecueny. Try to change it over, say, 10.000 Hz (although your dog -and young boys- may keep hearing it).

killwater
Posts: 22
Joined: Sat Jan 13, 2018 11:05 pm

Re: Controlling 5V fan from GPIO pin with PWM

Tue Jun 22, 2021 4:39 pm

I went down to 100Hz and it seams to be much better. Thank you.

Return to “Automation, sensing and robotics”