Reading PC Fan RPM with an Arduino

Tutorial Type:

Tutorial Difficulty

Parts Required

  • Arduino
  • 3 Wire PC Fan
  • 10k Resistor 
  • Jumper Wires
  • Breadboard

Tools Required

Reading PC Fan RPM and Waterpump RPM with Arduino



Part 2: Reading Fan / Water Pump RPM

Today we are going to learn how to read the RPM of a PC Fan. This also works well for the Water Pumps used in PC Water Cooling as well as any dc pump or fan that has a rotation sense wire. This is accomplished by counting the falling edge of the square wave generated by the  Hall effect sensor that is located inside the fan or pump. All we have to do is use the arduino to do is count that data, do some math for us, and output the converted data onto an LCD Screen. Lets get started! 





The water pump I have selected outputs RPM signals similar to a standard three wire PC fan. In fact you can plug the signal wire to the CPU fan header on a motherboard and if your pump dies or stops sending a signal it will shut your PC down to prevent a CPU failure due to heat. While a nice feature for safety, it will be much cooler to see the RPM at which your pump is running than knowing your CPU wont melt if it dies right?

Since the Fan and Pump RPM signals are so similar, and my waterpump has not arrived yet I decied to dev using a 120mm PC fan. The following schematic should explain how to wire things up.

Fan RPM via Arduino


This is pretty simple to hook up. First you need to run the Signal wire (almost always yellow) to the breadboard. Then from it connect a jumper wire to Arduino Digital Pin 2. Also from the sensor wire you need to connect a 10k resistor to the Arduino's 5V pin. This is a simple pull-up resistor. We also need to make sure that we connect the fans ground line to one of the Arduino's ground pins. Next just connect the fans power wire to the PSUs 12v line and the fans ground wire to the PSUs ground.

Now upload the following code to your Seeeduino, and then open the serial terminal. Again I would like to thank Crenn from for his help with the code.

//code by Crenn from
//project by Charles Gantt from

/*To disable interrupts:
cli(); // disable global interrupts

and to enable them:
sei(); // enable interrupts

//Varibles used for calculations
int NbTopsFan;
int Calc;

//The pin location of the sensor
int hallsensor = 2;

typedef struct{ //Defines the structure for multiple fans and their dividers
char fantype;
unsigned int fandiv;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1; //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor
//and 2 for bipole hall effect sensor

void rpm () //This is the function that the interupt calls

//This is the setup function where the serial port is initialised,
//and the interrupt is attached
void setup()
pinMode(hallsensor, INPUT);
attachInterrupt(0, rpm, RISING);
void loop ()
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" rpm\r\n"); //Prints " rpm" and a new line

You should see an RPM output in the serial terminal. It is accurate within 10-15 RPM of the fans actual RPM which is close enough for me. If your RPM output seems to be double what it should be your fan may have a bipolar Hall efect sensor and its counting each pass of the magnets pole as a single RPM when each should be 1/2 an RPM.  No worries though as this is an easy fix. Just simply change the " char fan = 0 code from 0 to 1. Upload the modified code and you should be seeing accurate RPM numbers.



Other Articles You Might Like

Review: Lulzbot AO-100 3D Printer part 1Lulzbot AO-100 / AO-101 reviewed

Tutorial: DIY Telescope to PC CableDIY Telescope to PC Cable

Project: LED Strip Bench LightingDIY RGB LED Strip Bench lighting

Review: ISO-TIP Portable  Soldering KitISO-Tip Portable Soldering Kit Review

Article: Arduino Due Overview

Project: 3D Printed Balloon Powered CarPrint a Balloon powered Jet Car with your 3D printer