Skill & Curiosity

DIY magnetic levitation toys

DIY magnetic levitation toys

CostLow to Medium

Includes: Electromagnet components, Hall effect sensor, Arduino, power transistor. Example: Total parts cost €30-50.

What it is

A magnet cannot simply hover above another magnet and stay there. A theorem proved in 1842 guarantees that any static arrangement of magnets is unstable, so the floating object always flips or escapes. Stable levitation has to cheat that rule, and learning how it cheats is the whole fascination of the project.

DIY magnetic levitation uses the interaction between permanent magnets and electromagnets to suspend an object in mid-air with no visible support, one of the most visually stunning demonstrations of electromagnetic force a home builder can make. An object that appears to defy gravity is genuinely captivating, and the stability is achieved through rapid electronic feedback that adjusts the electromagnet's current to hold the object at a constant height. Because Earnshaw's theorem rules out static levitation, the two real routes are dynamic spin stabilisation, like a levitating spinning top, or active feedback control, where a sensor watches the object's position and constantly corrects.

A feedback levitator is built from a handful of parts: an electromagnet, a ferrite core wound with a few hundred turns of wire, a Hall effect sensor positioned just below where the object floats, a controller, and a power transistor to modulate the coil current. The control loop is the clever bit. The Hall sensor measures how close the magnet is; if it is too close, the current drops, and if too far, the current rises, and this loop runs over a thousand times a second to hold the object suspended at its equilibrium point.

The reason feedback is unavoidable is that the magnetic force is nonlinear, rising with the inverse square of distance, so a tiny change in position causes a large change in force. That inherent instability is what makes static levitation impossible and feedback essential, and the sensor's job is to linearise it so the controller can compensate.

The hard part is tuning. Start with proportional control alone, raising the gain until the object barely holds, then add derivative control to damp the oscillation, because pure proportional control just oscillates and never settles. Get it right and you have a spectacular, genuinely wondrous object on your desk.

How it works

Everyone reaches for pure proportional control first and watches the object oscillate wildly and fling itself off, then assumes the build is broken. It is not. Stable levitation is impossible with proportional control alone, because the magnetic force is non-linear and inherently unstable, and you must add derivative control to damp the motion. Knowing this before you tune saves enormous frustration.

The build is a feedback loop. An electromagnet, a ferrite core wound with 200 to 500 turns of enamelled wire, hangs above where the object floats. A Hall effect sensor like the A1302, positioned just below the levitation point, measures the magnetic field strength, which tells the controller how close the object is. A power transistor like a TIP120 modulates the current through the electromagnet, and an Arduino runs the control loop that ties it together, all from a regulated 12V supply.

The loop logic is simple to state and hard to tune. The Hall sensor reads the object's position; if it drifts too close, the controller cuts the current so the pull weakens, and if it drifts too far, it increases the current. This runs over a thousand times a second to hold the object suspended at its equilibrium point. The object itself must contain a neodymium magnet and weigh within the electromagnet's lifting capacity, so a small sphere with a disc magnet inside, two to five grams, is ideal to start.

Tuning is the real work and the order is fixed. Raise the proportional gain until the object just barely holds position, then add derivative gain to settle the oscillation, because derivative control responds to how fast the object is moving and brakes it before it overshoots. What actually happens without enough derivative is a violent oscillation that grows until the object escapes, every time.

Benefits

Visually Spectacular Result Electromagnetism Understanding Control Systems Introduction PID Controller Experience Impressive Technical Achievement Creates Genuine Wonder

What you need

Here's what to gather before you start. The essentials are marked.

Some links below are affiliate links. As an Amazon Associate, trylii.com earns from qualifying purchases, at no extra cost to you.

Ferrite core electromagnet
Hall effect sensor (A1302)
Arduino

SuggestedAffiliate

Arduino

View on Amazon
Power transistor (TIP120)
Neodymium disc magnet (to levitate)

SuggestedAffiliate

Neodymium disc magnet

View on Amazon
Regulated 12V power supply

SuggestedAffiliate

Power supply

View on Amazon

FAQs

Yes, though stable levitation is trickier than it looks. Magnets naturally want to flip or slide rather than hold still in the air, so simply stacking repelling magnets won't make a stable floating object. The achievable home versions use either a spinning top (the Levitron principle) or a small electromagnet with a sensor that actively corrects the position thousands of times a second. Both genuinely float objects, just by different tricks.

Because of a physics rule called Earnshaw's theorem, static magnets can't hold a stable floating position. The floating magnet always finds a way to flip or escape sideways, no matter how you arrange fixed magnets. That is why every working levitation toy adds something extra: spin to stabilise it like a gyroscope, or active electronic correction. Understanding this saved me hours of trying to make a stack of magnets do the impossible.

A Levitron-style spinning top, if you have patience for the setup. It floats by spinning fast enough that gyroscopic stability keeps it from flipping, balanced precisely above a magnetic base. The catch is fiddly tuning of the weight and the spin, which tests patience. An electromagnetic levitator with a Hall sensor and a small circuit is more reliable once built, but it needs basic electronics, so the top is the gentler mechanical starting point.

A sensor watches the object's position and an electromagnet constantly adjusts to hold it. A Hall effect sensor detects exactly where the floating magnet is, and a control circuit adjusts the electromagnet's pull many times per second, catching the object before it can fall or fly up. This active feedback sidesteps the stability problem entirely. It is the same principle behind those levitating globes and speakers, and building one teaches real control-systems thinking.