DC motor control with absolute encoder

The catalog says that the 'BE' means an optical rotation sensor. The catalog says that the optical sensor gives 24 pulses per revolution. It is not an absolute encoder. It is not even a quadrature encoder. It will tell you how fast the motor is turning but not which direction. To measure speed, look for the time between pulses or the pulses over a time interval.

Blue is Ground
Orange is +5V Power
Yellow is pulse output

Here's some example code that might help in calculating RPM from the pulses:

volatile unsigned long time = 0;

const int countsPerRevolution = 4;

const int rpmCount = 5;
int rpmArray[rpmCount];
int rpmIndex = 0;
int rpmTotal = 0;

void setup()
{
  Serial.begin(115200);
  //Digital Pin 2 Set As An Interrupt
  attachInterrupt(0, fan_interrupt, FALLING);
  
  for (int i=0; i<rpmCount; i++)
     rpmArray[i] = 0;

  Serial.println("Current RPM:");
}

//Main Loop To Calculate RPM and Update LCD Display
void loop()
{
  int rpm = 0;
  if(time > 0) {
    rpmTotal -= rpmArray[rpmIndex];
    rpmArray[rpmIndex] = 60000000UL/(time * countsPerRevolution); 
    rpmTotal +=  rpmArray[rpmIndex];
    rpmIndex = (rpmIndex+1) % rpmCount;
    rpm = rpmTotal / rpmCount;
    Serial.println(rpm); 
    delay(1000);     
  }
}

//Capture The IR Break-Beam Interrupt
void fan_interrupt()
{
  static unsigned long time_last = 0;
  unsigned long now = micros();
  time = (now - time_last); 
  time_last = now;
}