Maglev Assembly Guide

You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
You are viewing the PRELIMINARY 6.3100 Fall 2026 web site. Please note that information on this page may change throughout the semester, please check back frequently.

The Maglev Sketch

Download the sketch for the magnetic levitator: 6310_MAGLEV_F26.zip.

You will edit these constants near the top of the sketch:

LineConstantMeaning
11MODE0: open loop (the coil command is the input waveform), 1: PD feedback, 2: state space
12–14SensA, SensB, SensCDistance-sensor fit, \Delta y = (a\,x + b)/(c\,x + 1)
15crntSignSign of the field-sensor reading (+1.0 or −1.0)

To change a parameter while the sketch runs, type its index, a space and a value in the serial plotter's send window, then click Send. For example, 3 4 sets the proportional gain to 4, and 5 0.5 sets the input frequency to 0.5 Hz.

IndexParameter
0Extra samples for the derivative estimate (ExtraB)
1Derivative gain, K_d
2Integral gain
3Proportional gain, K_p
4Plot spacing (Skips)
5Input frequency (Hz)
6Input amplitude: >0 square wave, <0 sine
7Coil-current gain (state space, later labs)
8Reference scaling, K_r (state space, later labs)
Tip: the plots may be easier to read in the Arduino IDE's dark theme (Settings → Theme).

Maglev in Action

PD control
PD control with sensor-nonlinearity inversion
Lead control with sensor-nonlinearity inversion

These videos show a previous term's setup. With PD control the coil command is very noisy, and that noise eventually knocks the umbrella loose. The lead controller takes much larger steps with far less command noise, though not zero.

Rare-earth magnets are dangerous. They are brittle, and when two of them slam together they can send sharp fragments flying. Keep the umbrella away from other magnets and from steel tools.
The coils get hot. Driving the coils hard for a long time heats them up. Unplug the high-current (driver) power supply whenever you are not actively testing, and if a coil is too hot to touch comfortably, unplug the supply and let it cool before continuing.

Assembling the Maglev

This term's build is faster than in past terms, and its frame holds the three steel rods, and so the electromagnet, level. Work through the steps in order. Each photo shows what you should have at that point.

Step 1: Collect the parts

Everything you need, laid out.

The magnetic umbrella. The umbrella is a 3-D printed holder for a neodymium magnet. Its flat top is a diffuse infrared reflector for the distance sensor, and a flat-head machine screw hangs below it. If the magnet is loose, tighten the screw.

Parts of the umbrella. The machine screw can be tightened if the magnet is loose.
The whole umbrella, showing the flat-head screw

Add the small magnets to the bottom of the umbrella: stick the disc magnet onto the head of the screw, then hang the stack of three small cylinder magnets below the disc.

Disc magnet
Three cylinder magnets, stacked
Disc and cylinder magnets attached below the screw head
Three electromagnet coils and the controller board
Three steel rods (the electromagnet cores)
Sensor-and-rod bracket (right) and field-sensor holder (left)
Hall-effect field sensor (top) and optical distance sensor (bottom). Course staff install the optical sensor in the sensor bracket for you.
Calibration attachment
Ten-conductor pin-to-socket cable (red on the left, orange on the right)
Compass
Table clamp

Step 2: Collect the Lego parts

About brick colors: we name the colors of the bricks only so you can find them in our photos. Any color of 2×8 brick works just as well, so use whatever colors you have.

Base plates, beams, bricks and pegs
Four long black Technic beams
Technic bricks
Magenta and gray beams
Three 2×8 Technic plates (gray or green both work)
Two yellow axles
Black pegs
Red pegs (rod retainers)

Step 3: Build the two side arms

Pin the long black Technic beams together in pairs, then add the magenta and gray beams and the yellow bricks at the ends.

Long beams with pegs
Beams pinned together in pairs
Magenta and gray beams added
Yellow bricks added at the ends

Step 4: Build the base

Join the gray plates with the green plate, leaving the square opening shown. Underneath, magenta bricks tie the plates together.

Top
Bottom
Bottom, with magenta bricks

Step 5: Attach the side arms to the base

Arms attached
Red bricks added; the yellow end bricks will hold the outer rods

Step 6: Wire the coils and mount the electromagnet and controller board

Prepare each coil wire: twist the stranded copper tightly, then trim the bare end to about ¼". Screw each wire into its driver terminal so that only insulated wire shows outside the terminal. Loose strands outside the terminal can short to the neighboring wire.

Stranded wire, as supplied
Twist the strands tightly
Trim the bare end
About ¼" of bare wire
✔ Correct: no bare wire outside the terminal
✘ Wrong: bare strands outside the terminal

Connect the coils to the driver terminals:

CoilTerminals
LeftA1L, A2L
CenterB1L, B2L
RightA1R, A2R

Slide the coils onto the steel rods, with the sensor bracket at the center and the coil wires on top. Then set the electromagnet and the board onto the base.

Coils wired to the board: left to A1L/A2L, center to B1L/B2L, right to A1R/A2R
Electromagnet and controller board in place, with each coil and its driver terminals labeled

Step 7: Build and attach the cover bar

The cover bar holds the center coil in place. Build it from three 2×8 Technic plates (gray or green; either color works), eight 2×4 Technic bricks, and two yellow axles, as shown below. The plates and bricks form a plate-brick-plate-brick sandwich, and the two yellow axles pass through it to stiffen it.

Press the cover bar onto the frame so that the two bricks hanging below it (red and magenta in the photos) push tightly against the black plastic end plate of the center coil, fitting snugly around the studs on that end plate.

Cover-bar parts
Assembled cover bar (top)
Assembled cover bar (side)
Cover bar in place over the center coil
Top view: the red and magenta bricks sit on either side of the center coil's end plate
Close-up: the bricks fit tightly around the studs on the coil's black end plate
Front view, looking along the center coil

Step 8: Lock the outer rods in place

Push red pegs into the arms beside each outer rod, so the rod cannot roll or slide.

Red pegs beside the rod
Close-up
Rod resting on the yellow brick
Both outer rods locked; the electromagnet is level

Step 9: Make the two sensor cables

Both sensor cables come from one ten-conductor pin-to-socket cable, with red on the left and orange on the right. Peel it apart from one end to the other into three strips:

  • red, brown, black (three conductors) for the magnetic-field sensor;
  • white, gray, purple (three conductors), not used in this lab;
  • blue, green, yellow, orange (four conductors) for the optical distance sensor.
Peel slowly and keep each strip together, so its wires stay neatly bundled.
The ten-conductor pin-to-socket cable
The three strips: red-brown-black (field sensor), white-gray-purple (unused), and blue-green-yellow-orange (optical sensor)

Step 10: Connect the optical distance sensor

Course staff have already installed the optical sensor in the sensor bracket. Plug the sockets of the blue-green-yellow-orange cable onto the sensor's four leads, and route the cable over the cover bar to the board's header. Keeping it away from the coil wires reduces noise.

WireBoard pin
Yellow3V (not 5V)
GreenIN5
OrangeO3
BlueO4

The sensor runs from the 3V supply because the 5V supply is not well regulated, and supply ripple would show up as noise in the distance reading. Also add a 10 kΩ resistor (brown-black-orange) from IN5 to the neighboring Gnd, as shown below. The resistor sets the sensor's output range.

Optical-sensor connections: blue to O4, orange to O3, green to IN5, yellow to 3V, and the 10 kΩ resistor from IN5 to Gnd
The wires are only long enough to reach the optical sensor if you bend the pins as shown in the figure above. Note that the 10k resistor was removed from this picture to make the wire bending easier to see, please be SURE to include the resistor!
Increase the wire slack by tilting the controller board up while connecting optical sensor.
Be sure to tilt the controller board back down when done.
Sensor in the bracket
Four-conductor cable attached
Close-up of connections

Step 11: Add the magnetic-field sensor

The field sensor is a DRV5055 Hall-effect sensor (range A2, marked "55A2" on its face). Its output voltage is proportional to the magnetic field through it. With the marked face toward you, its leads are 5V, GND and Vout, from left to right.

DRV5055 Hall-effect field sensor and its pinout

Plug the sensor's leads into the sockets of the red-brown-black cable, push the sensor into its holder, and mount the holder at the end of the center rod. Note that the black (ground) wire, which is on the outside of the strip, goes to the sensor's middle pin. Then plug the cable's pins into the board's header:

WireSensor leadBoard pin
Red5V5V
BlackGND (middle pin)Gnd
BrownVoutIN1
Field-sensor wiring: at the header, black to Gnd, brown to IN1 and red to 5V; at the sensor, black goes to the middle (GND) pin

Step 12: Add bricks to hold the board

Press a few more bricks onto the base around the controller board, so the board cannot slide: a yellow 2×4 Technic brick at the top right, a yellow brick on the left side above the red bricks, and a magenta brick on the right side, as in the photo.

Top view of the finished maglev: both sensors connected, the 10 kΩ resistor in place, and the extra bricks around the board (yellow at the top right, yellow on the left, magenta on the right)

Step 13: Clamp the maglev to the bench

The electromagnet must overhang the bench edge so that the umbrella can hang freely below it.

Front
Side

Checking the Coil Directions

All three coils must produce fields in the same direction. If one is reversed, it fights the other two, and the umbrella will not float.

  1. Connect your laptop and both 5V supplies (USB and driver) to the board; both power lights should be on.
  2. Set MODE to 0 on line 11, upload the sketch, and open the serial plotter.
  3. Send a slow square wave: 6 1 (amplitude 1), 5 0.1 (0.1 Hz, so the command flips every 5 seconds) and 4 100 (slows the plot to match). Plot only Cmd.
  4. Set the compass on a brick, one brick-width from the end of each steel rod in turn, as in the videos below. The needle should swing back and forth as the command flips.
  5. For every coil, the needle should point north when Cmd is high.

Use the same compass for all three coils. These compasses are easily remagnetized, so two compasses may not agree with each other.

Left coil
Center coil
Right coil

If a coil's needle points south when Cmd is high, reverse that coil's command in the sketch: swap the last two arguments of its hbridgeBipolar call, upload again, and recheck.

208  cmdCL = my6310.hbridgeBipolar(coilCmd, B1L,B2L); // center: B2L <-> B1L swaps direction
209  my6310.hbridgeBipolar(coilCmd, A2L,A1L);         // left:   A1L <-> A2L swaps direction
210  my6310.hbridgeBipolar(coilCmd, A2R,A1R);         // right:  A1R <-> A2R swaps direction

After making needed swaps, retest the coils with the compass, they should behave like the examples below.

Matching the Field Sensor to the Command

Once all three coils agree, check that the field sensor's reading (Crnt) has the same sign as the coil command (Cmd). Later labs model the path from command to field, and a sign flip here would make that model wrong.

  1. Keep MODE at 0, with the sketch uploaded and the serial plotter open.
  2. Send 6 1 (square-wave amplitude 1) and 5 1 (1 Hz).
  3. Turn off every trace except Cmd and Crnt.
  4. Check that Crnt steps up when Cmd steps up, and down when Cmd steps down.

If Crnt moves opposite to Cmd, flip the sign of crntSign on line 15 of the sketch (-1.0 to 1.0, or the reverse), upload again, and recheck. If you later reverse the coil commands to fix the feedback sign (in the lab, when you first try feedback), you will need to flip crntSign again.

✔ Correct: Crnt (orange) steps the same way as Cmd (pink)
✘ Wrong: Crnt steps opposite to Cmd, so flip crntSign

Testing the Distance Sensor's Range

Check the distance sensor's reading at the two extremes of the umbrella's travel. (You will calibrate the sensor in the lab.)

  1. Keep MODE at 0, send 6 0 (amplitude zero), and plot only Sensor, the raw sensor reading x (between 0 and 1). In MODE 0 with zero amplitude, the potentiometer sets a steady coil command.
  2. Turn the potentiometer so that the electromagnet pulls the umbrella up. Leave it there for the rest of the range test.
  3. +15 mm: let the electromagnet pull the umbrella up against the sensor-and-rod bracket, and note the reading.
  4. −10 mm: clip the calibration attachment onto the bracket (photos below), and let the electromagnet pull the umbrella up against the bottom of the attachment. Note the reading.

Your readings should fall in these ranges:

PositionSensor reading
+15 mm (against the bracket)0.80 to 0.90
−10 mm (against the bottom of the attachment)0.06 to 0.16

If either reading is out of range, check the optical-sensor wiring, especially the 3V connection and the 10 kΩ resistor from IN5 to Gnd, then ask a staff member.

Calibration attachment clipped onto the sensor bracket
The attachment from the other side
+15 mm: umbrella pulled up against the sensor bracket
−10 mm: umbrella pulled up against the bottom of the attachment (front)
−10 mm (side)