The electrostatic pendulum, also known as the electrostatic ping-pong, is an exciting experiment in school as well as in undergraduate education. We can easily demonstrate how the frequency of the electrostatic pendulum depends on the voltage across the capacitor. In this paper, we develop a simple mathematical model describing the dynamics of this experiment. In a step-wise manner, we introduce the external forces influencing the dynamics of the electrostatic pendulum. First, we take into account the electric force only. Then, we add air resistance and the non-elasticity of ball collisions with the capacitor plates. The model predictions show that the non-elastic collisions have greater effect on the pendulum dynamics than air resistance; in particular, this is true for higher frequencies of the pendulum. For lower frequencies, however, gravity is of crucial importance. The mathematical model is implemented in a graphic-oriented computer program, which gives the possibility of using this theoretical analysis also at the secondary school level.