Laird Scabar
All projects Mechatronics

Magnetic Levitation Device

A magnet held in mid-air by an analog control loop. I machined the aluminum, fabricated the sheet metal enclosure and hand-soldered the board from the schematic up. It earned the highest grade in the class, 98% out of 127 students, and it held levitation overnight.

Course
MECH 220, UBC
Grade
98%, highest of 127
Endurance test
~12 hours unattended
Control
Analog, no microcontroller
Longer, in-depth explanation Flip the switch for the full engineering breakdown

Quick explanation

What it is

  • A device that suspends a magnet in mid-air under an electromagnet, and keeps it there. It scored 98%, the highest grade in a class of 127.
  • Magnetic levitation is unstable by nature. Pull too hard and the magnet slams into the coil, too little and it drops. Nothing holds it up but a control loop correcting itself constantly.
  • A Hall effect sensor measures where the magnet is, an analog circuit compares that to where it should be, and a BJT adjusts the coil current to close the gap. No microcontroller, no code.
  • I machined the aluminum coil mount and the board stand on the lathe, mill, drill press and CNC router, working to the tolerances called out on the engineering drawings.
  • The enclosure is sheet metal I cut on the waterjet, bent on the press brake and joined on the spot welder.
  • I hand-soldered and brought up the whole board myself from the schematic, every component, and was the first in my section to finish assembly.
  • Tuned with the gain and offset pots, it held the magnet steady overnight, about 12 hours unattended.
The finished levitation device

Deep dive

How the device came together

Part 1: the problem

1. Why levitation is harder than it looks

  • An electromagnet pulling on a magnet is an unstable equilibrium. The closer the magnet gets, the harder it's pulled, so any tiny drift runs away in milliseconds.
  • There is no passive arrangement of magnets that holds this still. The only thing keeping it in the air is a loop measuring and correcting continuously.
  • That makes it a genuine control problem rather than an assembly exercise, and it's unforgiving: if the loop is wrong, the magnet either sticks to the coil or falls on the desk.
  • Everything else, the machining and the fabrication, exists to hold the sensor and the coil in exactly the right relationship so the loop has a chance.

Part 2: machining

2. Lathe, mill, drill press and CNC router

  • I machined the aluminum coil mount, the ring that clamps the coil bobbin and carries it out on the arm over the levitation point.
  • I also machined the aluminum stand under the board, which doubles as the heatsink for the BJT driving the coil. The transistor bolts straight to it so the aluminum pulls heat out of the device that's doing the current switching.
  • Between them that meant lathe work for the turned diameters and bore, mill work for the flats and faces, drill press for the holes, and CNC routing for the profiled geometry.
  • Everything came off a drawing package, so it was strict engineering drawings and strict tolerances, not "close enough". Dimensions, fits and finishes were specified and inspected.
  • That matters here more than on a typical shop part: the coil, the sensor and the magnet have to sit in a fixed geometric relationship, and slop in the mount turns into a loop that won't hold.
The machined aluminum coil mount

Part 3: sheet metal

3. Waterjet, press brake and spot welder

  • The enclosure is sheet metal, cut flat on the waterjet from the developed flat pattern.
  • Bent to shape on the press brake, which means the flat pattern had to account for bend allowance up front. Material stretches around a bend, so the flat is not simply the sum of the finished faces.
  • Joined with the spot welder, then fitted to the machined parts and the board.
  • The curved front panel and the swept arm are the parts that make it look finished rather than like a lab prototype, and they're the parts where a bad bend shows immediately.
The enclosure with the board on its machined stand

Part 4: the board

4. Bringing the whole board up myself

  • I was given the schematic and soldered and brought up the entire board from it myself, component by component, and was the first in my section to finish assembly.
  • That meant reading the schematic properly rather than following a pick-and-place list: knowing which part each reference designator pointed to, which way the polarised parts face, and what each section was for.
  • It's where op-amps stopped being a lecture topic. The board runs an LM324 quad op-amp, and each of its four sections does a different job in the loop.
  • Same for transistors: the BJT output stage drives real current through an inductive load, which is a different world from a logic-level signal, and it's why the output device needs a heatsink and the coil needs a flyback diode.
  • Hand-soldering every through-hole part cleanly, then testing section by section with the onboard test points, was what turned the schematic into something I actually understood.
The fully populated control board

Part 5: the circuit

5. What's actually on the board

  • Sensing: a DRV5055 Hall effect sensor sits above the levitation point and outputs a voltage proportional to the magnetic field, which is a proxy for how far away the magnet is.
  • Error and gain: the first LM324 section compares the sensor against the reference the offset pot sets, and a second stage amplifies that error through the gain pot.
  • Compensation: small capacitors around the gain stages give the loop a derivative term, responding to how fast the magnet is moving instead of just where it is. Without that damping the magnet oscillates instead of settling.
  • Current loop: a 0.1 Ω sense resistor under the coil feeds the coil current back into another op-amp section, so the circuit controls current rather than voltage, which is what actually sets the magnetic force.
  • Output: an NPN BJT drives the coil, bolted to the machined aluminum stand to shed heat. A flyback diode and an RC snubber sit across the coil to absorb the inductive kick when current changes.
  • Power: a barrel jack feeds a fuse, a reverse-polarity diode and a 5 V regulator. Three LEDs show 5 V present, power present, and coil current, so you can tell at a glance what the loop is doing.
  • Ten test points are broken out across the signal chain, which is how you debug an analog loop: probe along the chain until the signal stops looking like it should.
The levitation circuit schematic

Part 6: tuning

6. What the gain and offset pots do

  • The two blue trim pots on the underside of the board are how the device is tuned. They're the only adjustment it has.
  • Offset sets where the magnet should sit. It shifts the reference the sensor reading is compared against, which moves the equilibrium point up or down. It also cancels the sensor's own bias, since the Hall sensor outputs a voltage even with no magnet present.
  • Gain sets how hard the loop reacts to being off target. Turn it down and the correction is too weak, so the magnet sags and drops. Turn it up and the loop overcorrects, so the magnet buzzes, oscillates and throws itself off.
  • Tuning is finding the window between those two failures, then nudging the offset until the magnet hovers at a stable height with the coil current settled.
  • This is a PD controller built out of op-amps and passives: proportional from the gain stage, derivative from the compensation capacitors. Same control theory as a software loop, except you tune it with a screwdriver.
The gain and offset trim pots

Part 7: results

7. Twelve hours in the air

  • Once tuned, I left it running and it held the magnet levitating overnight, roughly 12 hours unattended.
  • That's the test that matters. Getting a magnet to float for thirty seconds is a tuning fluke; holding it for twelve hours means the loop is genuinely stable and the output stage is shedding its heat properly.
  • The project earned 98%, the highest grade in a class of 127 students.
  • What I took from it is how much the mechanical and electrical sides depend on each other. The loop only works because the machined parts hold the sensor and coil where the circuit assumes they are, and the circuit only survives because the heatsink was designed as part of the structure instead of added afterwards.