Under different conditions, stomata can open or close to regulate gas exchange.

carbon dioxide needed
nighttime
daytime
oxygen produced by photosynthesis
hot daytime temperatures