A milking system includes an optical detector for detecting radiation emitted and/or reflected by a part of an animal, the optical detector having a housing with a window that is substantially transparent to the radiation. The milking system further includes a cleaning device for cleaning the window of the optical detector. The cleaning device includes a nozzle connected to a source of steam, and in operation the nozzle directs steam against the window of the optical detector. The use of steam to clean the window provides heating and rinsing free of impurities and minerals that can leave deposits and residue on the window and which, over time, may degrade the operation of the optical detector.