Do-it-yourself magnetic levitation is the practice of suspending an object in mid-air using actively controlled electromagnetic fields to counteract gravity and overcome Earnshaw's theorem. In a real circuit, this transforms a static DC power supply into a high-speed, closed-loop feedback system requiring microsecond PWM switching and precise analog current sensing. Makers commonly confuse this with passive magnetic levitation, mistakenly believing that arranging permanent magnets in a specific geometry can achieve stable suspension without active electronic control or diamagnetic materials. To actually build a stable floating display or magnetic bearing on your workbench, you must design a control loop that reacts faster than gravity can pull the object down.
The Physics Constraint: Earnshaw's Theorem and Active Feedback
Earnshaw's theorem dictates that no stationary arrangement of permanent magnets can maintain a stable equilibrium in all three axes. If you try to levitate a neodymium magnet over another permanent magnet, it will inevitably flip and snap to the side. To bypass this physical limitation, DIY builders use active electromagnetic suspension. By placing an electromagnet above the object and continuously adjusting its current based on the object's exact position, you create a dynamic equilibrium.
The core of this system relies on a linear Hall effect sensor—such as the SS49E—which outputs an analog voltage proportional to the magnetic flux density passing through it. As the suspended object drops, the magnetic field at the sensor weakens, the voltage drops, and a microcontroller increases the PWM duty cycle to the electromagnet, pulling the object back up. This loop must execute in under a millisecond to prevent visible oscillation.
DIY Maglev Topologies Compared
Before winding coils, you must choose a topology. The table below breaks down the three primary approaches used in hobbyist and prototype environments, detailing the real-world electrical and mechanical trade-offs.
| Topology | Mechanism | Typical Air Gap | Power Draw (Steady State) | Control Complexity | Best Use Case |
|---|---|---|---|---|---|
| Top-Pull (EMS) | Electromagnet pulls upward against gravity | 10mm - 25mm | 10W - 25W | High (Requires PID loop) | Desktop displays, magnetic bearings |
| Bottom-Push (EDS) | Repulsion via induced eddy currents | 5mm - 15mm | 50W - 150W (AC) | Low (Passive at speed, active at start) | High-speed tracks, heavy payloads |
| Diamagnetic | Repulsion from pyrolytic graphite | 1mm - 3mm | 0W (Passive) | None (Inherently stable) | Micro-sensors, NEMS/MEMS devices |
| Inductrack | Halbach array over unpowered coils | 20mm - 50mm | Propulsion only | Moderate (Propulsion control) | Scale model trains, flywheel storage |
For 95% of do it yourself magnetic levitation projects, the Top-Pull Electromagnetic Suspension (EMS) is the only viable choice. It operates on standard DC voltages (12V to 24V), uses readily available microcontrollers, and allows for visible, impressive air gaps.
Sizing the Electromagnet and Hall Effect Sensor
Let's run a worked numeric example to size the components for a top-pull EMS system levitating a 50g neodymium magnet at a 15mm air gap.
First, calculate the required continuous upward force. Using Newton's second law ($F = m \times g$):
Force = 0.05 kg × 9.81 m/s² = 0.49 N
Magnetic force drops exponentially with distance. An off-the-shelf 12V electromagnet (like the ZYE1-P20/15) might pull 5 kg at a 0mm gap, but at a 15mm gap, the force degrades to roughly 0.8 N. This gives us a safety margin. To maintain this 0.8 N pull continuously, the coil must draw approximately 1.2A at 12V.
Power Dissipation = 12V × 1.2A = 14.4W
Dissipating 14.4W of heat inside a tight copper winding is a major failure point. If you use standard 26 AWG magnet wire, the resistance will be too high, and the enamel insulation will melt, causing an inter-turn short circuit. You must wind the coil with 22 AWG or 24 AWG polyurethane-coated copper wire over a low-carbon steel or pure iron core (20mm diameter). Aluminum cores will not work, as they lack the necessary magnetic permeability to concentrate the flux lines.
Bill of Materials: 12V Top-Pull Maglev Circuit
| Component | Part Number / Spec | Role in Circuit |
|---|---|---|
| Microcontroller | Arduino Nano V3 (ATmega328P) | Runs PID control loop at 1kHz |
| Magnetic Sensor | Honeywell SS49E Linear Hall | Provides analog gap measurement (1.75V to 4.5V) |
| Power Switch | IRFZ44N N-Channel MOSFET | Handles up to 49A; switches 12V coil via PWM |
| Freewheeling Diode | 1N4007 or 1N5819 Schottky | Protects MOSFET from inductive voltage spikes |
| Power Supply | 12V 5A Switching PSU (60W) | Provides headroom for transient current spikes |
Where You Meet This in Practice
While floating globes and desk toys are the most visible consumer applications of do it yourself magnetic levitation, the underlying circuit theory scales directly into heavy industry and advanced engineering. Understanding the PID-to-MOSFET feedback loop you build on your bench translates directly to:
- Active Magnetic Bearings (AMBs): Used in industrial centrifuges, flywheel energy storage systems, and turbomolecular vacuum pumps. These use radial and axial EMS topologies to spin rotors at 50,000+ RPM without mechanical friction or lubrication.
- Vibration Isolation Tables: Optical and semiconductor inspection tables use voice-coil actuators and Hall sensors to actively cancel out sub-micron floor vibrations, employing the exact same derivative-control math used in DIY maglev.
- Maglev Transit Prototypes: While full-scale trains (like the Shanghai Transrapid) use massive 3-phase linear synchronous motors, university research teams frequently build 1:20 scale EMS test tracks using the same IRFZ44N MOSFET drivers and linear Hall sensors found in hobbyist kits.
When you debug a 20kHz PWM oscillation on your Arduino, you are solving the exact same control instability problems faced by engineers tuning a 5-ton maglev bogie.
PID Tuning and Circuit Failure Modes
The most critical software component in your build is the Proportional-Integral-Derivative (PID) controller. Using the standard Arduino PID Library, you must tune three variables to achieve stable levitation. Misunderstanding these parameters is the primary reason DIY builds fail to hold the magnet steady.
- Proportional ($K_p$): Acts as the virtual spring. If $K_p$ is too low, the magnet falls. If $K_p$ is too high, the magnet snaps violently to the electromagnet core.
- Derivative ($K_d$): Acts as the virtual shock absorber (damping). This term looks at the rate of change of the error. Without sufficient $K_d$, the magnet will bounce endlessly. In magnetic levitation, $K_d$ is often the dominant term required to stop low-frequency oscillation.
- Integral ($K_i$): Corrects steady-state error. In a top-pull system, gravity is a constant disturbance. $K_i$ slowly ramps up the baseline PWM duty cycle to hold the object without requiring a position error to exist. Keep $K_i$ very low to prevent integral windup, which causes the magnet to crash if it is bumped.
Common Bench Failure Modes
Even with perfect code, hardware realities will disrupt your levitation. Watch for these specific failure modes:
setPwmFrequency() function to push the PWM to at least 20kHz (ultrasonic). This moves the switching noise out of the human hearing range and drastically reduces core hysteresis losses.
Another frequent failure is Hall sensor saturation. The SS49E outputs a linear voltage between 1.75V and 4.5V. If the suspended neodymium magnet gets too close (under 5mm), the magnetic flux density exceeds the sensor's linear range, and the output clips at 4.5V. The microcontroller reads this as 'object is too far away' and drives the PWM to 100%, instantly snapping the magnet to the core. To prevent this, wire a 10kΩ trimpot in series with the sensor's VCC line to artificially scale its output, or physically recess the sensor 2mm deeper into the iron core.
Finally, never omit the freewheeling diode across the electromagnet coil. An electromagnet is a massive inductor. When the MOSFET switches off, the collapsing magnetic field induces a voltage spike ($V = -L \frac{di}{dt}$) that can easily exceed 100V, instantly punching through the gate oxide of your IRFZ44N and destroying the microcontroller's I/O pin. A simple 1N5819 Schottky diode, oriented with the cathode facing the 12V rail, safely clamps this flyback voltage and protects your entire circuit.






