A brewing unit for making beverages using a capsule containing a powdered food substance, where the capsule comprises an outer casing, in which an infeed wall and an outfeed wall are identifiable, and a recognition element placed inside the outer casing, wherein the brewing unit comprises a first part and a second part, which are switchable between a home configuration, in which they are at a distance from each other, and a brewing configuration, in which they are coupled and between them delimit an infusion chamber configured to house the capsule, and wherein the brewing unit also comprises: a first piercing unit configured to pierce the infeed wall of the capsule inserted in the infusion chamber, supplying means for supplying hot water inside the capsule inserted in the infusion chamber, through the infeed wall, and means for causing the outflow from inside the capsule inserted in the infusion chamber, and through the outfeed wall, of a beverage which has formed following interaction of the hot water with the powdered food substance; a lighting device associated with the first piercing unit and configured to light the recognition element with an incident light radiation having a known first wavelength, and a detecting device associated with the first piercing unit and configured to detect a return light radiation which is emitted and/or reflected by the recognition element following the lighting with the incident light radiation; an electronic control unit, connected to the detecting device for receiving from it real data relating to characteristics of the return light radiation, the electronic control unit being programmed to execute a comparing step, in which the real data are compared with saved reference data, and a managing step, in which it manages operation of the brewing unit in a different way if the comparing step indicates that the real data match reference data, compared with if the comparing step indicates that the real data do not match the reference data; wherein, moreover, the hot water supplying means are configured to supply the hot water at a zone towards which the lighting device and the detecting device are directed; the brewing unit being characterised in that, when a first execution of the comparing step indicates that the real data do not match reference data, the electronic control unit is programmed to: execute a cleaning step for cleaning the recognition element, by activating the hot water supplying means; execute the comparing step a second time during and/or after the cleaning step; and execute the managing step based on the results obtained with the second execution of the comparing step. a first piercing unit configured to pierce the infeed wall of the capsule inserted in the infusion chamber, supplying means for supplying hot water inside the capsule inserted in the infusion chamber, through the infeed wall, and means for causing the outflow from inside the capsule inserted in the infusion chamber, and through the outfeed wall, of a beverage which has formed following interaction of the hot water with the powdered food substance; a lighting device associated with the first piercing unit and configured to light the recognition element with an incident light radiation having a known first wavelength, and a detecting device associated with the first piercing unit and configured to detect a return light radiation which is emitted and/or reflected by the recognition element following the lighting with the incident light radiation; an electronic control unit, connected to the detecting device for receiving from it real data relating to characteristics of the return light radiation, the electronic control unit being programmed to execute a comparing step, in which the real data are compared with saved reference data, and a managing step, in which it manages operation of the brewing unit in a different way if the comparing step indicates that the real data match reference data, compared with if the comparing step indicates that the real data do not match the reference data; wherein, moreover, the hot water supplying means are configured to supply the hot water at a zone towards which the lighting device and the detecting device are directed; the brewing unit being characterised in that, when a first execution of the comparing step indicates that the real data do not match reference data, the electronic control unit is programmed to: execute a cleaning step for cleaning the recognition element, by activating the hot water supplying means; execute the comparing step a second time during and/or after the cleaning step; and execute the managing step based on the results obtained with the second execution of the comparing step. execute a cleaning step for cleaning the recognition element, by activating the hot water supplying means; execute the comparing step a second time during and/or after the cleaning step; and execute the managing step based on the results obtained with the second execution of the comparing step.