3
// This is a test program to see if we can read the RPM speed of a PC fan.
4
// To set up, the fan should have an independent 12V poer supply, and the
5
// fan's SENSE techiometer pin should be connnected to the Arduino's pin 2.
6
// The RPM is sent back via serial (over USB).
10
// set up interupt 0 (which is pin 2) and turn on the pull-up resistor as we
11
// would if the pin had been set to be an input. This is so that when the
12
// switch on the pin is open, it is not a floatin signal and has 5V across it
13
// (albeit through a high-resitance resistor to heavily constricy the
15
attachInterrupt( 0, rpmCounter, RISING );
16
digitalWrite( 2, HIGH );
22
static unsigned long fan_rotations = 0;
32
unsigned long start_millis = millis();
34
// display fan speed. We divide by 2 because the fan's "sense" pin actually
35
// pulses twice per revolution. We multiply by 60 because fan_rotations will
36
// have counted the number of rotations in a second and we want RPM.
37
// Serial.println( fan_rotations );
38
Serial.print( "RPM: " );
39
Serial.println( fan_rotations / 2 * 60 );
42
// wait until the remainer of a second has elapsed
43
delay( start_millis + 1000 - millis() );