The effect of the non-covalent functionalization of single-walled carbon nanotubes (SWNTs) and graphene with imidazole is evaluated using Density Functional Theory (DFT) with the aim of improving the CO2 detection. Both metallic and semi-conducting SWNTs are investigated. The interaction of imidazole ring with different carbon nanomaterials is analyzed, as well as the adsorption of CO2 before and after the surface functionalization process. The binding energies, the energy band gaps, the Fermi levels, and the charge transfer process have been computed for all the possible fragments and for the total interacting systems. The functionalization of SWNT(8,0) and graphene by an imidazole ring increases the stability of CO2 physisorption and improves the positive charge transfer from CO2 to the carbon material, confirming that such functionalization can be a viable strategy for CO2 detection.