Magnetic Levitation

by headslant in Circuits > Arduino

30584 Views, 142 Favorites, 0 Comments

Magnetic Levitation

P4050032.JPG
P4050038.JPG
Levitation MOVIE

Hello Instructables community!

A while back I published an Instructable for a wireless screen, as part of my GR.9 science fair. Right at the top I mentioned that when the project was done, that I would publish an Instructable on my project, which happened to be Levitation. Now before I get started, I would like to say that the code is a fork of Simon Monks code from www.dangerouslymad.com, and that the idea for a 3D Printed Frame is from Tinkernut /Gigafide(here on Instructables).

This device uses an Arduino, as well as an IR LED and IR Photoresistor and electromagnet to levitate the object. When the object rises, it breaks the beam of the IR Sensor system, and the electromagnet deactivates, or when the beam is not broken, and the object is falling, the electromagnet activates, lifting the object.

My best guess is that this project was the result of over 500 hours of work!

DISCLAIMER: I don't even know what could go wrong, but if anything happens, it's on you. As well I would like to say that i am not affiliated or sponsored by any links here.

The Parts and Tools

FRAME

· 3D printer Filament

· 2 M6 Bolts

· 1 M6 Nut

ELECTRONICS

· IRFZ44N N-Channel MOSFET

· 5W Electromagnet

· 200, 1K, 10K Ohm 1/4 watt resistors

· Arduino Nano

· Any toggle switch

· IR LED

· IR Photo Resistor (This isn't the one I got, but it is close)

· Diode

· Bi-Colour LED

MISCELLANEOUS

· Breadboard

· MM, MF Dupont Wires

· 22, 30 AWG wire

· Heatshrink

· USB mini cable

· 12 Volt wall adapter

· 35 MM Film Canister

· Non-Neodymium Magnets

· A Good Case

TOOLS

· Drill

· Spade Bits

· Soldering Iron/Solder

· 3D Printer (I used the Velleman K8200)

Overall the parts I bought for this project only, costed me about $20 CAD, but in total, all the parts cost about $45-55 CAD

The Software

720px-Arduino_Logo.svg.png

This Step is really simple. All you need to do is download Arduino IDE from here: www.arduino.cc. If you ordered your Arduino from Ebay(or it is a clone), then you will need the CH340G Driver: www.arduined.eu. Also if you have a clone, consider donating to the Arduino Project, or buy a genuine board to support the great work they do.

The Frame

Lev_Stand.png
P4050024.JPG

This is my first useful model, and I made this in TINKERCAD. Here is the TINKERCAD link: Levitation Stand.Make sure to sand the poles, so that they fit into the holes. In the large arc, you may need to drill out the holes, so that the poles can fit in. It should like like the attached photo.

The Electromagnet Driver

coildriver.jpg

The Arduino needs a way to control the electromagnet. The Atmega 328p specifies that on any GP I/O it can output 40 mA at 5 volts, or .2 watts, but the electromagnet needs 5 watts. To overcome this, I had to use a circuit that controls an external power supply. This MOSFET controller connects or disconnects the electromagnets ground wire from the actual power supply ground wire. Whether the two grounds are connected is determined by the gate, or control pin (Blue wire connects to it). If the Arduino applies voltage to that pin, the two grounds are connected, therefor turning on the electromagnet. If the Arduino doesn't apply voltage to that pin, the two grounds are disconnected, and the electromagnet is turned off.

The Infared Sensor and Reciever

571682f150e1b6cdaf000368.jpeg
P4050033.JPG
photoresistor voltage divider 10K.png
00420014.JPG

The Infrared Sensor and Receiver function together to complete one key task, which is to find the position of the object. One problem with a photoresistor is that they change their resistance based on IR light. The Arduino Itself cannot measure resistance, but with the help of a voltage divider, changes in resistance result in changes in voltage. The IR LED is just connected between Arduino Pin 8 and ground, with a 200 Ohm resistor thrown in series.

(Make sure to check if your IR sensor has a polarity, and consider that. It took me a whole night to figure that out!)

The Flyback Diode

571fb03e15be4df4d0000553.jpeg

Although you can’t see the actual diode that sits in the red heat shrink on the red and black wires, there is a good reason for this. When an inductor is disconnected, current wants to continue to flow. This results in a 1000 volts in the opposite direction. Without that diode, the Arduino would probably crack, smoke then burst into flames. So, you should try to avoid that by adding in a diode.

The Case

P4050035.JPG
P4050025.JPG
P4050036.JPG

The case is one I found in my basement, and it simply has a breadboard attached to the bottom with double sided tape. There are 6 Holes, one for the Arduino Nano USB cable, one for the switch, one for the potentiometer, one for the electromagnet driver wires, and one for all the other wires. I simply hot-glued the electromagnet driver to the back. The heat of that circuit isn't an issue, as the MOSFET can handle hundreds of watts(I'm currently working on a project where a MOSFET must switch ~300 watts), and my electromagnet is 5 watts. All the wires coming out of the box have to be hot glued to prevent them from being pulled out of the box.

Assembling the Electronics

Schematic of thing.jpg

This step is the hardest. I find the Fritzing Diagram a little hard to understand, so I added notes on each part. Let me know if something is unclear, and I will try to help you. Also make sure to connect the Arduino ground to the power rails; I forgot to add that.

The potentiometer has no real use, so skip that, and the three wires connected to it.

Physical Assembly: Electromagnet

Hole in LEV STAND.PNG
HOLE in Lev post.PNG
Wire hile in Lev Stand.PNG
P4050030.JPG
00430017.JPG

First, you need to solder and attach extension wires to the leads of the electromagnet. Use the thicker wire, and heatshrink. then feed those wires through the small hole in the inner side of the semi-circle, and out through the large hole. After, feed the wire through the hole shown in the second photo, and out through the hole shown in the 3rd picture. It should look like the last photo. Now Assemble the stand. Make sure that the holes are oriented as shown in the photo above. Attach the bolt through the top hole in the stand, and into the electromagnet.

Physical Assembly: IR LED

LevStand LED.jpg
P4050038.JPG
P4050037.JPG
lev post edit.png
571683b54936d4fd4f0013ca.jpeg

The anode of the IR LED goes to pin 8, with a 220 Ohm resistor in series. The cathode goes to ground. Refer to the fourth picture for the location of the LED and Wires. I had spiced the other end with a jumper wire, so that way i can plug the wires into a breadboard.

Physical Assembly: IR Sensor

photoresistor voltage divider 10K.png
P4050037.JPG

The IR sensor is a photoresistor connected in a voltage divider. Vcc, or 5 volts goes through a 10K Ohm resistor, and into the actual sensor, which then goes to ground. To measure the voltage, we read the values from in between the Sensor and the fixed resistor. This goes to arduino A1. It is physically placed in the identical configuration as the IR LED. I made a little adapter which one sensor lead pugs into my adapter, which connects it to 5 volts and A1(while including a resistor internally), Then the other sensor wire just goes to ground.

Physical Assembly: Flyback Diode

flybackdiodefritzing.jpg

The flyback diode in mine is coiled with all the extra wire for the electromagnet (I cut the wires for the electromagnet about 2 feet too long). It is wired in parallel with the electromagnet, except in the opposite direction. you want the line on the diode to connect to the side of the electromagnet with 12 volts, and the other side of the diode is connected to the other wire from the electromagnet. I covered this in loads of heatshrink, and it looks nice.

Extras on the Case

P4050035.JPG
P4050025.JPG
POTentiometer.jpg
IMG_7320.JPG
IMG_7317.JPG

On the case there is a potentiometer (Don't put one on. It's useless), and a SPDT toggle switch. I drilled out holes for them, and then used thier mounting hardware to attach them. The potentiometer acts like a variable voltage divider. There are three pins on it. The switch can be any type of toggle switch, I used a SPDT type. The middle pin goes to D2, and the one to the outer pins goes to GND.

The Levitating Objects

Colour OBJECT.PNG
GREEN OBJECT.PNG
RED OBJECT.PNG

The Levitating Objects are 35mm film canisters, with magnets. One magnet is placed on the lid, and 2 underneath the lid. They are filled with some oil to dampen vibrations. After, I decorated them with electrical tape. They weighted in at about 65-75 grams. If I were to remake them, I would have them all with identical weights, as that would work better. I did try large 1 inch (diameter) neodymium magnets, but they were so powerful they just flew up and stuck to the metal casing on the electromagnet because they are stronger than the electromagnet. You must ensure that all the magnets are put on correctly, and that the same pole on the magnets faces up. You can do this by pushing the top of each object together, and every object should repel every other object.

Testing

720px-Arduino_Logo.svg.png
P4050035.JPG
Schematic of thing.jpg

To setup the actual code, run the test code. If everything is connected right, The number beside the label PHOTORESISTOR:IR LED LOW should be at least 100 lower than the number with the label PHOTORESISTOR:IR LED HIGH. The label of SWITCH 1 should be either 1/0. (Change the position of the switch, and when it gives you more data in 7 seconds, check that the number changed). Next, get the film canisters, and check that the electromagnet is pulsing quickly every 5 seconds. Also check that when it pulses, the film canisters fly up toward to electromagnet, and are not repelled. If they are repelled, then either swap the polarity of the electromagnet, or switch the orientation of the permanent magnets on the film canister. If everything looks right, and is verified by this code, continue to the next step, if it isn't working, go back and check your wiring. I also found it useful to indicate which way the switch would yield 0 and 1.

The Levitation Code

720px-Arduino_Logo.svg.png

This will need some calibration, but to start, take the PHOTORESISTOR:IR LED LOW number from the test code, then round it to the nearest fifty, and change the value of MIN_MAP in the Arduino code to that number. Then upload the code to the Arduino.

Turning It On

720px-Arduino_Logo.svg.png

Make sure that the switch is in the position that yielded 1 in the test code. Then plug in the electromagnet power supply, and then the Arduino into the computer. Open the serial monitor at 115200 Baud, Your levitation device is now active.

Calibration

P4050031.JPG
P4050034.JPG
00450021.JPG

Calibration is very important!

Put your object under the electromagnet level with the IR Beam. Adjust the height of the electromagnet using the bolt on top until your object can levitate for a couple seconds. Load the code provided, and configure the variables.

Final Thoughts, Ideas and Code

If you ever need any help with this project, please feel free to P.M me, and I can provide my contact details so we can solve your problem.

Potential Improvements
• Model a hexagonal hole for the bolt head to sit in
• 3D Print a Case

Instructable user Jhardenberg, was able to modify this to use a Hall effect sensor, with a PID control loop. I will post some photos and code later.

Final Thoughts

Thank you for reading all 20 sections of my instructable! It was a lot of fun to make. I didn't win the science fair, but I won 4 plaques for engineering awards, a computing award and a math award. I really hope that the community will find this useful. I was inspired to post this because I saw the interest in this project, so i wanted to share my version.

Comment or share if you like it.

Downloads