<h1>Magnetic Levitation (1 inch gap, stable, low cost)</h1>
[video width="1280" height="720" mp4="http://johann.langhofer.net/wp-content/uploads/2018/04/VID_20180418_2122030.mp4"][/video]

I've found a simple solution for the magnetic challenge in order to get a stable levitation. After several experiments and a lot of research on the WEB I came up with a solution using a handful components, more particularly, only five electronic parts were needed: a power supply, an arduino, a handmade coil, a MOSFET and a hall-sensor. With a small piece of software running on the arduino, the magnetic cubes can be hold in a very stable position. But wait, it isn't so easy, I've got several issues and finally run into a serious problem, but finally I've got the magic solution...

Lets start with the big picture: an electromagnet with a coil and an iron core on the top attracts a floating magnet, a  hall sensor reads the magnetic strength in the gap between the two magnets. An electronic switch turns OFF the coil if the strength exceeds a certain value (threshold) and turns ON if the strength falls blow this threshold. The threshold is exactly the line, where the sum of the up-pointing forces are in balance with the gravity of the floating magnet.

<img class="alignnone size-full wp-image-588" src="http://johann.langhofer.net/wp-content/uploads/2018/04/bigPicture1.jpg" alt="bigPicture1" width="510" height="616" />

So what's the main problem trying to keep a magnet in a constant position from the electromagnet? Stability is the answer. In the configuration above, there are some facts that prevents the floating magnet in a stable position, even if the electromagnet is switched in a perfect timing with high precision and high frequency. Several articles on the WEB are describing this situation and most of them are recommending a PID controller. Well, to cut a long story short, I had no success with PID controllers, neither software-based nor hardware-based. But even if I had been successful, setting the PID-constants would be for one specific scenario only and I like a more general system, where I chan change the type/size/weight of the magnets without reconfiguring the software. Here you can see the cubes getting out of control:

[video width="1280" height="720" mp4="http://johann.langhofer.net/wp-content/uploads/2018/04/VID_20180419_0724230.mp4"][/video]

And here is the solution I came up after successless fighting against various PID controllers: using a damper plate does the magic job.

&nbsp;

Useful components:
<blockquote>Arduino Mini, Nano, Mega, laser 405nm
RaspberryPI I, II
WLan ESP8266
and much more.</blockquote>
[supsystic-gallery id=5 position=center]