A drug delivery device comprising:a motor (530) configured to advance a stopper in a cartridge of medicament, the motor comprising an output shaft;a controller; anda motion detection system (522) configured to provide positional feedback to the controller, wherein the motion detection system comprises an optical encoder (534) and at least one element (528) operatively coupled to the output shaft (531) of the motor and configured to rotate with the output shaft such that the at least one element passes through the optical encoder.