Years ago I saw someone's website telling how he made a similar levitation project.
He used a lightweight globe about 2 inches diameter. It had a magnet at the top.
However he found it was impossible to adjust the pulses so finely that the globe would float. It either fell or popped up to the electromagnet.
He tried positioning an LED to send a narrow optical beam under the globe to a light detector.
As the globe fell it interrupted the beam. The light detector activated power to the electromagnet. The globe rose. When it exposed the light beam, the electromagnet was turned off.
This took place many times a second. The globe was automatically suspended in midair. That was the idea anyway.
Now I remember it wasn't so simple. The feedback circuit did not act quickly enough. The globe still fell.
I seem to remember the designer found a way to anticipate the globe's up-and-down motion. He found he could take advantage of a capacitor's current-lead characteristic with AC.
He made a circuit which automatically adjusted to the frequency of motion, and took a current sense through the capacitor at the right moment, to send a pulse to the electromagnet just before the globe could fall too far.
It worked. His project may still be on the internet somewhere.