An optical encoder including a sensor module including a light emitting
member, a light receiving member opposite to the light emitting member to
receive the emitted light, and at least one boss extending in a first
direction; a shade member located between the light emitting member and
the light receiving member and having a shading pattern; a first support
supporting the sensor module and including at least one recessed portion
engaged with the boss, and a groove connected with the recessed portion
and extending in a second direction, wherein the sensor module is
attached to the first support by being moved in the second direction
while the boss is guided by the groove, and wherein the recessed portion
has a depth greater than the height of the boss, and a portion of the
groove adjacent to the recessed portion has a depth less than the height
of the boss.