<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" loop="true"][/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 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. The target is to keep the magnet very close to this line.

<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 stability can't be reached even if the electromagnet is switched with  a perfect timing  and high frequency, after some seconds or minutes the system tends to oscillate. 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 configuration 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 finally here is my solution to fix this problem: using a damping plate/disc does the magic job. Putting a non magnetic, good electric conductor, such as aluminium or copper on top and/or bottom of your configuration will eliminate the oscillating due the lorentz force, which is generated by the induced current in the conductor and acts against the oscillating force.

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

However, to achieve a good damping factor, the plate/disc  must not be too far away from the magnet, it also depends how strong the magnet is. For my strong N42 cubes I'm using an aluminium disc with 6mm thickness, 40 mm of diameter and in a distance of approx. 15mm which is sufficient enough (disc at the lower section of the picture, the other discs are spacers):

[caption id="attachment_578" align="alignnone" width="1190"]<img class="size-full wp-image-578" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200844.jpg" alt="dav" width="1190" height="893" /> dav[/caption]

If the damping plate is too far away from the magnet, spacers can be used (non magnetic material such as plastic, acryl etc.). Good candidates for damping plates are also CPU heat sinks.

Finally, for my levitation system I can change magnets with different style, strength and size on the fly without reconfiguring the software. Sometimes, depending on the magnets, I have to remove/add a spacer, but this can be done without effort.

For people interested on how I built up the systen, here is some technical Information:

The system is supplied with a 7.5V power supply and draws a current of 40-50mA to hold the magnets (&lt; 400 mW). The power supply is connected to the arduino-nano Vin-pin and also to one end of the coil. The coil is not very critical, I used a 0.3mm wire and filled up the windings from 7 to 20 mm diameter. The coil length is 20 mm and the resistance is about 25 ohms. The other connection of the coil goes to the drain of a <span class="st">N-channel power MOSFET (<em>5N50</em> ),  the gate of the MOSFET is connected directly to an arduino output and the source is connected to the ground. For the magnetic sensor I'm using a Hall-Effect chip from Allegro (A1302), the output signal goes directly to an analog input of the arduino and the 5V supply is coming from the arduino pin. For optical effects I'm driving some Superleds (Apa102), but this is optional and has nothing to do with the core system. </span>

The software is using the arduino AD-Converter in free running mode and makes the decision whether to switch the coil ON or OFF after a conversion is completed. So the main loop is very straight forward:
<pre>void loop() {
  unsigned int sensorValue = analogNext();
  if (sensorValue &gt;= 622|| sensorValue &lt; 572) {
    digitalWriteD(3, 0);
  }
  else {
    digitalWriteD(3, 1);
  }
}</pre>
<span class="st">The whole sketch can be downloaded from <a href="https://raw.githubusercontent.com/androdlang/Magnetic-Levitation/master/levitation_core.ino">here</a>.
</span>

[caption id="attachment_579" align="alignnone" width="893"]<img class="wp-image-579 size-full" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200946.jpg" alt="Cover of the levitation controller. Here are some Super-LEDs integrated (optional)." width="893" height="1190" /> Cover of the levitation controller. Here are some Super-LEDs integrated (optional).[/caption]

[caption id="attachment_580" align="alignnone" width="893"]<img class="size-full wp-image-580" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_201039.jpg" alt="cof" width="893" height="1190" /> cof[/caption]

[caption id="attachment_582" align="alignnone" width="893"]<img class="size-full wp-image-582" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_202350.jpg" alt="cof" width="893" height="1190" /> cof[/caption]

[caption id="attachment_577" align="alignnone" width="893"]<img class="size-full wp-image-577" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200656.jpg" alt="cof" width="893" height="1190" /> cof[/caption]

[caption id="attachment_576" align="alignnone" width="1190"]<img class="size-full wp-image-576" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200627.jpg" alt="cof" width="1190" height="893" /> cof[/caption]

[caption id="attachment_575" align="alignnone" width="893"]<img class="size-full wp-image-575" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200615.jpg" alt="cof" width="893" height="1190" /> cof[/caption]

[caption id="attachment_574" align="alignnone" width="893"]<img class="size-full wp-image-574" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200514.jpg" alt="cof" width="893" height="1190" /> cof[/caption]

[caption id="attachment_573" align="alignnone" width="893"]<img class="size-full wp-image-573" src="http://johann.langhofer.net/wp-content/uploads/2018/04/IMG_20180418_200234.jpg" alt="cof" width="893" height="1190" /> cof[/caption]

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