• Home
  • About
  • Mathematica notes

Mekonikuv blog

Feeds:
Posts
Comments
« Modified Arduino library, Serial
Magnetic levitation projects »

My first Arduino project

March 2, 2009 by mekonik

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

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

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

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

Arduino floating device

Floating dart

Floating dart

About these ads

Like this:

Like Loading...

Posted in Arduino | Tagged Arduino, electromagnet, Hall effect sensor, levitation, magnet | 53 Comments

53 Responses

  1. on March 2, 2009 at 11:58 pm Stefano

    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


  2. on March 3, 2009 at 12:14 am mekonik

    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…


  3. on March 3, 2009 at 4:31 am Stefano

    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


    • on March 3, 2009 at 10:49 am mekonik

      ;) don’t worry. That was exactly the point of this first short post, to see if people are interested.


  4. on March 3, 2009 at 11:27 am rookiecoder

    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. :)


  5. on March 3, 2009 at 10:08 pm jan

    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


    • on March 4, 2009 at 1:48 am mekonik

      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.
      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 :) 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.
      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 gave up, for instance, using a photodetector and a light to locate the object, as is often seen in other projects.

      I’ll post more details in a few days once I have time, I promise. Thanks for the patience and support.


  6. on March 4, 2009 at 10:43 pm jan

    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


  7. on March 5, 2009 at 2:53 am jan

    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.


    • on March 5, 2009 at 11:28 am mekonik

      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.


  8. on March 5, 2009 at 5:41 am Magnetic levitation with Arduino - machine quotidien

    [...] 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. [...]


  9. on March 5, 2009 at 6:49 am Doug

    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?


    • on March 5, 2009 at 11:15 am mekonik

      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.


  10. on March 5, 2009 at 9:10 am DU

    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?


    • on March 5, 2009 at 11:23 am mekonik

      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.


  11. on March 5, 2009 at 11:15 am Drew and Ryan

    Fantastic – thanks for sharing.
    Good luck with the development
    Drew


  12. on March 5, 2009 at 3:56 pm Levitación Magnética con Arduino « Make: en español

    [...] 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. [...]


  13. on March 5, 2009 at 5:09 pm Sam

    Hi Norbert,

    Very cool project. I would just like to add another request for a parts list, schematics, and code.

    Thanks!


  14. on March 5, 2009 at 7:24 pm Magnetic Levitation using the Arduino | Hack N Mod

    [...] 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 [...]


  15. on March 5, 2009 at 10:47 pm jan

    nice, you made it on make magazine.


  16. on March 6, 2009 at 3:18 am test | Hack N Mod

    [...] 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 [...]


  17. on March 6, 2009 at 3:31 am Arduino-controlled magnetic levitation - SlashGear

    [...] 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. [...]


  18. on March 6, 2009 at 7:00 am Magnetic levitation with Arduino | SquareCows

    [...] 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. [...]


  19. on March 6, 2009 at 9:02 am Arduino-controlled magnetic levitation | FocuSoft Tech Blog

    [...] 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. [...]


  20. on March 6, 2009 at 9:30 am Arduino-controlled magnetic levitation | ComputerFinance.net

    [...] 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. [...]


  21. on March 11, 2009 at 10:35 am Lucka

    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Č!!


  22. on March 19, 2009 at 10:05 am Excellent, just gotta recomend this.

    Excellent, just gotta recomend this….

    got my thumbs up….


  23. on March 19, 2009 at 3:19 pm floating magnet « wicked7578

    [...] floating magnet blog [...]


  24. on March 21, 2009 at 5:13 pm Simonn

    Very interesting article, i have bookmarked your blog for future referrence. Best regards


  25. on March 28, 2009 at 10:01 pm nitlogic

    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 ?!


    • on March 29, 2009 at 1:26 pm mekonik

      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.


  26. on March 28, 2009 at 10:22 pm RaiulBaztepo

    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


  27. on May 12, 2009 at 10:45 pm Matt

    Heh, cool project. Random books off the shelf in the video, right?


  28. on May 14, 2009 at 2:25 pm Noel

    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


  29. on August 28, 2009 at 3:42 pm Magnetic Levitation « STEADY Labs

    [...] 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. [...]


  30. on August 28, 2009 at 3:52 pm STEADY Labs — Blog — Magnetic Levitation

    [...] 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. [...]


  31. on November 14, 2009 at 6:32 pm Ale Fernandez

    Hi,

    Just to add my approval of your project and your continued hard work. What kind of maths is it you are doing?

    I think you should make it into some kind of gadget or toy, maybe by trying to fit the electronics into some kind of space station and make a spaceship or some similar theme, which could be exciting if you have a friend who works in production of things, like woodwork or plastics…

    Just a suggestion, but also I wonder if it is possible to rotate objects while suspended, as this would make a very good way to move things more subtly than as is done so much these days with loud and jerky servos.

    Ale


  32. on January 10, 2010 at 11:44 pm online stock trading advice

    Hey very nice blog!!….I’m an instant fan, I have bookmarked you and I’ll be checking back on a regular….See ya

    I’m Out! :)


  33. on February 7, 2010 at 5:26 am cheapest stock trading

    disappointed of the stocks in your bank? get the cheapest stock trading on line.


  34. on February 23, 2010 at 1:47 am DIY : Mettre des objets en lévitation avec un kit Arduino. | Semageek

    [...] pouvez retrouver ce projet en intégralité sur mekonik.wordpress.com avec toutes les formules ainsi que les schémas et codes sources associés, vraiment un beau [...]


  35. on March 7, 2010 at 12:54 am Timo

    Very nice project !
    This gace lots of tips and thinking for my future projects =)


  36. on April 30, 2010 at 5:23 am Arduino Control floating magnet

    [...] Norbert Požár slowing the arduino controlling magnet to floating and stabilizing on the air with hall-effect sensor (Linear Hall effect sensor Honeywell SS19) with Mathematica 6 interface all detail and his explanation including control algorithm, theory, and source code available on this link. Arduino, Control, Hall-Effect [...]


  37. on July 31, 2010 at 11:57 pm nanodano

    I just got my Arduino 2009 and I have been doing all kinds of experiments with it since. This project by far tops any that I’ve seen. This took some real engineering, and you are to be commended! This inspires me to push the limits of my new toy.


  38. on December 14, 2010 at 10:14 pm Metal Oxide Varistor

    Oh, every useful! Thanks very much for sharing this with us.


  39. on January 17, 2011 at 10:58 am Jonathan

    I see you haven’t updated in a while- but I have a couple ideas. First, could you add a second hall effect sensor to the other side of the coil where it presumably would give you the magnetic field of only the coil without the suspended object’s field. Then you could subtract this from the other signal. Perhaps this would give you more accurate feedback. Second- what about not using a hall effect sensor for feed back at all; instead, you could use a optical or sonic sensor to find the distance. Perhaps this would also allow you to add an interactive element where you could adjust the height of the suspended object on command.

    Anyway, fantastic job, I am very impressed.

    What is your normal field of expertise? You say that you don’t have electronics experience, but you did a great job here.


    • on February 22, 2011 at 11:32 am mekonik

      Hey Jonathan, sorry for the late reply. I’ve been busy with math (finishing ph.d.), that’s my field of expertise. Don’t know much about electronics. I haven’t had time to touch this project for 2 years.

      Thanks for the suggestions. Using an optical or a sonic sensor is quite standard. But I wanted something more compact, without anything else than the coil above the magnet. The second hall-effect sensor would help a lot, and in fact I linked to a project that uses that kind of setup. It appears to be much more stable than mine. But my goal was using as simple hardware as possible, and use software to do the processing. I wanted to learn how to do advanced signal processing on a microcontroller. That’s much closer to my field of expertise. Of course, if someone just wants to make a magnet levitate, she should use one of the setups you suggested.

      Norbert


  40. on February 21, 2011 at 5:09 am Arduino levitation - Hack a Day

    [...] magnet it is holding in midair. Check out the embedded video after the break and browse through the overview page so see how pleasing it is to do away with a frame around the floating object. This makes us wonder [...]


  41. on February 21, 2011 at 5:41 am Arduino levitation | Boomeroo Web Resources

    [...] magnet it is holding in midair. Check out the embedded video after the break and browse through the overview page so see how pleasing it is to do away with a frame around the floating object. This makes us wonder [...]


  42. on February 21, 2011 at 5:59 am Andrew McMeikan

    I have been considering doing this with a magnet stuck on top of a small container. I was wanting to measure very small weights by monitoring coil current. Would be interested to know if you have any insights into this type of application.


    • on February 22, 2011 at 11:19 am mekonik

      Hey Andrew,
      that’s an interesting idea. However, I don’t think you can get a good accuracy doing this. Also the range of weights one can put in is quite limited. And it’s not too stable. But please let me know if you make it work. Norbert


  43. on February 21, 2011 at 2:28 pm Arduino levitation | wo-foo.com

    [...] magnet it is holding in midair. Check out the embedded video after the break and browse through the overview page so see how pleasing it is to do away with a frame around the floating object. This makes us wonder [...]


  44. on April 16, 2011 at 10:06 am Del Jackson

    Really love this project. I am an artist and have been experimenting with helium to make some of my sculptures float. Do you think the arduino would be able to power an electromagnet that could lift a 3-5 lb paper object rigged with magnets inside?


  45. on May 17, 2011 at 9:52 pm Mike

    I might be being a noob here, but I just had a thought. For a simpler-er version of this project, could you ditch pretty much everything except the electromagnet and maybe have just a pot hooked up to the arduino which controls how fast the voltage pulses are to the EM? i.e that controls how strong the EM is or how long it’s left on. Off the top of my head it seems like you should manually be able to find a speed which levitates whatever object you want just by starting at max power then slowly dialing down the pot. maybe? Missing something glaringly obvious?



Comments are closed.

  • Archives

    • December 2009 (3)
    • March 2009 (5)
  • Categories

    • Arduino (4)
    • AVR (1)
    • Japanese (1)
    • Links (1)
    • Programming (3)
      • Mathematica (3)
  • Pages

    • About
    • Mathematica notes

Blog at WordPress.com.

Theme: MistyLook by WPThemes.


Follow

Get every new post delivered to your Inbox.

Powered by WordPress.com
%d bloggers like this: