Go Down

Topic: How do I control fan speed on 12V DC fan? (Read 81811 times) previous topic - next topic


Hey guys, i'm providing 12v external power to 3 12V DC fans that have a 3rd control line...what code should I use to control the fan speed? Thanks


Each fan has 3 wires(Red, Black, and the Yellow reserved for control) btw


Let's look at it this way...i have 1 fan with a red, black, and yellow wire coming out of it... i put the yellow wire into the arduino and the black and red into a power supply...what code do i need in order to control pin 7 to change the duty cycle...

i found this code but don't understand what variables to change:

void setup()
pinMode(7, OUTPUT);

unsigned char speed;
unsigned int low = 1;
unsigned int high = 10;
unsigned int baseTime = 10;

void loop()


if (Serial.available())
speed = Serial.read() - 48;
low = speed;
high = baseTime - speed;



That code is doing PWM control on digital pin 7, so either connect your fan control wire to digital pin 7, or change the "7" in the code to another pin.


my control line is connected to digital 7...do i need to use GND? or should the circuit be just control line to the arduino and + & - to the power supply?

what's the advantage of changing the pins?


Yes, you'll need to connect the fan ground to the Arduino's ground.  There's no special advantage to changing the pins, but that was what you asked about!


Lol, my apologies what i'm really asking is how to get this code to work...I have now connected the fan ground to the arduino ground...and i'm still not able to discern which variables i should change in order to change the fan speed...any thoughts?


are you sure the yellow line is for control? most fans i've seen put a pulse per revolution signal so you can measure the fan RPM.


labeled with a"C" so i assumed control...is there a way to do this with this mosfet: http://www.steelnerve.com/2N3771-D.pdf and wiring the arduino through the fet so as to provide 12V to the fan?

what's the best way to do this? the project i'm trying to achieve is this: http://www.youtube.com/watch?v=gxwFzfvi0DY&feature=related


I haven't seen any fans with separate control signals - certainly all PC fans with 3-wire interfaces have pulse-per-rev strobe on yellow ("Count"?). Control is via DC voltage level or PWM (the latter is better for low-speed control). Do a search for "3-wire fan", and look through some of the stuff returned.


Yep, every 12v fan I've ever seen with a yellow lead has been for RPM.


Ok well then in that case here are the fans i have

2 x Innovative. DC Brushless Fan Motor. Model BS501012V. DC 12 Volt 0,13A.
1 x CoolerMaster (50x50x10mm) Model: EFB0512HA Case Fan with 3-Pin

and i have the FET http://www.steelnerve.com/2N3771-D.pdf  

given the code provided, how SHOULD i be wiring things up and what do i need?


nd i have the FET http://www.steelnerve.com/2N3771-D.pdf

That is not  FET it is a transistor. Connect the base to the Arduino pin through a 1K resistor. Connect the emitter to ground, the -ve of the fan to the collector and the +ve of the fan to the 12v supply. Connect the -ve of the 12V supply to the Arduino ground.

As has been said the third wire is to measure the fan speed. If you want this can be incorporated into a feedback loop so that the measured speed controls the PWM but this requires  more complex software.


Ah, again to my aid Grumpy Mike, thank you :-p ...i shall work on this setup and get back as to the progress this evening



Hey, Don't have a 1K handy but i've got about 50 330s lol at 5% tol and 1/4W...no reason 3 of them in series won't work for now, right? Thanks

330 x 3 = 990ohms which is ~1K

Go Up