Why does filling a compressed air cylinder produces heat?

Because what you are doing is a flow process, with mass inflow and no mass outflow, you need to use the thermodynamic equation:

$dU_{cv}={m_{in}d}{H}_{in}-{m_{out}d}H_{out}+\delta Q-\delta W_{shaft}$

If you insulate your air cylinder well enough, $\delta Q = 0$.

Assuming that your air cylinder does not deform, $\delta W = 0$.

Since you are filling your cylinder with air and assuming no air escapes, ${m_{out}d}H_{out} = 0$

Therefore, the enthalpy of the gas which you are filling adds to the internal energy of the gas in the cylinder, and because the internal energy is positively correlated to temperature, the temperature in of the gas in the cylinder rises.

$\Delta{U_{cv}}={H_{in}}>0$, so $\Delta{T} >0$

You may apply the reverse for the release of air from the cylinder. In this case:

$\Delta{U_{cv}}={-H_{out}}<0$, so $\Delta{T} <0$

http://en.wikipedia.org/wiki/Thermodynamic_system#Flow_process


I would explain it by simply using the first law of thermodynamics:

$$Q-W=\Delta U$$

$Q$ is heat added to the system, $W$ is work done by the system, $U$ is the internal energy. Keep in mind that internal energy is closely bound to temperature, so a change $\Delta U$ also results in a temperature change (which is what we are talking about).

If you look at the gas as a system - a control mass - then when you open the valve and let the gas out, you are letting this compressed gas do work on the surrounding air by pushing it out of the way. So $W>0$.

When filling the cylinder with some apparatus that compresses the gas to put more in, there is done work on the gas, meaning that the gas does negative work on the apparatus. $W<0$

Assuming no heat exchange with the surroundings (let's say this happens too fast for any significant heat transfer to occour), $Q=0$.

Since $W \neq 0$, the first law of thermodynamics then tells you that there must be a change in internal energy.

$$-W=\Delta U$$

And therefrom the temperature changes. Note that positive work (expansion) gives a decrease in internal energy, while negative work (compression) gives a rise.

This is experienced as heating or cooling by the observer that touches the cylinder because of the rapid heat conduction into the hand. Since the heat convection into surrounding air is much less effective, our assumption that $Q=0$ is fair as long as the cylinder doesn't touch any other good conducting material.