Hello, here is a magnetic levitation project realized with arduino. The suspended ball is a permanent magnet whose distance from the electromagnet is measured by a hall effect sensor placed under the coil. The digital control loop is a PID algorithm that modulates a PWM output to energize the electromagnet through a MOSFET. A voltage regulator is used to provide a fixed voltage and to limit the current in the coil (the schematics can be found in attachment).

You can find the sketch file in attachment. Basically it consists in the following functions:

1) PWM setup to change the frequency from the default value (490 Hz) to 3921 Hz;2) A command handler used to configure the controller gains and setpoint through the serial line (when arduino is connected to USB cable);3) A state machine that manages the transition between OFF, IDLE and CONTROL modes (this to avoid the controller to turn on the electromagnet at full power when the ball is not in range);4) The control loop.

Thanks much for sharing. I have a very similar project, but I'm driving the magnet through a D/A and then an opamp instead of with a PWM signal. I'm wondering if you ran into problems with the hall effect picking up both the field of the electromagnet and the field of the levitated magnet. I was planning on using two hall effect sensors (one at each pole of the electromagnet) and looking at the difference in the signals. This should give a good reading on the levitated magnet.

Also, how did you come up with your PID values? Did you model the system in Matlab or something similar? Or did you just experimentally come up with the values?

Super cool! I'll think about making this or having this made. That's the fun of being a teacher, you can order students to make things and that's all for their learning Considering this for instrumentation course because of PID and its application, also as a PR show item like my rotating stage with POV display.

I thought Si had one and thanks for posting so someone looking for this later sees two projects to learn from!