I am planning on making a magnetic levitation system with an arduino that checks the value of a hall's effect sensor twice per second (but I have tried even 1000 times a second though) and turns the electromagnet on or off based on the hall's effect sensor's value. I have managed to check the output voltage of the sensor and turn the electromagnet on/off too but when a magnet is placed below the electromagnet it either sticks to it (then falls) or falls immediately. Now I am starting to believe that my idea is impractical but before I abandon my project, I'd like to know: is my idea practical? Can it be done? If so do you have any advice on what could be wrong? If not what can I do to make it practical?

  • \$\begingroup\$ Twice a second seems impractically slow unless your object is enormous. \$\endgroup\$ Aug 25, 2015 at 23:00
  • \$\begingroup\$ @SpehroPefhany I have tried checking every millisecond but even then I haven't seen any improvements. BTW the object is roughly 100 grams \$\endgroup\$ Aug 25, 2015 at 23:03
  • \$\begingroup\$ Without knowing the active range for the Hall Effect sensor, and also the attractive strength of the magnet to the object, it's impossible to be sure. Also, the time constant of the coil. However, you probably need response times in the 10s to 100s of KHz, which generally requires much better control than banging the coil on and off. \$\endgroup\$ Aug 25, 2015 at 23:13
  • \$\begingroup\$ @WhatRoughBeast sorry but most of what you said didn't make sense to me :p I'm more of a programmer than an electrical engineer. From your comment all that made sense to me was that I need to have a more sophisticated system that doesn't just "bang the coil on and off". Now the question is: what should it do? \$\endgroup\$ Aug 25, 2015 at 23:26
  • \$\begingroup\$ Where is the hall sensor located? On the moving magnet or on the stationary coil? \$\endgroup\$ Aug 25, 2015 at 23:48

1 Answer 1


Your design is fundamentally a feedback control loop where the position is actuated by an electromagnet and measured by a pair of Hall effect sensors. At the core, such a design is practical but there are some critical details that merit close attention:

  • Your method for measuring the displacement of the magnet is a bit questionable here because the sensor will also be influenced by the electromagnet turning on and off. Even though you use two sensors to attempt to account for this, the cancellation is not perfect and thus you will have some component of positive feedback. Consider some other displacement sensor.
  • You are only allowing the coil to be on or off. This will make it much more challenging to stabilize. Consider an anlog current source for the electromagnet and a PID controller.
  • You are only sampling at 2-1000Hz. You may need to go faster than that. It depends on the other time constants in the system (which should be measured).
  • The magnetic system is far from linear. This further complicates control.

In short, it is possible but far from trivial.

  • \$\begingroup\$ I'm not sure how I could use a PID controller as I have never used one before but I assume I could use an analog current source with an arduino. Do you think that would work better? Also, what could I use instead of the displacement sensor I am currently using? I can't think of anything other than a fixed value in the code but that would be even worse \$\endgroup\$ Aug 26, 2015 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.