The primary substance in the upper atmosphere that plays a crucial role in temperature changes in the layers is water vapor. Water vapor acts as a greenhouse gas, absorbing and emitting infrared radiation, thereby contributing to the regulation of the Earth's temperature. When the amount of water vapor in the atmosphere increases, it leads to a rise in the overall temperature of the atmosphere, affecting the temperature gradients and influencing various atmospheric processes.