The adsorption of gas molecules (CO, NH$_3$, CO$_2$ ) on Polyaniline Emeraldine salt has been performed to study gas sensing. Density functional theory (DFT) and time dependent density functional theory (TD-DFT) calculations have been carried out to compute the response mechanism of polyaniline emeraldine salt (PANI ES) oligoanalinines (with two to six rings) to gas molecules. The optimized geometry and electronic structure corresponding to molecule and complexes are computed with the pseudo-potential and full-potential methods. The absorption spectra corresponding to polyaniline emeraldine salt molecule and its complexes are calculated using TD-DFT. We found it out that the electronic and optical features corresponding to complexes show more sensitive to the NH$_3$ adsorption. The optical absorption spectrum analysis was used for all ( nPANI ES-X ) and isolated nPANI ES. Then, the related spectrum indicates that the $lambda_{max}$ is shifted red or blue, is affected by the kind of complex.