A machine for preparing and dispensing a beverage, such as tea, coffee, hot chocolate, cold chocolate, milk, soup or baby food, such machine comprising: - an extraction unit for extracting a beverage ingredient capsule to form said beverage, e.g. a unit having a first part and a second part that are relatively movable between an open position for inserting and/or removing a capsule and a closed position, such as a closed position in which the first and second parts (11,12) delimit an extraction chamber, for securing and extracting such capsule, optionally at least one of said parts (11,12) has a capsule opener e.g. one or more capsule piercers and/or at least one of said parts (11,12) has an opening for an inflow of liquid to be mixed with an ingredient contained in such capsule; - a control unit for controlling the extraction unit to extract such capsule, such as a control unit powered by the mains e.g. via an electric cord; - an outlet for dispensing said beverage formed by extracting such capsule to a user-receptacle, such as a cup or a mug, located in a receptacle placing area, such as on a receptacle support (5,6) e.g. an external placement support on which such machine is located or a machine support e.g. a movable or removable machine support, to collect said beverage; and - a capsule recognition module for recognizing a type of said capsule inserted in said machine, the capsule recognition module comprising: - a light source for lighting at least part of the surface of such capsule; and - an optical sensor for sensing an optical property of said at least part of the surface of such capsule, characterised in that: the capsule recognition module is configured to: - determine a correction value of said optical property by sensing said optical property of said at least part of the surface of such capsule while said light source is switched off; - determine at least one sample value of said optical property by sensing said optical property of said at least part of the surface of such capsule while said light source is switched on; - calculate a corrected sample value with said correction value and said at least one sample value; and - determine said type of said capsule by comparing said corrected sample value with at least one reference value, said at least one reference value being representative of a type of capsule. - an extraction unit for extracting a beverage ingredient capsule to form said beverage, e.g. a unit having a first part and a second part that are relatively movable between an open position for inserting and/or removing a capsule and a closed position, such as a closed position in which the first and second parts (11,12) delimit an extraction chamber, for securing and extracting such capsule, optionally at least one of said parts (11,12) has a capsule opener e.g. one or more capsule piercers and/or at least one of said parts (11,12) has an opening for an inflow of liquid to be mixed with an ingredient contained in such capsule; - a control unit for controlling the extraction unit to extract such capsule, such as a control unit powered by the mains e.g. via an electric cord; - an outlet for dispensing said beverage formed by extracting such capsule to a user-receptacle, such as a cup or a mug, located in a receptacle placing area, such as on a receptacle support (5,6) e.g. an external placement support on which such machine is located or a machine support e.g. a movable or removable machine support, to collect said beverage; and - a capsule recognition module for recognizing a type of said capsule inserted in said machine, the capsule recognition module comprising: - a light source for lighting at least part of the surface of such capsule; and - an optical sensor for sensing an optical property of said at least part of the surface of such capsule, - a light source for lighting at least part of the surface of such capsule; and - an optical sensor for sensing an optical property of said at least part of the surface of such capsule, - determine a correction value of said optical property by sensing said optical property of said at least part of the surface of such capsule while said light source is switched off; - determine at least one sample value of said optical property by sensing said optical property of said at least part of the surface of such capsule while said light source is switched on; - calculate a corrected sample value with said correction value and said at least one sample value; and - determine said type of said capsule by comparing said corrected sample value with at least one reference value, said at least one reference value being representative of a type of capsule.