A Motor Encoder uses either a Hall Effect sensor or some kind of opto-interrupter to determine how fast a motor is turning. This is used by a PID Controller to set and maintain control over a robot motor.
This uses a small magnet attached to the motor's shaft and two electromagnetic Hall Effect sensors spaced 180° across each other from the shaft, which detect the motor's motion, with the sensors out of phase of each other. The phase shift permits a determination of motor direction (though this generally isn't required in a robot controller since we already know which direction the motor is going by the polarity we're sending it).
This uses an LED emittor-detector pair and a small wheel connected to the motor's shaft, with either holes (if the sensor is measuring the light passing through the holes) or alternating black and white patches (if the sensor is measuring reflected light).
On the motors page is listed a MiniQ Motor Wheel Set w/ Encoder that uses the teeth of a white plastic wheel hub for an optical encoder.
Here's some preliminary links related to quadrature encoders running on an RP2040 PIO: