It’s been only a couple weeks since I discovered Arduino, an open source microcontroller platform. I was looking for a cheap interface between my laptop and electronic circuits. Arduino with its price $35 and easy to use development environment was the best choice. So after getting my Arduino Duemilanove board and ordering some cheap components from AllElectronics, I had everything to start working on my old dream, making a magnet fly. Well, float.
Update: detailed description here
It took only a few days to figure out all the problems and my magnet floating device was born:

Floating a dart with Arduino
Here’s a video:
And another, shorter one:
A small cylindrical magnet can float as well:

A small magnet floating
As you can see by the blurred edges, the tiny magnet oscillates a bit. After a good calibration, the oscillations can be kept very small and the magnet can keep hovering for minutes. The big dart is much more stable and can float pretty much indefinitely. The device uses a small Hall effect sensor (SS19 from Honeywell, available for $0.50 from AllElectronics) to sense the field of the permanent magnet and uses that information to modulate the magnetic field of the electromagnet. Since the sensor is on the electromagnet,

Hall effect sensor on the electromagnet
the reading on it is the sum of the fields of the floating magnet as well as the electromagnet. The greatest challenge was separating these two and getting the floating magnet’s field only. After some theoretical research into inductors and the Amper’s law and experimentation, I achieved pretty good stability of a hovering magnet or a magnetic dart or whatever. The result is not completely perfect, some small oscillations are still noticeable. I think that I achieved the limitations given by the Arduino A/D converter. There is always some noise to be expected. I will post more details together with the source codes for both Arduino and my Mathematica 6 control center when I find just a little more time. I even created this blog because I wanted to share this beauty with the world
I also made some discoveries:
- It is really hard to buy a small, cheap electromagnet. I simply couldn’t find any. If you know how to buy one for say $4, let me know. I had to do a terrible thing, buy a solenoid from AllElectronics for $3.85 and tear it apart to get the coil from it. It works pretty well for me.
- The Arduino core library, Serial, for communication through the serial interface, is very slow because it is not optimized for the microcontroller it runs on, ATmega168. These are 8-bit RISC processors without an instruction for division, but the library uses 16-bit variables and division for no reason. The library also doesn’t offer an output buffer and thus the Serial.print methods lock the program waiting for one byte to be sent before they can send the next one. That can take precious time that is needed when a fast loop is being executed. Therefore I modified the wiring_serial.c file to optimize it for 8-bit RISC and added the output buffer (that can be completely disabled as well). See my other blog post for the file download.
The result looks pretty cool. Actually, it looks awesome. It is, however, only a device that keeps the magnet flying by pulling it up. My ultimate goal it the real “antigravity” device, a magnet flying above electromagnets. That is gonna take much more time but is hopefully feasible with this kind of simple circuitry, as was demonstrated by the maglev craddle or some neat levitating contraptions from SimerLab.
A couple more pics at the end. I will post a video too if I feel like it. But it seems that YouTube is full of crappy videos anyway.

Arduino floating device

Floating dart
Ciao!
very interesting project. I would build a similar device, but I don’t understand very well the feedback from the Hall sensor. Do you use it to modulate the electromagnet excitation?
Could you explain it with more details?
Thanks in advance.
bye-bye
Hey Stefano,
thanks =)
Yep, I totally wanna post more details very soon. And my code as well, after commenting it a bit and some cleanup. So come back in a couple days. It’s a very recent project (working only since last Friday).
A linear Hall sensor is the only sensor I have there. The stronger the magnetic field, the higher voltage on the sensor. The basic idea is essentially to decrease the field of the coil when the reading on the sensor is high, and increase it when it’s low. But since the field of the coil can be stronger than the field of the magnet, it messes up the reading and one has to subtract the coil’s field somehow. That’s not trivial as the coil acts like an inductor. So Arduino performs a simulation of the coil field. A low-pass filter, basically. More details to come…
oh.
please excuse me for my stupid urge. I didn’t see that this project was completed few days ago!
Thanks for the brief explanation and congratulation for the good work.
Ciao
Hey,
Great post!. Nice project you made. It is a change to see a well documented project with pictures ect makes a world of a difference.
very nice project. but why did you not do all the calculations inside the micro controller? the added serial communication seem to make it a bit complicated, the Arduino should be capable to do it alone. unless of course you wanted to try to do it like this
there is a german podcast (ex tv-show) they did the same with a smaller atmega controller. don’t know you can understand it, but the video alone is maybe interesting for you. (skip to 16:25)
http://de.sevenload.com/sendungen/Computerclub2/folgen/N7wXqna-Folge-20-Computer-club2
btw. i blogged about your project:
http://www.freeduino.de/de/blog/arduino-magnet-levitation
Hi Jan, thanks for blogging about my project in German. I already forgot most of it since high school. Thank you also for the link to the other cool project. I didn’t know about this before.
Another thing is that I don’t have any experience with electronics besides the little that I got 10 years ago at the beginning of high school when I assembled some simple digital circuits. Also, I’m completely new to microcontrollers. I had a general idea how to do the levitation but I didn’t find anything online about it besides some inspirational videos. So I had to experiment a lot. The ability to monitor everything on the computer turned out to be indispensable.
. I gave up, for instance, using a photodetector and a light to locate the object, as is often seen in other projects.
In my case, the microcontoller is performing all the calculations, you can disconnect it from the computer if you want. The computer interface is there only to set up the parameters, start or stop the levitation, and most important of all, to monitor the process. In the podcast, they have buttons and a big (and really cool) LCD panel to control it. I simply don’t have those resources, my laptop is the cheapest alternative
There is a small difference between the podcast’s project and mine. Their Hall effect sensor is under the levitating magnet, mine is on the coil, above the magnet. It’s a detail, but it turns out to be a critical one. They can directly use the reading to modulate the strength of the field. In my case, the reading is the sum of the magnet’s and coil’s fields. That was the greatest challenge to overcome and I simply didn’t see anything about it online. The advantage of my solution is that you have only the coil above the levitating object, nothing below it. So I can levitate a large dart or a small magnet or whatever, hovering in the air, with no sensors under or around it. That was my goal because I think it’s cooler. More magical
I’ll post more details in a few days once I have time, I promise. Thanks for the patience and support.
yes, i don’t have nice displays as well
just found some download to the podcast. maybe run it though google translate of necessary:
http://www.cczwei.de/atm18_downloads/DE2008070101.pdf
http://www.cczwei.de/atm18_downloads/MLC_SA_DIL_R2.zip
http://www.cczwei.de/atm18_downloads/ATM18_MLC_RC5.zip
they also talk about different kind of HAL sensor. some are better, others not so good.
anyway, really like the idea, will probably do it next.
I’m pretty sure that it makes a lot of difference. But once one has a sensor that is linear in the range of fields he uses, it is always possible to amplify the signal. Thanks for the docs, by the way. That’s a really nice explanation that they have there. I’m in the middle of writing my explanation of the software compensation. Hope I’ll post it soon.
[...] As you can see, it’s currently a magnetic pull instead of the familiar push levitation – but research continues. In order to get feedback/response to the sensor fast enough, he made some key changes to the Arduino IDE’s serial library. More info plus discussion in the comments of the relevant project’s blog entry. [...]
Very cool project. This is one of the more interesting things I’ve seen done with the Arduino.
You mention that your goal was to create a pushing rather than pulling maglev. You go on to say that it is more difficult than what you have achieved.
My question: What unique challenges do you face with the electromagnet on the bottom that you don’t when it’s in this configuration?
Thanks. To answer your question honestly, I don’t know. I haven’t tried doing this yet and I don’t have any experience, I do math. First indication that it might be harder is that I couldn’t find any home-made push up levitation except the magnetic cradle at http://amasci.com/maglev/maglev.html. If you know of some, send me a link. Also, the theoretical analysis shows that it will be harder. It’s like supporting a pendulum pointing up. You need 3 point at least, like a tripod. That will be harder with a magnet since the force depends on its orientation. So you have to also keep it from flipping or you lose some support points (when the magnet faces them with its side). However, one can borrow the idea from superconductors, tried to keep zero field on the electromagnets. That creates a repulsion and is easy to control. The main challenge is building it. Coding is easy.
Why did you have to do research? Isn’t this a solved problem? I’ve definitely seen other projects that do (something only similar to?) this. Or did you mean research to replicate the feat from first principles?
Of course it is solved. I wouldn’t start working on that if I didn’t know it’s possible. But I do math so I had to learn something new
I also do this for fun, so I tried to develop it myself. On the other hand, I don’t know about any other project using a single Hall effect sensor directly on the electromagnet and compensating for the coil’s field in software. That needed some researching, if I may call it that. If you do know about someone, send me a link. I want to learn how other people approach this. I’m not claiming that this technique is better than the other solutions. It’s most likely worse. But since I’m much better at coding than electronics, I chose this solution.
Fantastic – thanks for sharing.
Good luck with the development
Drew
[...] Como pueden ver, es una fuerza magnética en lugar de una fuerza levitacional familiar – pero la investigación continua. Para lograr una respuesta de retroalimentación del sensor los suficientemente rapida, el tiene algunos cambios claves en la librería serial IDE del Arduino. Más información y discusiones relevantes sobre el tema en la entrada del blog. [...]
Hi Norbert,
Very cool project. I would just like to add another request for a parts list, schematics, and code.
Thanks!
[...] great project uses the a soleniod’s magnetic coil, a Hall sensor, and Arduino to perfectly levitate a magnet. The Hall sensor detects the field of the permanent magnet and uses that information to [...]
nice, you made it on make magazine.
[...] great project uses the a soleniod’s magnetic coil, a Hall sensor, and Arduino to perfectly levitate a magnet. The Hall sensor detects the field of the permanent magnet and uses that information to modulate [...]
[...] Worth Reading? Every week I seem to be writing about how someone has used an Arduino to fashion an interesting gadget, and today’s – while not as obviously useful as, say a Pong-playing wristwatch - is still impressive. Using an Arduino, a Hall effect sensor and an electromagnet, the microprocessor board can keep a floating magnet perfectly positioned. [...]
[...] the reading on it is the sum of the fields of the floating magnet as well as the electromagnet. The greatest challenge was separating these two and getting the floating magnet’s field only. After some theoretical research into inductors and the Amper’s law and experimentation, I achieved pretty good stability of a hovering magnet or a magnetic dart or whatever. The result is not completely perfect, some small oscillations are still noticeable. I think that I achieved the limitations given by the Arduino A/D converter. As you can see, it’s currently a magnetic pull instead of the familiar push levitation – but research continues. In order to get feedback/response to the sensor fast enough, he made some key changes to the Arduino IDE’s serial library. More info plus discussion in the comments of the relevant project’s blog entry. [...]
[...] Every week I seem to be writing about how someone has used an Arduino to fashion an interesting gadget, and today’s – while not as obviously useful as, say a Pong-playing wristwatch - is still impressive. Using an Arduino, a Hall effect sensor and an electromagnet, the microprocessor board can keep a floating magnet perfectly positioned. [...]
[...] Every week I seem to be writing about how someone has used an Arduino to fashion an interesting gadget, and today’s – while not as obviously useful as, say a Pong-playing wristwatch - is still impressive. Using an Arduino, a Hall effect sensor and an electromagnet, the microprocessor board can keep a floating magnet perfectly positioned. [...]
AHOJ!!! Je to bezvadná věc! Sice vůbec nechápu, o co jde, ale je to určitě pokrokové a záslužné pro lidstvo
Gratuluji k úspěchu!! A mekonik je můj bratr, HEČ!!
Excellent, just gotta recomend this….
got my thumbs up….
[...] floating magnet blog [...]
Very interesting article, i have bookmarked your blog for future referrence. Best regards
really it is a very nice project, I want to ask you, I want to make a project that contains microconroller, what kind of microcontroller is better PIC or ATMEL ?!
Thanks. I don’t have much experience with MCUs so I’d say it depends on what you want to do =) In my case, I chose ATMEL because Arduino uses it, and an assembled Arduino board was the cheapest MCU board I found.
Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language
See you!
Your, Raiul Baztepo
Heh, cool project. Random books off the shelf in the video, right?
Pesumably you could make an electronic ‘wind chime’ by using several of these magnetic levitation devices and polling the current changes in the coils. I’ll leave the “devil in the details” to your imagination. I’m certain that there are much easier ways to create an electronic wind chime: but the concept of doing it this way caught my whimsy!! I liked your project.
Cheers
Noel
[...] This is a cool, dorky experiment that uses the Arduino to perform magnetic levitation. It was done by a Czech PhD student in L.A. See the documentation here. [...]
[...] This is a cool, dorky experiment that uses the Arduino to perform magnetic levitation. It was done by a Czech PhD student in L.A. See the documentation here. [...]