Just for fun, I decided to try the pulse counter in the Electric Imp.
The counter is quite easy to use, and seems to work pretty well too.
To count the pulses from the fan you first need to configure the pin to be a pulse counter, set the duration it should count, and then optionally set a divisor. In this example I set it to count pulses for 1.0 second, and divide the pulses by 2. This is because this fan (all I have come across actually), are giving off two pulses for each rotation. I am also only setting it to 1 second because while doing the .read(); it stops, counts, then continues, so if you wanted to read for 60 seconds to get all the pulses for one minute, it would stop there for one minute before continuing to do anything else again.
rpmDuration <- 3.0; //Define the duration of which we want to count pulses (notice, the imp will stop doing anything else during this time period)
hardware.pin1.configure(PULSE_COUNTER, rpmDuration, 2); //Configure pin1 as a pulse counter and divide by 2 (fan gives two pules for one rotation)
local pulseCount = hardware.pin1.read(); //Get the pulse count from the counter
pulseCount *= 60.0/rpmDuration; //Multiply by 60 divided by measure duration to convert rotations per second into rotations per minute
server.log("Fan is running at " + pulseCount + " rpm"); //Show what we got
imp.wakeup(60, rpmCalculate); //Do this again in 1 minute
rpmCalculate(); //Initial start of the function
If this just returns “Fan is running at 0 rpm” you might have to add a pull-up resistor between pin1 and the 3v3 pin. In my case I added a 10k resistor to get it to work.