An implement for automatically milking a dairy animal, such as a cow, comprises a milking parlour, a sensor for observing a teat, and a milking robot for automatically attaching a teat cup to the teat. The milking robot comprises a robot control that is connected to the sensor. The sensor comprises a radiation source for emitting light, a receiver for receiving electromagnetic radiation reflected from the dairy animal, a lens, and sensor control unit. The sensor comprises a matrix with a plurality of rows and a plurality of columns of receivers. The sensor control unit is designed to determine for each of the receivers a phase difference between the emitted and the reflected electromagnetic radiation in order to calculate the distance from the sensor to a plurality of points on the part to be observed of the dairy animal.