Air quality within a building is controlled by maintaining a count of people in the building and by ventilating the building with an amount of air dependent on the count. The count may be determined in accordance with an access control system and/or entry and exit sensors, such as infrared sensors.