Very high precision can be achieved by neutron measurements, due to the fact that neutrons are electrically neutral. Therefore, hypothetical forces and interactions being many orders of magnitude smaller than the electromagnetic force can be searched for, or tiny effects that are otherwise masked can be measured. That the neutron is a particle having zero electric charge has been checked by beam-deflection experiments, where slow neutrons pass through a strong electric field perpendicular to the beam direction. The value of the electric charge of the neutron could be restricted to be smaller than 10^{-21} times the electric charge of the electron. We propose to test the electric neutrality of neutrons at small distances by a new technique using the spectroscopy of quantum states in the gravity potential above a vertical mirror for ultracold neutrons. The new technique is an application of Ramsey's method of separated oscillating fields to neutron's quantum states in the gravity potential of the earth. In the presence of an electric field, the energy of the quantum states changes due to an additional electrostatic potential if a neutron carries a nonvanishing charge. The energy shift differs from state to state due to the special properties of the wave function in a linear potential. The energy difference between two quantum states with and without applying an electric field is measured in the experiment. In the long run our new method has the potential to improve the current limit for the electric charge of the neutron by 2 orders of magnitude.