the brain stem
The regular, rhythmic contractions of the diaphragm are controlled by the brain stem. It sends nerve impulses to the diaphragm through the autonomic nervous system. The brain stem monitors the level of carbon dioxide in the blood. If the level becomes too high, it tells the diaphragm to contract more often. Breathing speeds up, and the excess carbon dioxide is released into the air. The opposite events occur when the level of carbon dioxide in the blood becomes too low. In this way, breathing keeps blood pH within a narrow range.