Not able to run fan at full RPM when using PWM with Uno

I’m trying to build a simple fan controller with Arduino capable of changing the RPM of a 4-pin computer fan that supports PWM. Here is a link to the fan I’m using.

I have connected a 12 V power supply to the fan via the black (-) and yellow (+) cable of the fan. The blue fan cable is connected to pin 3 of an Arduino Uno. Additionally, the ground of my 12 V power supply is also connected to the ground pin of the Uno such that the fan and Uno shares a common ground.

To test the PWM I’m using the following sketch that I found on this forum:

word FanPin = 3;

void setup() {
  pinMode(FanPin, OUTPUT);

void loop() {
  pwmDuty(0);  // 0 %
  pwmDuty(19); // 25 %
  pwmDuty(39); // 50 %
  delay (5000);
  pwmDuty(59); // 75 %
  delay (5000);
  pwmDuty(79); // 100 %
  delay (5000);

void pwm25kHzBegin() {
  TCCR2A = 0;                               // TC2 Control Register A
  TCCR2B = 0;                               // TC2 Control Register B
  TIMSK2 = 0;                               // TC2 Interrupt Mask Register
  TIFR2 = 0;                                // TC2 Interrupt Flag Register
  TCCR2A |= (1 << COM2B1) | (1 << WGM21) | (1 << WGM20);  // OC2B cleared/set on match when up/down counting, fast PWM
  TCCR2B |= (1 << WGM22) | (1 << CS21);     // prescaler 8
  OCR2A = 79;                               // TOP overflow value (Hz)
  OCR2B = 0;

void pwmDuty(byte ocrb) {
  OCR2B = ocrb;                             // PWM Width (duty)

According to the forum post where I found the code the pwmDuty function takes an integer between 0 an 79 as input when controlling the fan.

My setup and the code sort of works in the sense that the speed of the fan increases when I run the code. However, even at pwmDuty(79), which should correspond to the highest possible RPM, the fan is not running anywhere near its maximum speed. I haven’t measured the RPM but I would estimate that it is running at about half speed (I know what the fan looks/sounds like when running at full RPM).

I have also tried other PWM sketches I found on various forums but none of them appears to set my fan to its maximum RPM.

Could anyone enlighten me on what I need to do in order to reach full RPM when controlling my fan with PWM?

Have you already tried the simple analogWrite()?

What happens if you connect the PWM input to Gnd (should stop) and Vcc (max. rpm)?

Can I run 4-pin PWM fans on 3-pin fan headers?PWM fans come with a 4-pin connectors for fully automatic speed control via your mainboard’s 4-pin PWM fan headers. Please note that 4-pin fans can also be connected to your mainboard’s 3-pin fan headers though. When connected to 3-pin fan headers, the fan will run at full speed (unless the mainboard supports voltage based speed control).

I have to wonder if you give it enough 12V to actually run the fan at 1200RPM? Fans can be power hogs.

Have you already tried the simple analogWrite()?

What happens if you connect the PWM input to Gnd (should stop) and Vcc (max. rpm)?

Thank you for the advice, I tried it and it still would not produce full RPM. So I tried a different fan of the same model and it worked with the same setup! So the mystery has been solved it seems, my issue was that the fan I was testing was defective. Thanks for the simple yet effective idea