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?
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.