A yawn, is an involuntary reflex action controlled by the nerve and spinal centers. When you yawn your alertness is heightened. The oxygen you take in raises your heart rate, and your exhalation releases carbon dioxide. You are most likely to yawn in that first hour after you wake up, or in the hour before bedtime. But the athlete or performer will yawn right before a big event.
Researchers say they are just keeping themselves at optimal alertness.
But it can work the other way, you also yawn when you're bored and not paying attention at all. Even if you're alert and attentive, you will yawn if you see someone else yawning. It's non-verbal communication. Researchers watching apes say the lead ape yawns to signal it is time for a change, let's do something different, and the other apes yawn back to signal they are willing to follow the leader. Yawning also synchronizes group behavior, it's a big boring meeting and look around, everyone's yawning, signaling we are all in this together.