I am very new to working with the arduino and am trying to use some code from a youtube video to test a computer fan using pwm... I copied the code exactly as far as i can tell. I keep getting void error. People in comments say that the code works for them so i can only assume I'm typing something wrong. The channel is 'science fun' and the video is ' Arduino Fan Control using High Frequency 25kHz PWM // 4-Wire CPU Fans'.
Thankyou for any help.
const int fan_control_pin = 9; //Blue Wire on Fan (About 25kHz PWM)
int count = 0;
unsigned long start_time;
int rpm;
void setup() {
TCCR1A = 0; // undo the configureation done by...
TCCR1B = 0; // ...the Arduino core library
TCNT1 = 0; // reset timer
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // Undo default timers
TCCR1B = _BV(WGM13) | _BV(CS10); // for pins 9 & 10
ICR1 = 320; // PWM will be 0 to 320 instead of 0 to 255
pinMode( fan_control_pin, OUTPUT);
OCR1A = 0; // Set PWM to 0 out of 320 on pin 9
OCR1B = 0; // Set PWM to 0 out of 320 on pin 10
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(2), counter, RISING); // Yellow Wire
}
Void Loop() {
for(int pwm = 0; pwm <= 320; pw += 64) {
OCR1A = pwm;
delay(5000);
start_time = millis();
count = 0;
while((millis() - start_time) < 1000) {
}
rpm = count * 30; // 60/2 -------Spacing incorrect
Serial.print("PWM = ");
Serial.print(map(pwm, 0, 320, 0, 100));
Serial.print("% , Speed = ");
Serial.print(rpm);
Serial.println(" rpm");
}
}
Void counter() {
count++;
}