Magnetic levitation is the suspension of an object against gravity using magnetic forces to counteract gravitational pull and maintain a stable air gap without physical contact. In a real circuit, achieving levitation changes your design from a simple static power delivery system into a high-speed closed-loop control system requiring microsecond sensor polling and dynamic PWM current regulation. Because of Earnshaw's theorem, static magnetic fields cannot create stable levitation on their own; you must actively measure the gap and adjust the electromagnetic pull thousands of times per second to prevent the object from snapping to the coil or dropping to the bench.
Core Component Specifications for a Bench-Scale EMS System
To build a functional Electromagnetic Suspension (EMS) system on your workbench, you need to balance coil inductance, sensor sensitivity, and switching speed. The table below outlines a proven component spec sheet for levitating a 50-gram steel sphere at a 15mm air gap using a 12V DC supply.
| Component Category | Specific Part / Parameter | Value / Specification | Design Rationale |
|---|---|---|---|
| Electromagnet Coil | AWG 24 Magnet Wire, 400 turns | R = 2.1 Ω, L ≈ 18 mH | Provides sufficient ampere-turns while keeping resistance low enough for 1.5A+ continuous current without thermal runaway. |
| Magnetic Sensor | SS49E Linear Hall Effect | Sensitivity: 1.4 mV/G, Vcc: 5V | Outputs an analog voltage proportional to the magnetic flux density, allowing the microcontroller to calculate the exact air gap. |
| Power Switching | IRFZ44N N-Channel MOSFET | Rds(on): 17 mΩ, Vds: 55V | Handles high continuous current with minimal heat dissipation; fast switching times support 20kHz+ PWM frequencies. |
| Microcontroller | STM32F103C8T6 (Blue Pill) | 12-bit ADC, 72 MHz Clock | The 12-bit ADC provides the resolution needed to detect sub-millimeter gap changes that an Arduino Uno's 10-bit ADC might miss. |
| Flyback Protection | 1N5819 Schottky Diode | Vf: 0.6V, I_avg: 1A | Clamps the inductive voltage spike when the MOSFET turns off, protecting the gate driver and power supply. |
The Control Loop: Calculating PID and Electromagnet Force
Designing the electromagnet requires matching the magnetic pull force to the gravitational force of your target mass. Let's walk through a worked numeric example to determine the required coil current.
Target Parameters:
- Mass of steel sphere ($m$): 50 grams (0.05 kg)
- Gravitational force ($F_g$): $m imes g = 0.05 imes 9.81 = 0.4905$ Newtons
- Target air gap ($g$): 15 mm (0.015 m)
- Coil turns ($N$): 400
- Core cross-sectional area ($A$): $3.14 imes 10^{-4}$ m$^2$ (based on a 1 cm radius core)
The simplified Maxwell pull force equation for an electromagnet across an air gap is:
$$F = \frac{\mu_0 \cdot N^2 \cdot A \cdot I^2}{2 \cdot g^2}$$
Where $\mu_0$ is the permeability of free space ($4\pi \times 10^{-7}$ T·m/A). Plugging in our knowns to solve for the required current ($I$):
$0.4905 = \frac{(1.256 \times 10^{-6}) \cdot (160,000) \cdot (3.14 \times 10^{-4}) \cdot I^2}{2 \cdot (0.000225)}$
$0.4905 = 0.1402 \cdot I^2$
$I^2 = 3.498 \implies I \approx 1.87 \text{ Amps}$
To maintain a 15mm gap, your circuit must deliver a steady-state current of roughly 1.87A. Because your coil resistance is only 2.1 Ω, applying 12V directly would push over 5.7A through the coil, instantly snapping the ball to the magnet and likely burning out your wire insulation. This is why you must drive the MOSFET with a high-frequency PWM signal (typically 20kHz to 30kHz to avoid audible whining and ensure smooth inductor current). The PID controller adjusts the PWM duty cycle in real-time to maintain the 1.87A average.
Tuning the PID loop is where most DIY builds fail. The Proportional (P) term reacts to the current gap error. The Derivative (D) term predicts future error based on the ball's velocity—this is critical for damping oscillations. The Integral (I) term is often set to zero or extremely low in maglev applications, as integral windup will cause the system to overshoot and drop the object when it is first introduced to the field.
Where You Meet Magnetic Levitation in Practice
While bench builds are excellent for learning control theory, the principles scale directly to heavy industry and commercial applications. You will encounter EMS and its cousin, Electrodynamic Suspension (EDS), in several key areas:
- Maglev Transit: The German Transrapid system uses EMS (electromagnets pull up toward a steel guideway from below), requiring the exact same active gap-control logic we calculated above, just scaled to 300 km/h. Japan's SCMaglev uses EDS, relying on superconducting magnets and induced repulsion, which is inherently stable at high speeds but unstable at low speeds.
- Magnetic Bearings: Used in high-speed flywheel energy storage and industrial centrifugal compressors. They eliminate mechanical friction, allowing rotational speeds exceeding 50,000 RPM with zero lubrication.
- Levitating Displays and Retail: Those floating globe desk toys use a simplified top-pull EMS system with an integrated analog comparator circuit rather than a full microcontroller PID loop.
Common Build Failures and Calibration Fixes
When your magnetic levitation circuit refuses to hold the object, the issue is almost always in the sensor feedback path or the PID derivative gain. Use this decision tree to troubleshoot.
Why does the steel ball instantly snap to the electromagnet and stick?
Cause: Your Derivative (D) gain is too low, or your PWM frequency is too slow. The controller sees the ball moving upward but doesn't cut the current fast enough to stop it before it hits the core.
Fix: Increase the D-gain multiplier in your code. If that fails, verify your PWM frequency is at least 20kHz. Check your MOSFET gate resistor; if it is too high (e.g., 10kΩ), the MOSFET is switching too slowly to react to the PID loop.
Why does the ball drop immediately when I let go of it?
Cause: The Hall effect sensor is either wired backward, placed too far from the core, or the ADC reference voltage is mismatched.
Fix: Put a multimeter on the SS49E output pin. With no magnet present, it should read exactly 2.5V (half of Vcc). When you bring a magnet close, the voltage should swing toward 0V or 5V depending on polarity. If it reads 0V or 5V at rest, your sensor is saturated or wired incorrectly. Consult the Texas Instruments Hall Sensor guidelines for proper biasing.
Why does the ball levitate but vibrate violently and buzz?
Cause: Proportional (P) gain is too high, causing the system to overcorrect, or there is mechanical resonance in the sensor mount.
Fix: Lower the P-gain until the vibration stops, then slowly increase the D-gain to tighten the hold. Ensure the Hall sensor is potted or glued firmly to the electromagnet core; if the sensor vibrates independently of the coil, the PID loop will read phantom gap changes and amplify them into the coil current.
Building an active magnetic levitation circuit is one of the most rewarding ways to bridge the gap between abstract control theory and physical hardware. By respecting the math behind the air gap and ensuring your sensor feedback loop is as fast and noise-free as possible, you can achieve perfectly stable suspension on your workbench.






