Device for the production of foam of a liquid, particularly of a food liquid such as milk, coffee or the like, comprising: - a source of a liquid, - a source of air or another gas, - a mixing device in fluid communication with said liquid source and with said air source adapted to mix said liquid coming from said liquid source with said air coming from said air source to generate a foam of said liquid, - a duct in fluid communication with said mixing device downstream of said mixing device, said foam flowing along said duct in a flow direction, characterized in that it comprises a foam sensor associated with said duct, said foam sensor comprising a radiation source adapted to generate a radiation which strikes said duct along an irradiation direction incident to said flow direction, said foam sensor further comprising: - a first photodiode placed on said irradiation direction from a side opposite to said radiation source with respect to said duct, said first photodiode generating a first electrical signal dependent on the radiation portion which passes through said foam which flows along said duct, or - a second photodiode placed along a diffusion direction substantially orthogonal to said irradiation direction, said second photodiode generating a second electrical signal dependent on the radiation portion which is diffused by said foam along substantially said diffusion direction. - a source of a liquid, - a source of air or another gas, - a mixing device in fluid communication with said liquid source and with said air source adapted to mix said liquid coming from said liquid source with said air coming from said air source to generate a foam of said liquid, - a duct in fluid communication with said mixing device downstream of said mixing device, said foam flowing along said duct in a flow direction, characterized in that it comprises a foam sensor associated with said duct, said foam sensor comprising a radiation source adapted to generate a radiation which strikes said duct along an irradiation direction incident to said flow direction, said foam sensor further comprising: - a first photodiode placed on said irradiation direction from a side opposite to said radiation source with respect to said duct, said first photodiode generating a first electrical signal dependent on the radiation portion which passes through said foam which flows along said duct, or - a second photodiode placed along a diffusion direction substantially orthogonal to said irradiation direction, said second photodiode generating a second electrical signal dependent on the radiation portion which is diffused by said foam along substantially said diffusion direction. - a first photodiode placed on said irradiation direction from a side opposite to said radiation source with respect to said duct, said first photodiode generating a first electrical signal dependent on the radiation portion which passes through said foam which flows along said duct, or - a second photodiode placed along a diffusion direction substantially orthogonal to said irradiation direction, said second photodiode generating a second electrical signal dependent on the radiation portion which is diffused by said foam along substantially said diffusion direction.