Tachometer using Arduino Uno and IR sensor

    Introduction

    In my older post, i have created a tachometer using A3144 and Arduino Uno that works perfectly fine with some limitations. If the environment is magnetic, the hall sensor A3144 gets undesirably triggered by the magnetic field created in the stator winding. To measure the speed, magnet is attached to the rotating part(generally wheel) and hall sensor is mounted near to it(generally the frame to which the wheel is attached) that senses the presence of magnetic field and sends  the signal to the micro-controller. The advert effect is obvious, when there is no wheel attached to the target motor and we need to measure the speed of motor by attaching the magnet to the rotor.
    To overcome this issue, a new tachometer is designed using IR sensor that promises to measure the RPM in the range of 60 RPM to 7800 RPM. In this post, detailed steps are discussed. 

    Modules Needed

    MT3608 boost converter is used to boost the 3.7V of Li-ion cell to 7V As arduino needs 7V at Vin pin to get powered up.
    MT3608 boost converter(input = 2-24V and output = 2A@5-28V)
    Power switch is used to turn ON/OFF the device power. It is connected in red wire from the cell.
    Power Switch
    Arduino Uno sends the RPM value to the OLED display. As you turn ON the switch OLED will show some dots indicating that the module is initializing. If the message on the screen is "SLOW!" that means the rpm of motor is out of range/motor is not running.
    SS1306 OLED display

    2200mAh battery is used to power up this module. To calculate how long will module can operate on this cell, we need to find out the current drawn by the module, say 200mA. Then the module can be powered upto 2200mAh/200mA = 11h.
    Li-ion cell

    Arduino Uno is responsible to receive the signal from IR sensor and to display the RPM on the OLED display screen.
    Arduino Uno

    Module Interconnection

    Li-ion ---->>>Boost converter ---->>>power switch ---->>>Arduino ---->>>(OLED display, IR sensor)

    Connection:
    1. Connect -ve of cell to Boost converter -ve Vin.
    2. Connect +ve of cell to Power switch.
    3. Connect another wire of power switch to the +ve Vin of Boost converter.
    4. Connect -ve Vout of Boost converter to GND of Arduino.
    5. Connect +ve Vout of Boost converter to Vin of Arduino Uno dev board. 
    6. Connect IR sensor and OLED VCC pins to Arduino 5V.
    7. Connect IR sensor and OLED GND pins to Arduino GND.
    8. Connect IR senosr signal pin to the Arduino D2 pin.
    9. Connect OLED SCL pin to the Arduino SCL pin.
    10. Connect OLED SDA pin to the Arduino SDA pin.

    Now connect the Arduino Uno board with USB Serial cable to the Laptop and burn below code.

    Code

    #include <Arduino.h>
    #include <U8x8lib.h>
    #include <SPI.h>
    #include <Wire.h>
    U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
    unsigned long rpmtime;
    float rpmfloat;
    unsigned int rpm;
    bool tooslow = 1;
    
    unsigned int ir_sensor = 2;
    void setup() {
      u8x8.begin();
      u8x8.setFont(u8x8_font_profont29_2x3_f);
    
      //init message
      delay(1000);
      u8x8.clear();
      u8x8.drawString(1, 0, ".");
      delay(1000);
      u8x8.clear();
      u8x8.drawString(1, 0, "..");
      delay(1000);
      u8x8.clear();
      u8x8.drawString(1, 0, "...");
      delay(1000);
      
      TCCR1A = 0;
      TCCR1B = 0;
      TCCR1B |= (1 << CS12); //Prescaler 256
      TIMSK1 |= (1 << TOIE1); //enable timer overflow
      
      pinMode(ir_sensor, INPUT_PULLUP);
      attachInterrupt(digitalPinToInterrupt(ir_sensor), GET_TIMER_COUNT, FALLING);
    }
    ISR(TIMER1_OVF_vect) {
      tooslow = 1;
    }
    
    void loop() {
      delay(1000);
      if (tooslow == 1) {
        u8x8.clear();
        u8x8.drawString(1, 0, "SLOW!");
      }
      else {
        rpmfloat = 120 / (rpmtime/ 31250.00);
        rpm = round(rpmfloat);
        u8x8.clear();
        u8x8.setCursor(1,0);
        u8x8.print(rpm);
      }
    }
    
    void GET_TIMER_COUNT() {
      if(TCNT1 > 500){      //this line can be removed if your IR is properly tuned.
        rpmtime = TCNT1;
        TCNT1 = 0;
      }
      tooslow = 0;
    }

    Possible problems during testing of this project

    1. "SLOW" message and 14448 are being displayed =>> properly tune the IR sensor resistor. To tune the resistor first rotate the nob in the direction where the LED at IR sensor is not blinking and turned OFF even if we brings our hand in-front of the IR sensor. Now rotate the resistor nob in the other direction and stop when the IR sensor starts detecting the presence of hand, LED at IR sensor board will be OFF and gets ON when your hand is detected.
    2. Unable to measure RPM below 60 =>> your clock speed of micro-controller is 16MHz. At 8MHz it can measure RPM minimum to 30. This is because the counter overflows in 1sec for 16MHz clock and 2sec for 8MHz clock.

    Working Module Images

    Tachometer Module

    Tachometer ready to measure RPM

    Tachometer back side

    Stay tuned for new articles and updates; keep visiting.

    Comments