Magnetic Levitation with Arduino

magnetic levitation with arduino.

Hello friends this is another magnetic levitation project done with arduino.

The suspended ball is a permanent magnet. Distance of the ball 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.


In simple term when a ball moves away from hall effect sensor the PWM output is increased to cause more current flow in the coil and that produces more magnetic field causing the  ball to move upward.

Opposite case: When the ball has come closer to hall effect sensor PWM output by arduino is decreased causing less electromagnetic field, and gravity does rest of the work.

This algorithm can be implemented linearly also but by implementing PID proportional output (when error is higher output is higher , for low error output is lower)


here is a video in action.

Here is the link to the article which describes the operation.

Incoming search terms:


  1. Lila says:

    Hello Adrian,This is my first Arduino and I also want to make exactly the same thing as you did but i have stelbmud across a serios of problems because some of the code that I am using in my arduino is writen in romanian and I don’t know exactly what to change in my code.Could you please help me ? The thing is that my arduino has Temperature, Humidity, Pressure and light sensor and there is a lot of code I must go through.Kind Regards,Flaviu Vlaicu

Speak Your Mind