I followed everything from this project but still, the magnet is not levitating - https://www.hackster.io/jsirgado/magnet-levitation-with-arduino-eeeee4

The best I can do is to make the magnet jump up and down fast but it never levitates. Have tried changing PID setting from the project as aggressive and mild but still didn't achieve the final result.

I need advice from an expert to tell me what I am doing wrong here. All components are in good condition and 5v electromagnet is strong enough.

So what am I missing here? will implementing fast PWM mode be helpful?

  • I'd try to hold the magnet in your hand, and hold it at different positions, and feel if the system is trying to move the magnet, like you want it to. There't to many factors that could be different to the hackster project, like magnet strength, weight, coil strength, coil diameter, coil resitance(, your latitude on the planet).
    – Gerben
    Apr 2, 2019 at 13:44
  • I tried that and for me, it vibrates up-down and even sideways. How do I dampen this vibration to make it stable? Will the fast PWM mode help here?
    – suu
    Apr 2, 2019 at 14:25
  • That sounds like it's over-correcting. Not sure what to do about that. I'm not that familiar with PID.
    – Gerben
    Apr 2, 2019 at 14:50
  • @suu if it vibrates my guess is that your PID gains are to strong. What happens when you experiment with the gains while holding the magnet? Have you tried changing the position of the hall sensor? I don't think changing to fast pwm will make a change...
    – Sim Son
    Apr 2, 2019 at 18:22
  • Maybe the magnet has an inductance too high to adjust the magnetic field fast enough. You would then loose resolution which is already very limited on an uno and which will worsen the quality of your control loop. The same applies to the analog measurement, you should try to use the 10 bits you get from the arduinos adcs as good as possible. For debugging you can monitor the dutycycle and the analog reading.
    – Sim Son
    Apr 2, 2019 at 18:36

1 Answer 1


The answer to the solution was quite simple. I just had to comment out all serial port reading and Arduino processing became 60 times faster which helped to levitate the magnet. Thanks to everyone who helped me here :)

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.