This work presents a breath sampler prototype automatically collecting end-tidal (single and multiple breaths) or dead space air fractions (multiple breaths). This result is achieved by real time measurements of the CO2 partial pressure and airflow during the expiratory and inspiratory phases. Suitable algorithms, used to control a solenoid valve, guarantee that a Nalophan(®) bag is filled with the selected breath fraction even if the subject under test hyperventilates. The breath sampler has low pressure drop (<0.5 kPa) and uses inert or disposable components to avoid bacteriological risk for the patients and contamination of the breath samples. A fully customisable software interface allows a real time control of the hardware and software status. The performances of the breath sampler were evaluated by comparing (a) the CO2 partial pressure calculated during the sampling with the CO2 pressure measured off-line within the Nalophan(®) bag; (b) the concentrations of four selected volatile organic compounds in dead space, end-tidal and mixed breath fractions. Results showed negligible deviations between calculated and off-line CO2 pressure values and the distributions of the selected compounds into dead space, end-tidal and mixed breath fractions were in agreement with their chemical-physical properties.