Home▸Articles▸Electromagnetism

Magnetic Levitation: The Science Behind PID-Controlled Suspension

An intriguing phenomenon where a magnetic field can hold an object in mid-air through precise control systems.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What Magnetic Levitation Is

Magnetic levitation, or maglev, is a method used to suspend objects using magnetic fields. In this setup, an electromagnet generates a field that interacts with the ferromagnetic ball, creating a force that counteracts gravity and keeps the ball aloft.

The key equation governing the force between the coil and the ball is F = k * I^2 / x^2, where F represents the force, k is a constant related to the magnetic field strength, I is the current through the coil, and x is the distance (gap) between the coil and the ball.

Why It Happens

The phenomenon of levitation arises from the interaction between the magnetic field generated by the electromagnet and the ferromagnetic properties of the ball. As the current through the coil changes, it creates a varying magnetic field that exerts force on the ball.

When the force exerted by the magnetic field is equal to the gravitational force pulling the ball down, the net force becomes zero, resulting in suspension.

live demo · related simulation● LIVE

PID Control System

A PID (Proportional-Integral-Derivative) controller is used to maintain the gap between the coil and the ball at a setpoint. The controller continuously adjusts the current through the coil based on the error (difference between desired and actual gap).

The proportional term (Kp) scales the response, the integral term (Ki) eliminates steady-state errors over time, and the derivative term (Kd) anticipates future errors by considering past changes in the gap.

Real-World Applications

Magnetic levitation has numerous practical applications beyond this lab setup. Maglev trains use similar principles to achieve high-speed transportation with reduced friction and noise.

In industrial settings, magnetic levitation is used for precise positioning of objects in manufacturing processes, such as aligning components during assembly or handling delicate materials.

Frequently asked questions

How does the PID controller work to maintain stability?

The PID controller continuously measures the gap between the coil and the ball. It then adjusts the current through the coil based on proportional, integral, and derivative terms to minimize any deviation from the setpoint.

Why is magnetic levitation important in technology?

Magnetic levitation enables the development of high-speed transportation systems like maglev trains and precise industrial applications where stable positioning is crucial.

Can any ferromagnetic material be used for levitation?

Not all ferromagnetic materials are suitable. The ball must have a strong magnetic response to the field generated by the electromagnet, which depends on its composition and magnetic properties.

What happens if the PID controller fails in this setup?

If the PID controller fails, the current through the coil will not be properly adjusted. This can result in either the ball falling due to insufficient lift or overshooting the setpoint gap and potentially damaging the system.

Try it live

Everything above runs in your browser — open Magnetic Levitation (2D) — PID-Controlled Electromagnet & Ball and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Magnetic Levitation (2D) — PID-Controlled Electromagnet & Ball simulation

What did you find?

Add reproduction steps (optional)