Yet Another 4-Pin PWM Fan Control Question

Hello all,

This is my first post here so please tell me/forgive me if I screw something up.

I have been banging my head against a wall for hours trying to get my Mega to control a 4 wire PC fan via PWM.

I have installed every library I can find and tested ever block of code, but the best I can get the fan to do id drop to it's minimum speed. It won't adjust anywhere in between high and low.

I've tried multiple different fans and multiple different frequencies (some of the code I've found allows for easy adjustment) but nothing seems to work.

I'm a total newb with a knack for logic but a lack of brain power sufficient to really dive deep enough to understand what happening in the background in order to actually make this work.

If anyone can be of any assistance I sure would appreciate it.

Which of the hundreds of different 4 wire fans do you have?

i would suggest you write some code to use PWM to control the LED (pin 13?) on the Mega then trying connecting pin 13 from the Mega to the PWM input to your fan

Thank you guys so much for the replies.

JCA34F:
Which of the hundreds of different 4 wire fans do you have?

I have tried several so far, currently I have a Nidec BETAV TA450DC Model B35502-35 4 wire fan connected.
Red and black wires are connected to 12v+&- and the bleck is also connected to the ground of the Arduino.
White is connected to pin 9 for RPM sensing and blue is connected to pin 8 for the PWM signal.

I believe everything is connected correctly because the fan drops to a low speed when I load the code into the arduino. I've also tried switching the pins around in the code.

I have also tried other fans with no better results.

I just measured the frequency coming from the PWM pin with a cheap oscilloscope/muiltimeter and it reads at 24.95khz.

gcjr:
i would suggest you write some code to use PWM to control the LED (pin 13?) on the Mega then trying connecting pin 13 from the Mega to the PWM input to your fan

I could try this but after all the reading I've done I feel like the issue might be a bit more complex, plus the oscilloscope is reading a PWM signal from the pin.

Is there any particular reason you might think I should still try and operate an LED from pin 13?

If there are any more ideas out there I would greatly appreciate them.

This is the simplest bit of code I would find that at least drops the speed of the fan:

word VentPin = 8;

void setup() {
  pinMode(VentPin, OUTPUT);
  pwm25kHzBegin();
}

void loop() {
  pwmDuty(79); // 25% (range = 0-79 = 1.25-100%)
  Serial.println("25%");
  delay(5000);
  pwmDuty(79); // 50% (range = 0-79 = 1.25-100%)
  Serial.println("50%");
  delay (5000);
  pwmDuty(79); // 75% (range = 0-79 = 1.25-100%)
  Serial.println("75%");
  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)
}

I inserted the “Serial.println” portions to try and see when it was trying to change the speed but nothing shows up in the monitor.

You need a serial.begin in setup

plus the oscilloscope is reading a PWM signal from the pin.

Is there any particular reason you might think I should still try and operate an LED from pin 13?

if you're convinced the PWM signal fed to the fan is correct then is sounds like a hardware issue

seems to me if the fan has power, providing the max PWM voltage on the PWM should turn the fin on full speed

wildbill:
You need a serial.begin in setup

Ok, great, I will add that in.

gcjr:
if you're convinced the PWM signal fed to the fan is correct then is sounds like a hardware issue
seems to me if the fan has power, providing the max PWM voltage on the PWM should turn the fin on full speed

Yeah, it's really odd, though I've found a lot of people with the same issues.
I hesitate to think it's a hardware issue since the meter reads the PWM signal I'm trying to produce and I've tried multiple fans and the code above does drop the speed of the fan.

I'd love to get it working just with the arduino and a 4 pin fan but if I need to switch to a 2 pin fan and a motor controller I will...I just hate giving up.