Three wire fan

Objective: measure the rotational speed of a three wire DC fan

You will need: Arduino UNO (or similar), three-wire DC fan, I2C LED display, 10kΩ resistor, breadboard and patch cables.


Many small DC brushless fans have a third wire that transmits pulses that can be used to calculate their rotational speed. The output lead is connected to a 10kΩ resistor and then to a digital input pin on the Arduino that is configured as an interrupt pin. More on interrupts.

A note on interrupt pins

The Uno has two pins that can be used for interrupts, digital pins 2 and 3. These correspond to interrupt identifiers 0 and 1 respectively. It's good practice to use the digitalPinToInterrupt() function to convert from the digital pin number to the interrupt identifier. You'll need to do this if you wish to port the sketch to a different model of Arduino.

The interrupt pin must be pulled high because the fan pulls the signal low, usually twice per revolution, and this can then be counted by the Arduino and the speed calculated.

When you call pinMode(), set the pin to INPUT_PULLUP and when setting up the interrupt, set that to FALLING.

A 7-segment LED display is used to display the fan speed in RPM. This is connected to the Arduino using I2C to minimise the number of connections required.

Link to sketch source code.

Exclamation mark If you are writing your own sketches and use millis() or micros(), you need to ensure that any variables that are given a value by those functions have the same type, that is, unsigned long. If you're checking for a difference in time you need to remember that millis() and micros() will overflow and go past zero after about 50 days and 70 minutes respectively. If your sketch is expected to run longer than these times, you will need to accommodate the overflow.

The corresponding Fritzing diagram is below.

Fritzing diagram