Controlling a 12v fan with a transistor and PWM

I’ve been working on a project that I need to be able to control the speed of a fan. I have a 12v fan that doesn’t have a PWM pin so it’s voltage only. I’ve hooked up a manual potentiometer and that was great but I need something controlled by the software. So I first started looking at a digital potentiometer but that looked pretty complicated. So my friend Ian pointed me to this article to control it with a transistor through PWM.

So today I tried to get that setup but was having some problems. I was able to get the voltage to go between 12v and 1v with setting the cycleduty but the fan would never respond at any voltage. I used a multimeter to test the voltages and it was showing up to 12 volts. But as soon as I hooked the fan straight up to the 12v source it worked fine.

I tried changing the frequency to different ranges but it didn’t have any affect. It seems that my PWM is functioning correctly because the voltage changes appropriately but it doesn’t run the fan.

What am i missing? Any thoughts I can try?

Btw, running a cerbuino bee with netmf 4.2.

Can you show the code you are using?

What frequency where you using for the PWM and what duty rates?

What happens if you set it to a 100% duty cycle?

Here is my code I’m using. I’ve tried many different frequencies. 1000, 2000, 10000…


double frequency = 1000;
double duty = 1.0;
PWM pwm = new PWM(FEZCerbuino.Pin.PWM.A2, frequency, duty, false);
pwm.Start();

for (var i = 9; i > 0; i--)
{
    duty = i / 10;
    pwm.DutyCycle = duty;
}

Here are my voltage tests at different frequencies. I can’t seem to get it to range completely from 1v to 12v. Frequency is X axis and duty is Y axis.

----10,000—2,000—1,000
0-------.1--------.1--------.1
.1-----11.9-----7.3------5.3
.2-----11.5-----7.2------5.3
.3-----11.5-----7.1------5.4
.4-----11.6-----6.9------5.2
.5-----11.5-----6.4------5.0
.6-----11.5-----5.7------4.7
.7-----11.5-----5.3------4.5
.8-----11.6-----5.2------3.5
.9-----11.7-----5.1------3.0
1.0-----.1----- .1--------.1

I also attached my schematic for this section. Maybe it’s my wiring?

I just wandered across this page also. I haven’t read it all but its fairly lengthy and may help you identify the problem. I think your diode is reversed.

Thanks for the article. My diode was reversed but unfortunately it didn’t solve the problem. I’m still getting the same results. Not sure why my voltage meter would say it’s pushing 7v but nothing happens when I plug in the fan. But as soon as I skip the transistor and plug it straight to the 12V, the fan starts spinning.

It is actually -12V or are you referring to GROUND?

Your circuit won’t work if this is GND as the transistor is an NPN darlington.

The emitter should be connected to GROUND and the COLLECTOR to the motor. This way, when the transistor is switched on it conducts the current to ground.

Put the DIODE across the motor with the CATHODE to the +12V

Here is a nice little diagram of how to do this with an Arduino but same basic wiring.

1 Like

A little late night hacking at DevLink last night quickly revealed the source of this problem. His grounds were not tied together :slight_smile: