How does heart beat faster while doing a strenuous task?
I am sure that there are many ways that your body can regulate heart rate, but I am going to cover this topic briefly from the perspective of $\ce{CO2}$/$\ce{O2}$ concentrations, and pH.

The medulla oblongata

The medulla oblongata is part of the central nervous system, and makes up the lower portion of the brain stem. It is responsible for performing autonomic functions, including the regulation of heart rate through chemoreceptors. The medulla oblongata receives its blood supply from the vertebral artery and makes both afferent and efferent connections with the vagus nerve. 

Chemoreceptors

There are two main types of chemoreceptors in your cells that are responsible for regulating heart rate.


Central chemoreceptors


These are located in the medulla oblongata, and are responsible for measuring the concentration of $\ce{H+}$ ions (ie. pH). When the pH is low, neural cells with these receptors will signal the release of norepinephrine and epinephrine.


Peripheral chemoreceptors


These are located in the carotid and aortic bodies and measure the concentration of $\ce{O2}$. The receptor cells of these structures make connection with afferent nerves, to send a signal to the central nervous system in times of hypoxemia.

$\ce{CO2}$/$\ce{O2}$ Exchange

Blood is the tissue responsible for distributing chemicals around your body. It is therefore also involved in the $\ce{CO2}$/$\ce{O2}$ exchange between tissues. Blood cells use hemoglobin as as a carrier molecule for this exchange.

When $\ce{O2}$ is delivered to tissues, it will be processed by the mitochondria of the cells to synthesise ATP, and $\ce{CO2}$ as a biproduct. ATP is also responsible for muscle contractions, and so, with exercise comes an increased utilisation of ATP. With ATP stores running low, your cells will begin to use more $\ce{O2}$, and therefore, they will produce more $\ce{CO2}$.

$\ce{CO2}$ and Acidity

So, I kinda lied when I said hemoglobin is the carrier of $\ce{CO2}$. This is mostly true, but $\ce{CO2}/$$\ce{O2}$ is also somewhat soluble in blood, and this accounts for changes in blood-pH.

$\ce{CO2 + H2O}$ $\ce{&lt;=&gt;}$ $\ce{H2CO3}$ $\ce{&lt;=&gt;}$ $\ce{HCO3- + H+}$ 

The above equilibrium is catalysed by carbonic anhydrase, and accounts for a decrease in pH levels.

Signalling in response to pH

So your exercising, your body is using lots of $\ce{O2}$ to produce ATP. Your $\ce{CO2}$ levels have increased, and your internal pH has dropped. Now what?

Well, as I'm sure you have guessed, your nervous system takes over. 

The central chemoreceptors of the medulla oblongata send an impulse to  the adrenal glands in response to the decreased pH. This signals the release of the hormones epinephrine and norepinephrine in to the bloodstream. The release of epinephrine and norepinephrine is regulated by the sympathetic nervous system. This accelerates the heart rate by binding β-receptors in your heart tissue. Efferent nerve connections from the vagus nerve also participate in this process (I think).

For mechanisms on heart contration, see here; everything following "excitation contraction coupling" is probably the most relevant.