a 4-pin PWM fan is not controlable!

I have written a simple PWM code for a 4-pin fan. The code is working since an LED shows that the correct values are sent to the PWM port

Full code is:

#include <LiquidCrystal.h>

// Fan sens (tach) wire connected to digital_8 port
int fanSens = 8; 

// Fan PWM wire connected to digital_9 port
int fanPWM = 9;

// Middle pin of LM35 connected to analog_A1 port
int tempPin = 1;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void showRPM() {
  unsigned long pulseDuration = pulseIn(fanSens, LOW);
  double frequency = 1000000/pulseDuration;
  lcd.setCursor(5, 1);  // fifth column on the second row
  lcd.print(frequency/2*60);
}

void setup()
{
  pinMode(fanSens, INPUT);
  digitalWrite(fanSens,HIGH);
  lcd.begin(16,2);
  lcd.setCursor(0, 0); // cursor at top left
  lcd.print( "TMP:" );
  lcd.setCursor(0, 1);  // cursor at bottom left
  lcd.print("RPM:");
}

void loop()
{
  float val = analogRead(tempPin); 
  float mv = (val/1024.0)*5000;
  float cel = mv/10; // this is the celcuis

  lcd.setCursor(5, 0); // fifth column on the first row
  lcd.print( cel );

  analogWrite(fanPWM, 0);
  delay(8000);
  analogWrite(fanPWM, 1);
  delay(4000);

  showRPM();
  delay(500);
}

The LED is OFF for 8 seconds and is in LOW ON with value 1 for 4 seconds.

The fan is a 4-pin PWM for a TYAN server. You can see the official picture here and mine here and here.

The pin description is available at TYAN website. I paste the picture of that page as an attachment. Please note that the header is not standard!

According to the manual, the fourth pin is PWM. The LED is also connected to that pin. However, by running the code and attaching the fan, I see that it is constantly running while is LED is OFF for 8 seconds.

I posted a video of its abnormal functionality, here. Please check it.

You can see that the blue wire of the fan is connected to a purple wire and that is connected to PWN pin (9) of the Arduino.

Is there any idea about that weird functionality?!

Untitled.jpg

From what I remember from my halcyon PC-building days, 4-wire fans were controlled as you described: 12v and GND plus a PWM input on pin 4 and a SENSE or TACH on pin 3.

Thus you could test the fan by supply the 12v and GND (nothing should happen) then supply 5v (via a small resistor say, 100R) to the PWM pin and the fan should spin at full speed.

Have you got this bit working? If so, then supplying a standard Arduino PWM signal to PWM pin 4 should work.

I don't know what your LEDs are for (apart from visual feedback?) but they are muddying the water as far as your coding goes (or my understanding of it) and I would remove them for now. And simplify your code.

I have two YouTube videos #14 and #15 too (the next video) that cover PWM in various ways (you may want to fast forward to the fan control and skip the LED control) but it's all good viewing and may help you move forward. URL in the signature of this post.

Have you got this bit working? If so, then supplying a standard Arduino PWM signal to PWM pin 4 should work.

I supplied +5, +7, +9, +12V to the VCC and saw that the fan speed increased. I didn't use the PWM pin

I don't know what your LEDs are for (apart from visual feedback?)

Yes. Just what to be sure that the PWM pin is working correctly

ut they are muddying the water as far as your coding goes (or my understanding of it) and I would remove them for now. And simplify your code.

yes. Because that complete code is a working one to read the temperature and decide the fan speed and that is working fine for another 4-pin fan.

  analogWrite(fanPWM, 0);
  delay(8000);
  analogWrite(fanPWM, 1);
  delay(4000);

There isn't much difference between a PWM value of 0 or 1. :wink: Try 255 to see if it's inverted.

...and that is working fine for another 4-pin fan.

If another fan is working as expected, the non-working fan could be bad, it could be wired differently, or it might be designed to work differently.

mahmoodn:
I supplied +5, +7, +9, +12V to the VCC and saw that the fan speed increased. I didn't use the PWM pin

Mmm, not sure whats going on here - no PWM input but the fan still went round?

Incidentally, the PWM frequency for 4-wire fans is usually in the order of 25kHz not the 490Hz that the Arduino delivers by default (I describe how to increase the default in my video that I mentioned).

Have you read the Intel 4-Wire Fan Control Specification ?

(Why is it so hard to add a working link here?)

http://www.formfactors.org/developer\specs\rev1_2_public.pdf

If you look at section 2.4, page 9, it says that:

The following requirements are measured at the PWM (control) pin of the fan cable connector:
PWM Frequency: Target frequency 25 kHz, acceptable operational range 21 kHz to 28 kHz

The Arduino PWM frequency is 490/980 Hz.

I think that it is this difference in frequencies that is causing your problems.

There are ways to alter the PWM frequency, maybe someone else can help with this.

​