What is the main mechanism that heats air in the atmosphere?

This is pretty much all based on Atmospheric Heating and I assume you mean the atmosphere that surrounds you, rather than at any great height. I am concentrating on ground heat levels up to 500 m.

In order of importance, the electromagnetic radiation from the sun, which obviously provides the initial energy for the atmosphere to heat up during daylight.

Higher frequency radiation has more energy than lower frequency radiation. Most of the sun's radiant energy is concentrated in the visible and near-visible portions of the spectrum. UV radiation accounts for a small percentage of the total radiation received from the sun, but it is extremely important in that it has much higher energy.

It should be noted that, because of the proportion of sea to land on Earth, about 71% of the radiation from the sun falls on water. The specific heat capacity of seawater at $0^{\circ}$C is 3985 J kg$^{−1}$ $K^{−1}$, but because of currents and differences in sea levels, it may be difficult to estimate the true heat transfer by convection and consumption, to the air mass above the sea water.   

enter image description here

enter image description here

A graph of solar intensity by wavelength.

Image Credit: www. solarcellcentral.com

In the atmosphere, convection includes large- and small-scale rising and sinking of air masses and smaller air parcels. These vertical motions effectively distribute heat and moisture throughout the atmospheric column and contribute to cloud and storm development (where rising motion occurs) and dissipation (where sinking motion occurs).

Meanwhile, the slow rotation of the earth toward the east causes the air to be deflected toward the right in the northern hemisphere and toward the left in the southern hemisphere. This deflection of the wind by the earth's rotation is known as the Coriolis effect.

To understand the convection cells that distribute heat over the whole earth, let's consider a simplified, smooth earth with no land/sea interactions and a slow rotation. Under these conditions, the equator is warmed by the sun more than the poles. The warm, light air at the equator rises and spreads northward and southward, and the cool dense air at the poles sinks and spreads toward the equator. As a result, two convection cells are formed.

enter image description here

Since air is a poor conductor, most energy transfer by conduction occurs right at the earth's surface. During the day, solar radiation heats the ground, which heats the air next to it by conduction.

Finally, a small part of the energy of the sun is directly absorbed, especially by by gases such as ozone and water vapor. Some energy is also reflected back to space by clouds and the earth's surface.