Driving a PC fan - transistor with or without an optocoupler?

Hello,

I'm going to be controlling and driving 8 PC-style fans from an Arduino project, and want to use PWM to vary the speed of the fans.

I've seen several examples that use an optocoupler (or even a relay) to isolate the 5.5V Arduino side from the 12V fan side. Is that really necessary? Can I not drive this through a simple transistor only?

Either way can work. If you use a transistor switch then the negative terminal of the +12vdc voltage source must be wired to an arduino ground pin to function. If you use a opto-isolator chip then there is no need (and no point) in connecting the two ground points together.

Cool, thanks. Everything is being powered from a PC power supply, so I was envisioning all the grounds being tied together, and the Arduino being powered from an LM317 voltage regulator.

Sorry for digging this topic up, but is this diagram really correct? Shouldn't the diode be connected in parallel with the fan, and not with the transistor?

I would agree with you on that Rubid. Little funny to use a LM317 for a regulator, fixed 5v like LM7805 would require less parts, just a couple of caps.

Yeah, the diode there is a silly mistake. I only used a 317 because that's what I had lying around.

Sorry if the circuit is messy

I remade the circuit and it works now...ish.

When using the following code I get the fan spinning at 100% speed...cool, only im really interested in using PWM to vary the speed. (I know this board isn't for code, but its a very simple question I'm assuming)

int fan = 3;

void setup() {
  Serial.begin(9600);
pinMode(fan, OUTPUT);
}

void loop() {

analogWrite(fan, 1023);
}

This however will not spin with lower values, I get a 9 second gap of no spinning of the fan. The fan will not spin even with a manual push.

int fan = 3;

void setup() {
  Serial.begin(9600);
pinMode(fan, OUTPUT);
}

void loop() {

analogWrite(fan, 1023);
delay(3000);
analogWrite(fan, 0);
delay(3000);
analogWrite(fan, 512);
delay(3000);
analogWrite(fan, 0);
delay(3000);
}

Sorry, here’s the circuit

A 12V dc fan isn't a simple load, its a BLDC motor driver circuit with decoupling caps reading hall sensors and commutating a 2 or 3-phase BLDC motor.

You can't just PWM the supply to such a circuit. If you want to vary the speed get fans with a speed control input.

schematic is wrong the diode has to be linked to the motor connectors, not the transistor

PC fans don't take a great deal - about 120mA at 12v, so 8 would be about an amp..

so if you put a lowpass filter after the PWM followed by a gain-of 2.5ish linear power amplifier, it would work.

Inefficient - but you may not care, - and you might be able to use another fan to cool the heatsink which would be necessary!

regards

Allan

Cylindric: Yeah, the diode there is a silly mistake. I only used a 317 because that's what I had lying around.

And the 1k base resistor too? 150 ohm would be more normal.

8 fans are going to take a lot of current - is a BJT going to hack it? Perhaps a MOSFET is needed.