Infra-red sensors are used in motors as shaft encoders to keep track of rotation
Inside a motor, there is usually an infrared sensors that works as either a reflectance sensor or as a break-beam sensors that is used to measure the amount of rotation of a motor. This is called a shaft encoder, and by using two sensors you can also have the direction of the rotation.
Break-beam shaft-encoders use a notched disk that when rotates goes into the beam. Reflective shaft encoders use a disk with black and white colors that reflects or not the light. The quality of the encoder (more notches or black-white zones, for example) will determine the precision of the measurement.
Notes References
20210524205426 Robotics Infra-red sensors 20210516201246 Robotics Motors - Basics