A milking system includes a milking robot with a robot arm for applying teat cups to the teats of an animal, an optical detector (40) for detecting radiation emitted and/or reflected from the animal and a controller. The detector has a housing (410) with a window (420) and a detecting element (430) enclosed in the housing that is sensitive to the emitted or reflected radiation passing through the window. In order to prevent contamination from impacting on the detector window, an airflow arrangement is provided that can be connected to a source of pressurized air and has at least one aperture (411) disposed adjacent the detector window (420) for generating a curtain of air that flows parallel with the surface of the window. The controller controls the generation of the air curtain to coincide with the start of at least one further operation controlled by the controller.