When it comes to magnetic levitation, there are two kinds of levitation: attractive and repulsive. In this guide, we're going to use an attractive levitation circuit as it's a lot easier to get working. As we know, a magnet has two poles, north and south. Magnetic fields with the same polarity repel each other, whereas opposite poles attract. With magnetic levitation we need a fixed magnetic field, provided by permanent magnets, and a magnetic field that we can control to position the permanent magnets.
To create a magnetic field that can be controlled, we can use an inductor. Inductors store energy similar to capacitors; while capacitors store voltage in the form of an electric field, inductors store current by generating a magnetic field. Here we'll be using the magnetic field of an inductor to interact with the magnets. With attractive levitation the inductor is used to oppose the force of gravity which then attracts the magnet up to the inductor.
If the magnet gets too close to the inductor, the magnet's field strength will be strong enough to stick to the inductor, regardless of how much current is passing through the inductor. However, if the magnet is too far away from the inductor, the magnetic field strengths will be too weak relative to gravity to be pulled back up. So the trick is to find the window where magnet isn't strong enough to pull itself up on its own, but with the attraction of the inductor's opposing field the magnet is able to overcome gravity. To keep track of its position, we'll use a magnetic field sensor, called a hall effect sensor.
Hall Effect Sensor
A hall effect sensor is a device that is used to measure the strength of a magnetic field. The output of the sensor is directly proportional to the magnetic field strength passing through it. The sensor we'll need is the SS496B, which has an analog voltage output. There are other hall effect sensors that act as a switch and only turn on or off in the presence of a magnetic field. In the next section we'll see how the sensor responds to the presence of our magnets.