A sensor device (2) is removably attachable to a drug delivery device (12). The sensor device comprises an array (20) of optical sensors arranged within the sensor device such that, when the sensor device is attached to the drug delivery device, the drug delivery device having a first movable element (14) which is configured to move along a path parallel to the longitudinal axis of the drug delivery device, each optical sensor is operable to detect light received at different locations along the linear path and to output a signal indicative of an amount of detected light; and circuitry (21) configured to receive the signals output from the optical sensors and, based on the received signals, to determine information associated with a location along the path of the first movable element.