Arduino Forum

Using Arduino => Motors, Mechanics, and Power => Topic started by: FlyingSteve on Nov 14, 2012, 12:05 am

Title: 12V PC fan voltage control
Post by: FlyingSteve on Nov 14, 2012, 12:05 am
Hi, I am looking for a simple straight forward way to control the voltage to a PC fan with a 12VDC brush motor. Would like to be able to turn the fan on low speed (5V input) with Arduino pin set to low and high speed (12V) when the pin goes high...

Thanks for the input guys and sorry for being such a damn newb lol
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 14, 2012, 12:52 am
I've played a bit with a pc-type 12v fan. I changed its speed by changing the duty cycle of the pwm signal coming from Arduino.
To control the fan I used a couple of transistor I had aroud... a BC548 and a BD135.
An Arduino PWM-enabled pin controlled the BC548, which in turn activated the BD135. The latter was acting as an ON-OFF switch on the fan +12v line.
On the software side, analogWrite(fanPin, value) did the trick. Too low values made the fan noisy and still, because you need a minimum torque to have it start rotating.
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Nov 14, 2012, 01:58 am
I fooled with an array (4) 120MM fans on a full H-Bridge motor controller (Pololu brand) and the PWM wouldn't work... Maybe I needed to set the PWM pulse speed lower (less than the 20kHz)? I don't know, but I'd just like a simple way to switch the supply voltage lines without having to rig up a bunch of relays or anything eccentric like that. Maybe a 5-pin relay or something? Mmm... The fans will always be on, so it's not like I need 12V, 5V and Off... They could always run at 12V and be switched to 5V when needed.
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Nov 14, 2012, 04:52 am
If I use a 5v relay with both N.O and N.C outputs, I can put a pot on one of the outputs... Any idea's for doing this solid state, such as a transistor or mosfet that has 2 separate outputs depending on control signal?
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 14, 2012, 08:46 am
http://www.arduino.cc/en/Reference/AnalogWrite

"The frequency of the PWM signal is approximately 490 Hz."

Maybe those 20KHz were actually too high...
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Nov 15, 2012, 01:02 am
That's my thoughts... Lower the PWM freq. or I might use a different way.
Title: Re: 12V PC fan voltage control
Post by: dhenry on Nov 15, 2012, 01:28 pm
Quote
less than the 20kHz


Yes, like < 100hz.
Title: Re: 12V PC fan voltage control
Post by: dc42 on Nov 15, 2012, 03:59 pm
If the PC fan really does have has a brushed motor, then you can just control it with PWM. However, all the PC fans I have come across use brushless motors, which don't work very well if you PWM the supply voltage.

You can buy PWM-controllable PC fans. They only cost a little more than regular PC fans. The specification says you should PWM them at 25KHz, which can be done using an Arduino, although most will probably work over a wider PWM frequency range than the spec says.
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Nov 15, 2012, 08:47 pm
Thanks dc42, I know of those pwm-capable fans, but I'm prototyping and I already have a bunch of fans laying around from a previous project and I'm trying to not blow my budget with buying things I already have. Any thoughts on how I can just switch the voltage going to them? I'm using a PC power supply, so I'll have 5V and 12V readily available and it would be great if I could switch between 5v and 12v rather than doing a variable control.

** I thought brushed motors were more difficult to control through PWM than brushless... Maybe they are brushless then, I'm not sure. I just remember that I tried it before and they didn't slow down or respond to the PWM control through the motor controller at all.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 15, 2012, 08:49 pm
Since the load is small a relay is probably sufficient... Can't understand why you keep running away from pwm though...
Title: Re: 12V PC fan voltage control
Post by: dhenry on Nov 15, 2012, 09:05 pm
Quote
they didn't slow down or respond to the PWM control through the motor controller at all.


Brushless motors are easy to tell: if you rotate the blades effortlessly, they are brushless motors.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 15, 2012, 09:39 pm

Quote
they didn't slow down or respond to the PWM control through the motor controller at all.

Brushless motors are easy to tell: if you rotate the blades effortlessly, they are brushless motors.


I have a pc fan that reads:
"DC brushless, model AD0612MS C70GL 12V 0,13A ADDA CORP."
but if I turn it when it's off I can feel "magnetic force hills" so to speak. Even if I give it a spin, it oscillates a little around a precise position just before totally stopping. Every 360° turn sees 4 distinct poisitions (4 poles ?).
I can control this fan with a transistor and an arduino pwm pin (i.e. standard analogWrite() call).
Is this "real" brushless or what ? I'm confused. Thanks for any hints!
(ps: I've looked for a datasheet but couldn't find nothing but endless part lists...)
Title: Re: 12V PC fan voltage control
Post by: dhenry on Nov 15, 2012, 10:44 pm
Quote
but if I turn it when it's off I can feel "magnetic force hills" so to speak.


That's a brushless motor.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 16, 2012, 12:24 am
Then the fact that I could vary its speed with just an analogWrite() and a couple of transistors seems to contradict what dc42 said earlier...  ?-|
Title: Re: 12V PC fan voltage control
Post by: dc42 on Nov 16, 2012, 07:25 am

Then the fact that I could vary its speed with just an analogWrite() and a couple of transistors seems to contradict what dc42 said earlier...  ?-|


How wide a speed range did you get? Come to think of it, I've heard of people PWMing brushless PC fans before. I remember they had problems with the tacho output.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 16, 2012, 07:50 am
This particular fan I have has only two wires: black and red.

The control range I had was quite narrow: IIRC from about 50% upward. At lower pwm values the fan would just "play a note" ;)
Once started though, the lowest acceptable pwm value decreased. Start inertia, I guess.
If I have a minute I'll rewire the thing and note down the exact values.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 16, 2012, 07:24 pm
Here's the sketch I wrote to control the fan. It's simply parsing integers from the serial line and analogwriting them directly to pin 6.

Code: [Select]

int cnt = 0;
char buf[100];
int pin = 6;

void setup() {
    Serial.begin(115200);
}


void loop() {
    if (Serial.available() > 0) {
        char ch = Serial.read();
        if (ch == 0x0D || ch == 0x0A) {
            if (cnt > 0) {
                buf[cnt] = 0;
                int value = atoi(buf);
                analogWrite(pin, value);
                Serial.println(value);
                cnt = 0;
            }
        }
        else {
            if (cnt < 100-1) {
                buf[cnt++] = ch;
            }
        }
    }
}


Pin 6 goes to a 1k resistor which goes into a bc237b base. bc237b collector to +5 and emitter to a 1k resistor, to bd135 base.
Fan red wire to +12v, black to bd135 collector. bd135 emitter to gnd.

When the fan is stopped, it only starts with values 120 and above.
When it's running, I can go to as low as 25 without it stopping.
When running under 150 I can clearly hear a sort of note.
Title: Re: 12V PC fan voltage control
Post by: dhenry on Nov 16, 2012, 10:16 pm
Quote
When the fan is stopped, it only starts with values 120 and above.
When it's running, I can go to as low as 25 without it stopping.


That's perfectly normal.
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Nov 17, 2012, 06:13 am
I'll give Tuxedo's transistor setup a try... Should work. The PWM freq. from the Pololu motor controller was too high, that's why the fans didn't respond. PWM would actually be the preferred method so I can set different fan speeds for different temperatures.

** What radioshack friendly transistors could I use to setup a pwm circuit like the one Tuxedo mentions
Quote
Pin 6 goes to a 1k resistor which goes into a bc237b base. bc237b collector to +5 and emitter to a 1k resistor, to bd135 base. Fan red wire to +12v, black to bd135 collector. bd135 emitter to gnd.
?
Again, sorry for lacking so much electronics knowledge lol I knew more a few months ago when I was learning something new every day, but then I stopped working on Arduino projects for a few months and now I'm back to stupid.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 17, 2012, 11:04 am
Code: [Select]

                     5V                12V
                     |                  |
  +------------------+                  +-------Fan red wire
  |                  |
  |                  |                  +-------Fan black wire
--+--+               |                  |
A    |     1k        C                  |
R  6 |---/\/\/----B     Q1   1k         C
D    |               E-----/\/\/-----B     Q2
U    |                                  E
I    |                                  |
N    |                                  |
O    |                                 GND
--+--+
  |
GND

FAN = 12V 0,13A brushless PC-type fan
Q1 = BC237
Q2 = BD135, no headsink required


I hope some kind hw-sould will step in and correct any silliness I've written... :P
Title: Re: 12V PC fan voltage control
Post by: dc42 on Nov 17, 2012, 11:24 am
Q1 in that circuit is redundant, because of the value you have chosen for the base resistor of Q2. You could just as well drive Q2 from the Arduino pin through a 1k base resistor. Although I would reduce the base resistor to about 470 ohms, to make sure that Q2 turns on fully.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 17, 2012, 11:44 am

Q1 in that circuit is redundant, because of the value you have chosen for the base resistor of Q2. You could just as well drive Q2 from the Arduino pin through a 1k base resistor. Although I would reduce the base resistor to about 470 ohms, to make sure that Q2 turns on fully.


TBH that circuit comes from an experiment I made (too) many years ago... I was using the parallel port of 286 and writing to it with qbasic 50-or-so lines "program" ;-P

I'll try your suggestion.

Thanks!
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Nov 17, 2012, 03:05 pm
Ok, so could I do this circuit with a TIP120 Darlington?

I'd imagine the circuit would be Pin 6 to Base, Fan Ground to Collector, Emitter to Ground? Would I need a pull-down resistor to Ground on the Base?
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 20, 2012, 08:44 pm

Q1 in that circuit is redundant, because of the value you have chosen for the base resistor of Q2. You could just as well drive Q2 from the Arduino pin through a 1k base resistor. Although I would reduce the base resistor to about 470 ohms, to make sure that Q2 turns on fully.


I tried you suggestion and it worked (I had no doubt :) )

It seemed to make no difference if I used a 1k, 470 or even 220 ohm resistor between pin 6 and bd135 base.

Thank you :)
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 20, 2012, 09:03 pm
Edit: for the record, with a 100uF 25V connected between the fan wires I could silence it at low speeds. The relationship between pwm raw value and fan speed changed - now I can go as low as 16, provided the fan is already running, and the start pwm value is now about 50.
Title: Re: 12V PC fan voltage control
Post by: dc42 on Nov 21, 2012, 09:10 pm

Edit: for the record, with a 100uF 25V connected between the fan wires I could silence it at low speeds. The relationship between pwm raw value and fan speed changed - now I can go as low as 16, provided the fan is already running, and the start pwm value is now about 50.


Be careful, with that capacitor in place you may easily exceed the current rating of the BD135 at the start of each PWM pulse, especially if you use a low-value base resistor. Also, the capacitor will make the fan run faster at low PWM values - which is why you can now go down to 16.

To silence the fan, it would be better to use a PWM frequency above the audible range, say 25KHz. If the fan doesn't work well at that PWM frequency, then an inductor and capacitor can be used to smooth the voltage. Or (more simply), buy a PC fan with a separate PWM input.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 21, 2012, 10:12 pm
Thanks for the info!

Quote
Or (more simply), buy a PC fan with a separate PWM input.


The "buy" option is good when you don't want to waste time in details and get a project done. But I'm just experimenting with some electronic "waste" I have accumulated over the years from my dad's shop... ;)
Title: Re: 12V PC fan voltage control
Post by: ash901226 on Nov 22, 2012, 12:01 am
sorry for me to interrupt. but for me since the motor would be always on then why not use a relay?
connect the red wire to the comment of a relay and the black to ground. on the one of the N.O. just put a 12VDC or the V max of the motor while the other use a well any kind of volatage converter you know to power that motor. just put a transistor and a diode to activate the relay. this will make it run at different speed.
Title: Re: 12V PC fan voltage control
Post by: marcello.romani on Nov 22, 2012, 12:14 am
As you can see I'm no expert when it comes to electronics, let alone motor control, but thinking about the pros and cons of a relay vs. pwm, some words come to mind: cost, noise, reliability (no mechanical failure for the transistor option).

I'm just thinking out loud... I'm curious too about the answer from the gurus :P

my 2 1 cent.

Title: Re: 12V PC fan voltage control
Post by: ash901226 on Nov 22, 2012, 07:25 am
technically i would say that yeah i would always choose the pwm way. but if your the type that is result oriented then the method i suggest will get you far enough.
Title: Re: 12V PC fan voltage control
Post by: FlyingSteve on Dec 03, 2012, 11:35 pm
I set a PWM circuit up using a FET and any time I try to slow the fans down (4 120mm PC fans, 350mA) at all they start making an unhappy noise. Any idea's? The fans are definitely a brushed motor.

Thanks