Simple PWM Fan Speed Control

As the title says, I want to control the fan speed of a PWM Noctua 140mm Fan using an Arduino UNO.
My application simply requires me to be able to change the fan speed/RPM from completely off, to some intermediate values, to max speed.

My current equipment is:

Benchtop Power Supply
Arduino UNO
PWM Noctua Fan
Wires

With respect to the wiring, I know that the 4-wires in my PWM fan correspond to the following:
BLACK---GND
YELLOW---12V
GREEN---TACHOMETER
BLUE---PWM

Therefore, I connected the BLUE wire into the Number 3 Pin in the Digital I/O portion of the Arduino UNO. (I've also tried to connect the PWM wire to the 5,6,9,10, and 11 pins but to no avail)
The GREEN wire is currently unused. The YELLOW wire is connected directly to my power supply. The BLACK wire is currently connected to the power supply and I have also ensured that the Arduino shares a common ground with it.

This guy is basically doing what I'm trying to accomplish in this video:

My project is much simpler than what he did. First of all, I just need to control 1 fan instead of the 5 fans he did. Second, I have no need for the LED part he used.

I took his source code, which can be found here: (arduino-pwm-fan-serial-control--for-tuning-/fan_serial_commander.ino at master · catalystoftechnology/arduino-pwm-fan-serial-control--for-tuning- · GitHub)

And modified it to better suit my project. This is the code I used:

int fanSpeed = 0;
String command;
char werd;
int currentFan = 0;
int fan = 6;
int frontSpeed = 0;
int commandCheck;
String frontMarker = "-> ";

void setup() {
  pinMode(6, OUTPUT);
  analogWrite(6,0);
  Serial.begin(9600);
  Serial.println();
}

void loop(){
  while ( Serial.available() > 0 ) {
    delay(5);
    werd = Serial.read();
    command += werd;
  }
  Serial.flush();
  if ( command.length() > 0 ) {
    commandCheck = 0;
    if ( command == "front" ) {
        currentFan = 0;
        frontMarker = "-> ";
    } else {
        commandCheck = 1;
    }
    if ( commandCheck == 1 ) {
      if ( currentFan == 0 ) {
        //front
        analogWrite(fan, command.toInt());
        frontSpeed = command.toInt();
      }else {
      }
    }
    command = "";
    Serial.print(frontMarker);
    Serial.print("Front: ");
    Serial.println(frontSpeed);
    clear();
  }
}

void clear() {
  Serial.println();
}

I've gone through a myriad of variations on that code and others that I've found online but none seem to work.

First, I connect my fan, Arduino and PSU as stated above. Then, I give my fan 12V with the PSU which causes the fan to start rotating. Then, I upload the code into the Arduino UNO.
I've tried both his code and mine. When I go to the Serial Monitor I can change the numerical value of the speeds just fine. However, I observe absolutely no change in the speed of the fans regardless of the value I input in the serial monitor.

Please let me know any suggestions, corrections, and/or ideas you have. I'm currently at a standstill with this, and has halted my research. This is my first time using Arduino so I'm still getting used to the syntax and the electronics, so I apologize if I ask any elementary questions.

Thank you in advance for any and all help!

Enter "4-pin fan" in the search box on top of this page.
4-pin fans should be controlled with a ~25khz PWM signal.
Google for the "Intel CPU fan (pdf)". That doc. explains why 4-pin fans are different.
Leo..

I've checked that thread already and I'm familiar with the Intel datasheet. I know that the PWM fan needs to run at 25kHz already...

Most of the threads on PWM fan control revolve around temperature since many of those applications are to be implemented into a computer case. That's not what I need. I've also tried the codes in several of these threads but have been unsuccessful thus far.

I needed help with corroborating that the code I provided is indeed correct because in the Youtube link I provided a more sophisticated setup was used successfully without the need of the temperature control. If there is a problem with the code then I can move on to determining if I need additional electronics.

Can anyone check if the code I provided above will allow me to input values to change the fan speed? Any modifications that can be made to the code to allow me to turn off the fan? Since the fan will always be connected to a PSU I can simply kill the voltage when I need the fan off, but it would be nice to be able to control it, if possible, through the computer.

Thanks

Squaraine84:
I know that the PWM fan needs to run at 25kHz already...

Maybe the fan doesn't like the 980Hz PWM generated on pin 6 by analogWrite()?

I've checked that thread already and I'm familiar with the Intel datasheet. I know that the PWM fan needs to run at 25kHz already...

OK, then break this project into smaller pieces.

  1. Learn how to set up Timer 2 (controlling pwm on pin3) for 25khz, and write a simple sketch controlling the fan with analogWrite(3, dutycycle) which will run the pwm at the timer's preset frequency.

  2. Learn how to control a relay or transistor to to turn the power to the fan on and off.

  3. Finally, work on the Serial input to set the duty cycle and to turn the power on and off. Take a look at Robin2's excellent tutorial on serial input basics.

What he said ^.
Another alternative, if you don't feel competent to tackle timers just yet, is to take a look at the "PWM Frequency" library.
There's a bit of info and a link to it in this thread:-
PWM Frequency Library

Gotcha.

I'll break it down into smaller projects and try to bring them together.

I think I have a good idea on how to control the relay. The timer and Serial Monitor portions will probably be more challenging for me at the moment, so I'll read more and experiment with those.

I'll post an update in about a week or so after I do more reading and get my components.

Thanks! :slight_smile:

P.S

In case anyone is curious, here is a design of the application I'm working in. I basically want to coat solar cells using various conducting polymers while exposing the films to various wind speeds during the film formation process. I already have the wind chamber made. I'm already able to control the blade speed, blade height, and blade contact force via the computer using a couple of servo motors and a force sensor. I'm also able to control the temperature of my substrate platform using a couple of heating cartridges. I will be monitoring the wind speed using two different anemometers: a vane anemometer and a hot-wire anemometer. They have different sensitivities so I'm using them in tandem to kinda calibrate each other out. I will eventually add a solvent bubbling system that will allow me to saturate the wind chamber with different substances that will hopefully change the thermodynamics of film formation. I have also included he ability to take various spectroscopic measurements in situ in order to determine the absorbance, photoluminescence, external quantum efficiency, etc. of my films as they are being made. This will be pretty cool because it'll allow me to see how optical properties change DURING the film formation process.

I was using some 3-pin fans before where I was just changing the supply voltage to change the air flow but I learned about PWM fans and figured that I could get more tunability with them.

Cheers!

2 Likes

There is one thing, you need to learn about air flow.
What comes out of a fan is not straight air.
It comes out in a vortex or spinning flow from the fan.
Air is also effected by the Bernoulli effect.
What that means is that the nice rotation vortex will usually
choose one of the edges of your box and flow down that surface.
It may even oscillate around the edges.
Moving air is funny stuff.
If you want smooth moving air across the width of the box,
you need to put vanes in there to straighten and direct the air.
You also need something to restrict the flow some so it is
uniform across the box.
Without that, you may find places in your box that the air
is even flowing backwards, towards the fan.
Squirrel cage blowers are much more friendly for producing
uniform air flow.
Dwight

Hello,

I would like to share my experience here as I'm working on a similar project.

In my case I need to turn on four 4-pin PWM fans (12V) at the same time using different protocols. More specifically they need to be turned on at max speed for 6 seconds, or gently increase their speed from relative 0% to 100% during a 30s period (considering that <30% of PWM is insufficient to start up the fan).
The specs of the fans I'm using also says that they need a 21-28 kHz PWM signal so I struggeled for a few days on how to change the timers. At some point I figured out that there was a grounding issue in my circuit that prevented the PWM signal to affect the rotational speed (yes, stupid error..).
Long story short: I gave up trying to modify the timer and did a last try using the ~500 Hz PWM of the Arduino with the analogWrite function and it worked!

So apparently these relatively new fans are smart enough.

Concerning the project design, I agree with dwighthinker. In fact in my project I initially wanted to convey the airflow generated by the fan into a smaller cylinder using some sort of funnel but could basically not have any airflow where I wanted, most of the air was going backwards and "spilling" over from the back. Fluid dynamics is really a tough thing...

Good luck with your project!

Best,
S

Save_Morello:
...considering that <30% of PWM is insufficient to start up the fan).

4-pin fans (should) have a controller inside with a smart start-up sequence.
Google "intel 4-wire cpu fan pdf"

Save_Morello:
The specs of the fans I'm using also says that they need a 21-28 kHz PWM signal...

...I gave up trying to modify the timer and did a last try using the ~500 Hz PWM of the Arduino with the analogWrite function and it worked!

25kHz is used to get fan noises (knocking/whining) outside our hearing range.

Save_Morello:
So apparently these relatively new fans are smart enough.

4-pin "intelligent" fans are not new. They were used for CPUs since I can remember, 3-pin fans are known as case fans.
Leo..

Thank you for completing/correcting my entry.

Wawa:
4-pin fans (should) have a controller inside with a smart start-up sequence.
Google "intel 4-wire cpu fan pdf"

Then my fan does not have it. According to that PDF (and many other topics that refer to it) I should have changed the PWM frequency to have my fans working.

Wawa:
25kHz is used to get fan noises (knocking/whining) outside our hearing range.

I always heared that knocking/whining sound when the PWM signal was applied directing to the + pole of the fan, but never in a 4-pin fan. Moreover, that fan noise was well above the ~500Hz of the Arduino PWM.

Wawa:
4-pin "intelligent" fans are not new. They were used for CPUs since I can remember, 3-pin fans are known as case fans.

That's why I wrote "relatively".

Then I guess I'm just lucky that my fans are not producing any noises...