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 PC fan I have selected outputs RPM signals on its yellow wire. This signal can be used to tell fan controllers or motherboard inputs how fast the fan's blade is tunring. In our case we are going to use this to tell the Arduino how fast the fan is spinning. In fact you can plug the signal wire to the CPU fan header on a motherboard and set the BIOS so that if the fan ever 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 fan is running than knowing your CPU wont melt if it dies right?

Wiring things up!

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 http://thebestcasescenario.com for his help with the code.

//code by Crenn from http://thebestcasescenario.com //project by Charles Gantt from http://themakersworkbench.com //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; }fanspec; //Definitions of the fans //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 fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1; void rpm () //This is the function that the interupt calls { NbTopsFan++; } //This is the setup function where the serial port is initialised, //and the interrupt is attached void setup() { pinMode(hallsensor, INPUT); Serial.begin(9600); attachInterrupt(0, rpm, RISING); } void loop () //Set NbTops to 0 ready for calculations { NbTopsFan = 0; //Enables interrupts sei(); //Wait 1 second delay (1000); //Disable interrupts cli(); //Times NbTopsFan (which is apprioxiamately the fequency the fan //is spinning at) by 60 seconds before dividing by the fan's divider Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Prints the number calculated above Serial.print (Calc, DEC); //Prints " rpm" and a new line Serial.print (" rpm\r

"); }

You should see an RPM output in the Arduino IDE's serial terminal. It is roughly 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.

If you like this tutorial, and would like to see more like it, consider visiting our Patreon page and donating to help us keep TheMakersWorbench.com up and running! You can also support us by using the Amazon.com search bar in the left-hand sidebar on the homepage, or by clicking on and purchasing any of the hardware items we listed during this tutorial!