(EN) The present invention relates to a method and an apparatus for controlling a milking machine or milking robot in order to remove each teat cup from the udder when the quarter in question is emptied to an optimum. Sensing means (6, 36, 38) are arranged in a measuring chamber and via an energy source (30) and a detecting and storing unit (32) connected to the computer of the milking system. Signals are generated by means of said sensing means, which signals via said unit (32) and said computer control the exact timing of the teat cup removal.