Hi there!
I'm working on a project where I need to control the fan speed of a 3-pin 12V PC fan (Thermaltake Pure 20). The fan is powered by a 12V power supply that goes through an n-channel MOSFET (IRF520) which I control with my Arduino Nano. I'm trying to use PWM on the gate to control the voltage supplied to the fan and in that way control the fan speed. It works perfectly fine with the default PWM frequency of 488Hz and all the way up to 8kHz but since the frequency is in the human hearing range, the fan makes an audible hum. To combat this I tried changing the frequency on pin 3 to 31.4kHz with the following code:
TCCR2B = 0b00000001;
TCCR2A = 0b00000001;
Now the fan only turns when a constant HIGH signal is sent to the gate analogWrite(3, 255) and anything below 255 makes the fan stop spinning. I checked with a multimeter and even though it reads voltages in the range of 7-11V the fan won't spin (it did spin with 7V at lower frequencies). I also checked the frequency over the fan with the multimeter, which read 31kHz as expected. Is there something I can do to make the fan spin at a higher frequency or am I out of luck here?
To output 31.25kHz PWM on timer 2 with analogWrite(), you only need to change the timer2's prescaler by adding the following lines of code to the setup() portion of your sketch:
TCCR2B &= ~_BV(CS22); // Increase the timer2 PWM frequency to 31.25kHz
TCCR2B |= _BV(CS20);
Hi, I added those to lines to setup() but it didn't change anything. I already checked with a multimeter prior to adding those lines that the Arduino was indeed outputting a 31kHz signal so adding them made no difference.
One is that the fan does not want to respond to the higher PWM frequency due to the inductance of its coils.
The other is that using the wrong FET is not generating a proper PWM output. Of course, we can't say as we don't know the details of your secret circuit.
As it is only a three pin fan, you can't simply use a PWM logic signal to control it.
I'm aware that the fan itself can't be controlled with PWM directly but I was under the impression that by adjusting the voltage supplied to the fan with a transistor I could regulate the fan speed. The code and circuit above do work just as expected if I just remove the two lines that adjust the frequency but then it makes the hum/tone I'm trying to get rid of.
Hehe Iām fairly new to electronics so any suggestions for improvements would be welcome. For the 12V power supply I use a 60W wall adapter that takes 230vac and outputs 12vdc. The Arduino is powered with USB.
OK, so this will in general work, but only due to the isolation in the grounds.
Point is - the circuit you posted is clearly wrong and if it is actually how you have wired it, may be part of the trouble you are having. Care to check it is actually how you have it wired?
Been out to radio club construction night, then had to get some medication for grandsons at 24hr chemist, then home and I had an attack of the munchies....
Hi again guys,
Sorry for the late response, life got in the way . You were right Paul, the circuit I posted is not right. It seems that I mixed up the drain and the source of the MOSFET and forgot to put in the pull-down resistor I have between gate and source. I'm quite new to this so if there's something else wrong I would really appreciate some help . However, since the circuit works fine (except for the noise) at a lower PWM frequency I would assume the issue isn't in the circuit.
The term logic level was new to me so I looked it up and if I understand it correctly it's when a transistor is designed to operate with only 5V or less on the gate? (A voltage that a microcontroller can supply.) When looking at the datasheet for an IRF520 it says that the Gate Threshold Voltage is min 2V and max 4V, don't know if that matters. Do you think a logic level transistor will solve the issue?
We repeatedly have to point out that the Gate Threshold Voltage is the voltage below which the FET turns off. It is quoted as a figure of several microamps.
If you want it to switch power to something, you need the gate voltage at which the source-drain resistance is quoted.