· 2 MIN READ

Levitation Is a Control Problem

Build log from the maglev platform: why magnetic levitation is fundamentally unstable, and how a Hall-effect sensor, a handful of op-amps, and an Arduino impersonating a PWM chip hold a platform in mid-air.

  • #hardware
  • #controls
  • #arduino
  • #build-log

There's a moment in the maglev project that I keep coming back to. The platform is floating — actually floating — and then someone closes the lab door a little too hard. The platform wobbles, catches itself, and settles. That tiny recovery is the entire project. Everything else is just parts.

Why levitation doesn't want to happen

Take an electromagnet, hang a permanent magnet under it, and try to hold it at a fixed gap. Earnshaw's theorem says you can't — not with static fields. The intuition is simpler than the theorem: magnetic attraction grows roughly with the inverse square of distance. Move the magnet a hair closer and the pull gets stronger, yanking it closer still. A hair farther, and the pull weakens and gravity wins.

The equilibrium exists, but it's like balancing a pencil on its tip. Any disturbance grows exponentially. The time constant for my geometry is on the order of tens of milliseconds — which tells you immediately that no human, and no slow control loop, can stabilize it. The loop has to be electronic.

The loop

The architecture is the classic one:

  1. Sense. A Hall-effect sensor under the platform reads field strength, which maps (nonlinearly, but monotonically) to the air gap.
  2. Decide. The error against the setpoint becomes a correction. My first version was purely analog — proportional control via op-amps.
  3. Actuate. The correction modulates PWM duty cycle into the electromagnet's driver, changing the average coil current.

The fun engineering decision was the controller itself. The original circuit used a MIC502 — a fixed-function PWM controller IC. It works, but tuning the loop means physically swapping resistors and capacitors. So I replicated the MIC502's behaviour on an Arduino: same input, same PWM output, but now the gains live in firmware.

// The heart of it — embarrassingly small for something that defeats gravity
int gap = analogRead(HALL_PIN);
int error = setpoint - gap;
int duty = constrain(BASE_DUTY + KP * error, 0, 255);
analogWrite(COIL_PIN, duty);

Replacing a chip with code felt like cheating until I realized that's just… mechatronics. The discipline is choosing which parts of the loop deserve silicon, which deserve firmware, and which deserve a better mechanical design.

The mechanical part nobody talks about

Half my time on this project has gone into SOLIDWORKS, not circuits. A 1D controller can only reject disturbances along its one axis. If the solenoid axis isn't precisely vertical, every correction has a small sideways component, and the platform slowly walks itself out from under the magnet — and there is nothing the controller can do about it, because it can't even see that axis.

So the electromagnet mounts went through multiple design iterations purely to guarantee vertical alignment of the solenoid axis. The lesson, which I suspect generalizes to most of engineering: when the controller seems broken, check the mechanics first.

What's next

Stable levitation is the boring part now. The goal this project is named for is linear motion — a rail of coils handing the platform off to each other, which turns one control loop into a scheduling problem across many. That's the next build log.