## 1 Introduction  
The efficiency of milk production is directly related to automated quality control, which is based on various sensing technologies. One of the important technological factors for the effective management of dairy farms is the monitoring of the composition of milk produced. A dairy farm is a fairly broad concept and includes both high-tech large farms with a high degree of automation, and small farms without milking robots and most automation systems. Whilst dairy farms use milking machines of different types and characteristics, all of them need a system to control the flow rate and composition of milk. Obtaining information on the quantitative content of milk components (fat, proteins, lactose, somatic cells, progesterone, amino acids, etc.) underlies the assessment of milk quality, as well as diagnosing the nutritional balance and clinical condition of cows [1, 2]. In particular, the content of fat and protein is considered to be the main criterion that determines the market value of milk. The real-time control of milk composition is especially important for promptly responding to deviations in the parameters of the physiological state of animals and for the timely adjustment of diets when milk yields are reduced. Currently, there is no unified system compactly built into milk pipelines that provides a simultaneous measurement of both the flow rate and the component percentages of milk [3]. Most small farms only operate flow meters installed on the milking machines, whilst the analysis of milk quality is carried out by a stand-alone sample analyzer, or milk samples are sent for periodic testing to specialized laboratories. For high-precision analysis of the composition of milk, such laboratories use expensive stationary instruments. Obviously, the efficiency of dairy production can be significantly increased with the use of inexpensive and compact devices for inline analysis of the milk composition during the milking process. In accordance with the ICAR requirement to use control devices that do not lead to a significant pressure drop in the milk hose, when developing milk quality sensors for dairy farm equipment [4; 5], optical diagnostic methods are primarily promising, since these methods can perform non-contact and non-destructive diagnostics with high sensitivity and speed [6; 7; 8; 9; 10]. The existing devices for online assessment of the content of the three main components in milk (fat, protein, and lactose) use spectral methods, for the most part, infrared (IR) spectroscopy [3]. However, the incorporation of IR transmission spectroscopy into milking systems has the disadvantage of requiring a thin layer of milk, which reduces milk pumping rates. IR reflection spectroscopy avoids this problem, but the accuracy of the analysis decreases due to the influence of diffuse scattering on the reflectance intensity. High-precision systems using Fourier transform infrared (FTIR) spectroscopy are very expensive and have larger dimensions overall. A more compact and less expensive alternative to FTIR spectrometers are commercially available near-infrared (NIR) analyzers [11], such as Afimilk analyzers [12], but these require specialized computer software. Light-scattering analyzers appear capable of further improving price-performance ratio. Some approaches to measuring the content of milk components based on light-scattering effects have been reported in [13; 14; 15; 16]. The spatial distribution of diffuse transmission from a layer of milk which is a few millimeters thick is measured with a digital camera using three LEDs emitting at different wave lengths, and then analyzed by a regression model to determine the content of fat and protein [13; 14]. The optical transmission and internal reflectance of milk, which are sensitive to the fat level due to diffuse scatter, can be measured using fiber optic technologies [15; 16; 17].