when atoms/ions are heated they gain energy and move to a higher energy level. When they calm back down, the energy is radiated as electromagnetic waves (electricity). Each element produces a unique wavelength. This is the idea behind flame tests and flame emission spectroscopy.