-
Notifications
You must be signed in to change notification settings - Fork 0
/
fan_pwm_test.ino
42 lines (33 loc) · 816 Bytes
/
fan_pwm_test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//http://www.beefrankly.org/blog/2011/12/21/read-out-4-pin-cpu-fan-speed/
int fanPulse = D3;
int fanControl = D2;
unsigned long pulseDuration;
int p = 0;
void setup()
{
Serial.begin(9600);
pinMode(fanPulse, INPUT);
digitalWrite(fanPulse,HIGH);
pinMode(fanControl, OUTPUT);
}
void readPulse() {
pulseDuration = pulseIn(fanPulse, LOW);
double frequency = 1000000/pulseDuration;
Serial.print("pulse duration:");
Serial.println(pulseDuration);
Serial.print("time for full rev. (microsec.):");
Serial.println(pulseDuration*2);
Serial.print("freq. (Hz):");
Serial.println(frequency/2);
Serial.print("RPM:");
Serial.println(frequency/2*60);
}
void loop()
{
analogWrite(fanControl,1200);
delay(5000);
readPulse();
analogWrite(fanControl,200);
delay(5000);
readPulse();
}