Levitating magnet and improved Serial library

Hi guus, I discovered Arduino only recently so my first project is rather simple but it was my dream when I was a kid. A levitating magnet. Well, this is only a simple magnet hovering under an electromagnet. Go to http://mekonik.wordpress.com/2009/03/02/my-first-arduino-project/ for a video, more pics and a short description. I guess I'll post more details later if there's an interest.

While working on this, I needed a high speed serial connection so I improved the Arduino serial library, wiring_serial.c, to allow for 1,000,000 baud speeds. It also makes the code shorter (a hundred bytes or two) and faster (~4x - 10x). I also added an outgoing buffer so Serial.print and println are buffered. That speeds up sending data substantially. To download the modified version, see http://mekonik.wordpress.com/2009/03/02/modified-arduino-library-serial/, the file is here http://www.math.ucla.edu/~npozar/arduino/wiring_serial.c. It is used exactly the same way as the original file.

I LOVE this! Last time I saw one of these was at the San Francisco Exploratorium when I was a kid.

Excellent, this sort of project used to be set as a final year degree project with the student expected to take an academic year over it. That was done with photo cell and light beam providing the positional feedback.

How did you isolate the electro magnet from the permanent magnet? Was it a case of only measuring the hall effect device when the magnet was turned off or is there an other trick to it?

A movie would be good as a still can look like you just caught it right.

Well done again.

That is very cool. Nice work!

@Grumpy_Mike: It took a couple days (two, I think) to find the right way how to separate the fields of the magnet and the coil. I'm essentially using Arduino to simulate the coil field to be able to subtract it, the coil behaves as an inductor. I'll post more details later this week.

I was experimenting with a photocell as well, but that doesn't really work well for objects of irregular shapes. Or I didn't find a way since I gave up really fast =) The hall sensor seems better suited for this.

A short video is at http://www.youtube.com/watch?v=LDcBqwRJCyg , enjoy. I have also more pics in the blog post mentioned above. I'll be posting more videos because I don't have a video with a magnet only, for instance. But the dart seemed cooler to me.

EDIT: Ok, here's a much better video with both a magnet and a magnetic dart: http://www.youtube.com/watch?v=QunBD_fD04k

Nice job for a first project.
Perhaps you could be interest by this : http://bea.st/sight/levitation/
To substract the field of the magnet the guy uses a second hall sensor on the other side of the coil.

Thanks for the link! His levitating bulb powered by a wireless energy transfer is really cool. I thought about using 2 hall sensors too, but that was not possible with my coil ripped out of an old push-type solenoid. It has the push nob there :)

Maybe I’m just a software geek at heart, but I’m more interested in knowing whether Arduino can adopt any improvements in the high-speed and buffered-output Serial library performance!

I know I'm being a bit evil suggesting this but it'd be awesome:

It's much easier to levitate a magnet from above it so... how about upping the challenge by flipping everything over! You'd need more than one electromagnet to stabilize things. Say, 4-8 coils arranged in a geometric pattern. This also has the bonus of allowing the system to intentionally move the magnet around. Imagine how impressed your family and friends will be seeing a magnet run a figure 8 in the air.

fantastic and original project :)

this is a great project and really well executed. I have a quick question about the work you have done with altering the serial speed. The project I am currently working on involves controlling individual LED's through MIDI over the USB interface on the Arduino board - the results are great but the LED's sometimes stick i.e. they stay on after the key has been depressed - this only happens when a lot of keys are pressed in succession and I think the problem must be with the serial speed. Would it be just a matter of downloading and installing your updated version or will I also have to make amendments to my Arduino script to recognise the new speeds available.

thank you for your time

No this problem is not related to the speed, it is your code not keeping track of the MIDI on / off commands, even professional sound devices sometimes end up with stuck on notes.


Great movie - you really get a feel for it.

I finally put together a detailed description together with full source code:


Thanks for all the feedback!