help me chose the right sensor please

i want to make speed meter with arduino but i need for very high speed motor (( water pump motor 2hp ))
so what should i use IR sensor or hall effect sensor
if IR sensor i use one like that ->

and i use that code->

#include <LiquidCrystal.h>
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int encoder_pin = 2;  // The pin the encoder is connected           
unsigned int rpm;     // rpm reading
volatile byte pulses;  // number of pulses
unsigned long timeold; 
// The number of pulses per revolution
// depends on your index disc!!
unsigned int pulsesperturn = 20;

 void counter()
 {
    //Update count
      pulses++;    
 }

void setup()
 {
   lcd.begin(16, 2);
   Serial.begin(9600);
     //Use statusPin to flash along with interrupts
   pinMode(encoder_pin, INPUT);
   
   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, counter, FALLING);
   // Initialize
   pulses = 0;
   rpm = 0;
   timeold = 0;
 }

 void loop()
 {
   if (millis() - timeold >= 1000){  /*Uptade every one second, this will be equal to reading frecuency (Hz).*/
 
  //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*pulses if the interrupt
   //happened once per revolution
   rpm = (60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses;
   timeold = millis();
   pulses = 0;
   
   //Write it out to serial port
   Serial.print("RPM = ");
  lcd.setCursor(0,0);
   lcd.print("RPM = ");
   Serial.println(rpm,DEC);
   lcd.print(rpm,DEC);
   //Restart the interrupt processing
   attachInterrupt(0, counter, FALLING);
   }
  }

but when arduino work the lcd give me read till 700 RPM the back to zero
i want know if the problem here from sensor or the code
i so sorry for my bad english

Easiest: an encoder. Those things can be connected the shaft and are meant to measure the rotation.

That failing: a small magnet on the shaft, and a hall effect sensor, to count complete rotations (for your purpose probably good enough).

IR sensor may also work but you need a break beam type, preferably using modulated IR to not be affected by ambient light.

how much rpm does the motor do?

1-> Easiest: an encoder. Those things can be connected the shaft and are meant to measure the rotation.

my english bad so can you explain more please

2-> That failing: a small magnet on the shaft, and a hall effect sensor, to count complete rotations (for your purpose probably good enough).

that mean hall effect sensor maybe good more than IR sensor

3->IR sensor may also work but you need a break beam type, preferably using modulated IR to not be affected by ambient light.

what you mean with (( break beam type ))

4->how much rpm does the motor do

i donot know that why i want make speed mater but i think alot maybe more than 5000RPM maybe more

sorry for long time to reply
sorry for my bad english
thanks for help

LMGTFY.
encoder
Break beam sensor

Hall effect sensor has the advantage of less problems with dirt.

A magnet attached to the shaft may cause problems due to instability at 5000 rpm. It has got to be attached firmly to not fly off. A small hole in the shaft, or two notches (opposite sides) for a break beam sensor would be balanced.

Your motor specs should indicate the maximum free running speed it can do. This is important to know as you have to design your detection method based on this value.

A 2 pole AC induction motor runs near 3000 RPM at 50 Hz, near 3600 at 60 Hz, a 4 pole runs at half those speeds, what type of motor do you have?

1> lmgify = let me google it for you that right ??

any way i never read about the Rotary encoder so sorry

2> thanks for the now data but for the IR break beam why i think that the same idea of ir i talk be for but here the moving parts will cut the ir light not reflex it

3> what type of motor do you have

2hp water pump motor like that >> https://www.alibaba.com/product-detail/centrifugal-water-pump-of-2hp_60563282132.html?spm=a2700.7724857/B.main07.9.20c6576fSmtpDy&s=p

4> for hall effect if my motor run under 5000 rpm that mean will work good ??

The link you posted says RPM is 2850 and power is 1.1 kW (1.5 hp), the RPM of an AC induction will not vary much from full load to light load, maybe 100 RPM or 3%. I don't see the point in measuring it.

that is mean hall effect will run good or ir break beam sensor
ok thanks for help and explanation

elsayed_ayman:
4> for hall effect if my motor run under 5000 rpm that mean will work good ??

That is not a magic limit or so. At 5000 rpm it may still work fine, it's just that you have to know what you're doing when modifying a system. Fast rotating systems require a proper balance or bad things may happen, and at speeds of 5000 rpm a small imbalance may become very noticeable.