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);
pwm25kHzBegin();
}
void loop() {
pwmDuty(0); // 0 %
delay(5000);
pwmDuty(19); // 25 %
delay(5000);
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?