Yawning is a response to boredom. The PVN of the hypothalamus (i.e. A particular brain region) gives a signal to initiate a yawn.
The signal stimulates brain cells to produce the muscle contractions, i.e. Yawning. The chemical messengers that induce yawning are made by the PVN, which are released a lot during sleep. This explains that we tend to yawn when we wake up in the morning and also be able to yawn during sleep .
Yawning can also be contagious. You may want to yawn even if you are reading something about yawning. Find out more about yawning here.