RPM Measurement using Arduino

Hello all ! In this short article I would love to share an old project of mine which is regarding measurement of the speed of CPU fans using the popular Arduino lineup of development boards

Tinkering across quite a few CPU cooling fans I often found that there are more than 2 wires that usually goes to the motherboard or the control unit of any electronic equipment, often 3-4 wires and I wondered what do the extra wires signify apart from the obvious power cables. Upon researching more ,I found out that these are actually linked to a Hall effect sensor and in some cases the additional wire was also lined to a thermistor to determine the temperature of the in-coming or out-going air. These types of CPU fans come in all shapes and sizes and are not restriced to just use in laptops or desktops.

Here I teardown one such miniature exhaust fan to understand it's basic working and then use the popular Arduino Nano to measure the speed of rotation using the fan's inbuild hall sensor and display the values on an OLED screen.

The Coding..

The video pretty much explains the connections to and from the Arduino with the fan and the OLD display. In this section I have posted the code that I have used for the demonstration

You will be needing a couple Adafruit Libraries in order to make the OLED display work correctly with the Arduino. However, you are free to use whatever kind of display you feel comfortable to use. The link to the Library is:SSD1306 LibraryAdafruit GFX Library

The code definitely needs to be modified with respect to the type of fan and the display you are using

If you are using the exact setup as I am, then feel free to use this code..


    #include <SPI.h>
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    #define OLED_RESET 4
    Adafruit_SSD1306 display(OLED_RESET);
    int tON=0;
    int tOFF=0;
    int Tperiod=0;
    int freq=0;
    int RPM=0;
    void setup() 
    {
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
    display.display();
    delay(1000);
    display.clearDisplay();
    display.setTextSize(1);
    display.setCursor(0, 0);
    display.setTextColor(WHITE);
    pinMode(3,OUTPUT);
    }
    
    void loop() 
    {
    tON=pulseIn(3,HIGH);
    tOFF=pulseIn(3,LOW);
    Tperiod=tON + tOFF;
    freq= 1000000.0/ Tperiod;
    RPM=freq * 15;
    if(digitalRead(3)==HIGH)
    {
    display.clearDisplay();
    display.setCursor(0, 0);
    display.print("RPM  METER ");
    display.setCursor(0, 10);
    display.print("Frequency: ");
    display.print(freq);
    display.println(" Hz");
    display.setCursor(0, 20);
    display.print("RPM: ");
    display.print(RPM);
    display.display();
    delay(1000);
    display.clearDisplay();
    }
    tON=0;
    tOFF=0;
    Tperiod=0;
    freq=0;
    RPM=0;
    }