Magnet Levitation with Arduino

Magnet levitation toy using Arduino. Cheap and easy to make!

Mar 11, 2018

176803 views

213 respects

Components and supplies

1

Power supply 12V 1A

1

Jumper wires (generic)

1

Resistor 1k ohm

1

Arduino Nano R3

1

Electromagnet 12v 25mm diameter.

2

Pushbutton switch 12mm

1

Linear Hall Effect Sensor 49E

1

Darlington High Power Transistor

1

Breadboard (generic)

1

1N4007 – High Voltage, High Current Rated Diode

Apps and platforms

1

Arduino IDE

Project description

Code

Levitator.ino

arduino

Code for Magnet Levitation toy with Arduino. Easy(No PID)

Levitator_PID.ino

arduino

Code for Magnet Levitation toy with Arduino. Hard(PID version)

Levitator.ino

arduino

Code for Magnet Levitation toy with Arduino. Easy(No PID)

Levitator_PID.ino

arduino

Code for Magnet Levitation toy with Arduino. Hard(PID version)

Downloadable files

Board Schematic

Fritzing IDE

Board Schematic

Comments

Only logged in users can leave comments

neouno

a year ago

Hi jsirgado! When using Linear hall-effect sensor AH3053 (NANJING), only small electromagnet and small permanent magnet could be realized. The reason is that the sensor becomes magnetically saturated at B>100mT. By using GaAs Hall-element HG-166A (ASAHI KASEI), the problem was solved without magnetic saturation even at B>100mT. Successful even with large electromagnet, large permanent magnet, and heavy payload. Please refer to the technical data. neo https://permanentmag123.blogspot.com/

crash891

2 years ago

This project need a overvoltage protection, cause i burned 2 arduinos using vin, cause the electomagnet generate an overvoltage if the magnet stick fast to it. nice work, good circuit (to make a burner)

crash891

2 years ago

This project need a overvoltage protection, cause i burned 2 arduinos using vin, cause the electomagnet generate an overvoltage if the magnet stick fast to it. nice work, good circuit (to make a burner)

mmdeluna

2 years ago

Hello, could you explain why do you need this line in the pid code: digVal += output; ? It looks like you are integrating the PID and I don't understand why it is not enough to use the output and do analogWrite(digPin, output). I've tried it both ways and it levitates much more stably with the line you use but I don't quite understand why.

asap3210

2 years ago

I, Good job. I did one as well: https://youtu.be/RqrPMbACC7s It took me a few months to calibrate the PID, I guess you know about it as well

kierbker238

2 years ago

Do you sell the completed project?

kierbker238

2 years ago

Do you sell the completed project?

sevens2345

2 years ago

I made the almost the same project as you but I cannot make the magnet to float. I used an 12V electromagnetic/solenoid, linear hall sensor, IRF520 MOSFET, diode and resistor same as you. I used an potentiometer instead of buttons. I used the 12V power supply of the arduino board and I connected the solenoid to Vin. I, also, used the 8x3 neodium magnet. Something is wrong but I don't know what. The magnet is only attracted by the solenoid and not floating. Any ideas?

Anonymous user

2 years ago

Hello. What is range of motion the magnet can move up and down? Thank you

Anonymous user

2 years ago

With my version I never really tested that, but I would say that maybe 10 mm. Certainly you will not get anything like 50+ mm.

Anonymous user

2 years ago

Hii..I am student of bechlor of technology (BTech) ..I am in 2nd yr ...and I want to make a project related with levitation. ..I want to make a prototype machine on levitation. ..plz plz help me on this ....I search everywhere but I can't find right things for it ...so plz help me and send me some details for making my project .......I will really appreciate your help ...plz reply

Anonymous user

2 years ago

It can't help ..I need detail information for construction of my project

Anonymous user

2 years ago

Or can you just provide me some images of real circuit connection of project ...plz

jsirgado

2 years ago

Hi Vaibhavr2107. I believe it is a relative easy task even for beginners. There is a lot of information(all you need) in this "Page" https://create.arduino.cc/projecthub/jsirgado/magnet-levitation-with-arduino-eeeee4 And lot of tips in the "Comments" of the page. The project was first published in the Thingiverse site, there is much more information and tips there, if you need: 1 - Body for 3D printer(Parts) https://www.thingiverse.com/thing:1392023 2 - Board (Electronics) http://www.thingiverse.com/thing:1392530 3 - Body Sample(Make) https://www.thingiverse.com/make:201394 4 - Electronics Sample(Make) https://www.thingiverse.com/make:201420 Kind regards Juan.

jsirgado

2 years ago

Hi people. I just see it now! Thank's all for the support. Now the PID version of the code is correct too. No "safe mode" yet sorry, I need test all again. Kind regards Juan.

Anonymous user

2 years ago

Just buy the parts from suggested sites, then replicate the given breadboard circuit? Make sure to position the hall sensor and electromagnet correctly - use the 3d printed stand. It's all laid out in front of you, all you have to do is order parts and assemble it.

Anonymous user

2 years ago

Also, I believe he meant the post starting with: "The Levitator_PID.ino source has the variable setpoint, which is never changed once initialized. It should be changed in the check for the up/down button..." (also the only main post that he made) That's assuming you have problems with software. If you actually have a problem with circuit connection you should probably practice on a simple circuit with breadboard first. I don't have a picture of the original circuit (breadboard) but have one of a slight modification that I tried out before. (sorry about the quality, only one I have on hand right now) Will send a protoboard picture (original circuit, should be more clear than ones I have on hand) later in day. https://imgur.com/ExOFNRK https://drive.google.com/open?id=1FkBThKEqvwgGF_6evo1_W2iNXQjoIxkY schematic pcb

Anonymous user

2 years ago

should be at the bottom of this page. I can see it.

Anonymous user

2 years ago

See my most recent post.

Anonymous user

2 years ago

Since I posted all the design files, parts, and source code, what more do you need?

Anonymous user

2 years ago

Where is your recent post ? Can you plz send me some detail to make a project type levitation machine

Anonymous user

2 years ago

Thnks eeknud but actually I did not find your post ..idk where it is 😅...I just read ur perious comment

Anonymous user

2 years ago

Thank you very much for such help ...

Anonymous user

2 years ago

thanks for sharing.. i connected everything as in schematic but how do you find the value. I read the comment to use serial monitor but mine just shows the value for the switches, hall doen not show anything and tried 4 new 49e hall sensors. i also used multimeter to test connection between hall pin and arduinoboard and its fine

Anonymous user

2 years ago

I've the same problem I don't know to do it too

Anonymous user

2 years ago

The Levitator_PID.ino source has the variable `setpoint`, which is never changed once initialized. It should be changed in the check for the up/down button. In addition, the up/down button should be debounced in code by waiting a few milliseconds and then checking to see if the button is still pressed. The PID parameters will have to be adjusted depending on the electromagnet used and the mass of the levitating magnet plus whatever its attached to.

jsirgado

2 years ago

Hi eeKnud. You are correct. 1 - Yes, the code is wrong, sorry! You need change the value of the variable "setpoint" and not of the variable "levVal" when the switches are pressed, the "levVal" is just the start point for "setpoint", I will try to correct it and add the safe-mode in the code and update all in the site as soon as possible. 2 - No, but you can change all. The program waits 250 milliseconds(1/4 of a second) every time the switches are pressed to make easy for beginners. 3 - Yes, you need find the correct values for "dt", "Kp", "Ki", "Kd" and "levVal" for your toy(hard to do...). Thanks! Kind regards Juan.

Anonymous user

2 years ago

Regarding point 2, waiting 250 ms after detecting an initial switch activation is not the same as de-bouncing the switch. After the initial check for the switch press, delay 5-10 ms, then check again that the switch is still pressed. Jack Ganssle provide a good page on this http://www.ganssle.com/debouncing.htm

esamali

2 years ago

Nice

Anonymous user

2 years ago

Thank you for sharing the project, I did everything as you said it but I baought a bigger electromagnet. Now I don't know what exactly the PID values mean and in my serial monitor I can only see some weird looking signs sometimes. Can you help me there?

Anonymous user

2 years ago

Hi jsirgado, I am having a problem with the levitating part. I duplicated your project Except that I am using 5V electromagnet, linear hall effect sensor module and SS8050 transistor. I found the new setpoint but I believe that Arduino or Electromagnet is reacting slowly to the change which breaks the balance. I am using the non-PID code for testing (PID also didn't work). From your experience, how do I make the reaction of the system faster?

jsirgado

2 years ago

Hi Sultan. I do not find the frequency of work for the SS8050, you need a fast transistor. You can try a big, have and strong magnet, heavy objects are more stable and the strong electromagnetic field will help with the stability. The PID version is very hard, you need find the correct value(levitation point) with the non-PID version and then with the correct value, tune the PID version. If you still have problems after all, please just send your email to me and I will send you a "new TEST version" of the non-PID code, that I believe is more stable and can avoid resonance. Kind regards Juan.

Anonymous user

2 years ago

Very nice, I built a similar project (http://johann.langhofer.net/electronics). My problem was stability, preventing the system from oszillation. Finally I came up with a simple slution (no PID controller). Thanks for sharing

jsirgado

2 years ago

Hi Javalang. I saw your project in the link and is great! Nice work! If I make a new one, I will include some upgrades like in your project: 1 - Curver arms for better view; 2 - Hall effect sensor in the bottom for more stable levitation; 3 - Big, really big eletromagnet, maybe without an iron core just copper; 4 - Include "safe mode" in the code, in case of permanent magnet drop. 5 - And I will test the aluminium/copper in the bottom as diamagnetic. Thank you very much!

Anonymous user

2 years ago

Wingardium Leviosa !!!

Anonymous user

2 years ago

Anyone interested can see my version based on jsirgado's at [Hackaday](https://hackaday.io/project/159566-discovere-magnetic-levitator)

jsirgado

2 years ago

Great work in the Hackaday! Thank you for sharing and for the support. The PID code is now correct. Kind regards Juan.

Anonymous user

2 years ago

https://hackaday.io/project/159566-discovere-magnetic-levitator is the full link in case people miss the embedded link above...

Anonymous user

2 years ago

I, Good job. I did one as well: https://youtu.be/RqrPMbACC7s It took me a few months to calibrate the PID, I guess you know about it as well

jsirgado

7 years ago

Great job, nice work. Big electromagnet and big gap! ;-) Thanks.

Anonymous user

2 years ago

Can I use a tip 122 instead of tip 120?

jsirgado

2 years ago

Hi Glitch. I saw the datasheet for both, tip120 and tip122 and I believe it will work fine. The difference is that the tip120 supports up to 60V in the pins 1-Base and 2-Collector and the tip122 up to 100V in the pins 1 and 2. All others parameters look be the same: https://www.onsemi.com/pub/Collateral/TIP120-D.PDF Same for the tip121, up to 80V(DC) in the pins 1 and 2. But attention: A safety voltage for "normal humans" is up to 48V(DC). 100V is a lot of voltage(DC) please be careful. Kind regards Juan.

jsirgado

2 years ago

Do not forget! The limite for all, TIP120, TIP121 and TIP122 are 65 WATTS. Regards Juan.

ekaggrat

2 years ago

is it possible to change the height of the suspending magnet in realtime? like you start on the top and then slowly move it towards the bottom and then pull up again? i cant find anyone doing it..

jsirgado

2 years ago

Hi ekaggrat! Yes, I saw a video of it in the youtube(differente toy). With this toy you can do it pressing the switches + and - or creating a new function in the arduino to control the permanent magnet position, but I believe the range is very small. To work better, I recommend a really strong electromagnet and maybe remove the iron core for a bigger range: (from the electromagnet to the ground) ;-). You can also try change the tension/current in the electromagnet and/or the frequency in the arduino. Be careful... Kind regards Juan.

Anonymous user

2 years ago

How can the magnet stabilise itself without using PID?

Anonymous user

2 years ago

the "simple code" is a P function (no I, no D): turn on or off the electromagnet proportionnaly to the distance. Well done @jsirgado! Thanks for sharing

Anonymous user

2 years ago

Could you explain how, like the process? For all of the project I have seen they use PID, so I am very curious how the magnet is able to stabilise with a simple code. Thank you :) Good job btw

jsirgado

2 years ago

Yes, for sure! There are 2 versions of the firmware for Arduino: 1 - Easy Levitation. Levitator.ino - Fixed value (Just change the value with the switches). 2 - Hard to do... Levitator_PID.ino - PID function (You need find the correct PID values for your toy, but you can adjust the seed with the switches). Sorry if it is not clear in the project. kind regards Juan.

jsirgado

2 years ago

Hi arvinwu168 and Mat13. The no PID version (fixed value), how it works: The eletronics just turn on the electromagnet when the permanent magnet is falling and then turn off before the permanent magnet rise too much(just tenths of a millimeter). Because the electromagnet is turned on and off a hundred times per second the permanent magnet stay in place. The linear hall effect sensor 49E is extreme precise and sensitive, for those who look it, is like the permanent magnet were standing. Kind regards Juan.

paulofreitasnobrega

2 years ago

Hello! I realized that the design of your fritzing project is more elegant than normal. Could you tell me if this is a specific version of fritzing or a package of parts?

paulofreitasnobrega

2 years ago

Thanks for the feedback. The image was very nice.

jsirgado

2 years ago

Hi Paulo Freitas Nobrega! Sorry, the original project was made in the Fritzing last version, no external packages, but the image above was edited using PaintBrush, just to make it more clean and simple for beginners. Abraços! ;-)

Anonymous user

2 years ago

Hello I've been looking for a long time, schematics for this project, but my intention is to do levitation in reverse, a levitron, Let the magnetic field form up, not down like this. You can help me in this, I do not know if I can adapt yours from this, to mine. Thank you

jsirgado

2 years ago

Hi Isolino! No, the materials I mentioned are for 4 electromagnets. I will make some blue prints and send to you. Please attention: I believe it will work. But I never did one. Kind regards Juan.

Anonymous user

2 years ago

Hello Thanks for the help you are giving me, I will communicate you all the steps of the project, and provide images of yourself, over time. For better communication, and if you want to send me your drawings, we'll email you if you can. isolinoliveira@hotmail.com Thank you very much

Anonymous user

2 years ago

Hello again For my project, I will use 4 reels, the materials you mentioned, I will need to increase the 4 times?

jsirgado

2 years ago

Hi Isolino. It is a differente project but is the same idea. Look at this toy in the youtube, I think it is what you wanna: https://www.youtube.com/watch?v=6klN93yWnd8 To build a similar toy "I BELIEVE", you need, 4 strong electromagnets, 4 transistors, 2 linear hall effect sensors, 4 diodes 4007N, 4 resistors 1K ohm, 4 switchs, and an arduino, the permanent magnets in the base for bigger gap are optional. 1 - Create 4 schemes for the electromagnets like the image above in my toy (ports D5, D6 and D10, D11). 2 - Create 2 schemes for the linear hall effect sensors (ports A1 and A2) and the switches (ports D4, D7 and D8, D12) like the image above in my toy. 3 - Mount the 4 eletromagnets aligned with the center, with a little gap 10mm between each other. 4 - Mount the 2 linear hall effect sensors with 10mm to 15mm out of the center, 1 to the left or rigth and the other to the front or back. It will allow read the X and Y position for the permanent magnet. 5 - Alter the code to read 2 linear hall effect sensors, control 4 electromagnets and alter the center values for X and Y with the 4 switches 2 for X value and 2 for Y value. 6 - Turn all ON, hold the permanent magnet in the correct position and hard code the linear hall effect sensors values in the arduino code. 7 - Use the switches for fine adjust. Obs: For this model all the electromagnets will be ON, just turn OFF the electromagnet opposite to the center value for X or Y. Try it and if you need more help, just let me know. Kind regards Juan.

Anonymous user

2 years ago

This project is amazing, and now i am struggling to look for something i can research on related to Quantum Physics, maybe you can help me with this, thank you. God bless.

jsirgado

2 years ago

I do not have projects with quantum physics yet... My tip is look in Youtube there is a lot of things there. I also sugest the "The Action Lab" channel in the Youtube. It is not extreme educational, but have good samples that you can do at home. Thanks!

jsirgado

2 years ago

Hi guys! I found an other levitator in the site and it have a PID function too. The code is more complex, but have a lot of comments and default values. The goal is the same: a TARGET(know value), kP, kI, kD and an INTERVAL. Maybe it can help everybody with trouble with my PID version. https://create.arduino.cc/projecthub/chanhj/magnetic-levitation-8c3ad0?ref=similar&ref_id=83650&offset=4 Kind regards Juan

Anonymous user

2 years ago

Hello, Will the PID code make the magnets levitate with more stability? I've tried the simple code, but it always seems to start shaking and stick to the electromagnet after a little while, maybe around 5-6 seconds. Is it a hardware problem (the electromagnet and hall sensor are positioned in the 3d printed stand), did I not adjust it enough (rough estimate of around 400 right now), or should I switch to the PID code?

jsirgado

2 years ago

I believe you can do it without using the PID version. I recomend first do it with "NO PID", then after try the PID version. Tips to avoid resonate: 1 - Try to put the hall effect sensor at 5mm or MORE from the electromagnet, remember it reads in both sides the electromagnet affects it, dismount all, clean the house for the sensor, bend the legs like the images, try again. 2 - Use big and strong permanent magnets, they are more stable because the weight and stronger magnetic field. 3 - Increase the value in 2 or 3 using the "switch +", I believe that the permanent magnet can be to close to the electromagnet. With my toy and the normal code(No PID), I do stable levitations with 2x 20mm x 5mm cylinder permanent magnets, or with 1x 10mm x 10mm cube permanent magnet with a 8mm screw atached to it, please see the videos. Kind regards Juan.

Anonymous user

2 years ago

Thank you for sharing this awesome project. I wanted to reduce the size and, more importantly, cost for this project. What would you suggest? Is it possible to use an ATtiny 85 microcontroller rather than an arduino and/or not use micro switches?

Anonymous user

2 years ago

I think you can reduce the cost for sure. If you go for a lower clock speed, it may be more challenging to get the PID loop working. If you mean the ATtiny 85, and not the 85V, you should be fine as long as you run it >= 10 MHz. If you want to keep the ability to change the gap between the magnets and avoid the switches, maybe a cheap potentiometer is the way to go. The largest cost is the electromagnet, so you can either try and find less expensive on ebay, Aliexpress, and others, or make your own. There is nothing special about the one I chose except that it arrived first in the mail. I am sure you can think of other areas to cost-reduce. In the end, it's always going to be a bit of a custom project.

Anonymous user

2 years ago

I wanted to create a code for this project in which I could put the magnet (which will float) directly underneath the hall sensor and the electromagnet would immediately turn on so the magnet would be touching the hall sensor (and not yet levitating). At this point the magnet would be 0mm away from the hall sensor. Then, after ~5 seconds, the distance between the hall sensor and magnet would slowly increase (by ~1mm every second until it reached an ideal, target distance (~20 mm)). This way, you could simply attach the magnet to the hall sensor easily and then it would levitate after so you wouldn't have to play with placing the magnet a specific distance away from the hall sensor initially. If this is possible, what should I change from the original Levitator.ino code?

jsirgado

2 years ago

Hi greenlight123. I believe you can do it. But you will need a strong electromagnet. The same code can do it, just create an interval "for {}" changing the value of "levval" from start point(top) to end point(bottom). For this vesion of the toy it is less than 2mm, too far the permanent magnet will fall, too close it will stick in the electromagnet. There are others options like: 1 - Remove the iron core from the electromagnet. 2 - Control(alternate) the polarity of the electromagnet. 3 - etc. But will be hard work. Kind regards Juan.

Anonymous user

2 years ago

How do I know which face is down or up for the hall effect sensor?

Anonymous user

2 years ago

The curved side of the hall effect should be faced down.

Anonymous user

2 years ago

Hello! Thank you so much for sharing this project. I have build the project but am having difficulties making the magnet levitate. I am using a similar electromagnet as the one you showed. However, it cannot levitate the permanent magnet. I believe that electromagnet has a steel casing and this affects the magnetic field near the edges of the electromagnet. Would you have any suggestions? I am considering making an electromagnet myself if it could fix the issue.

Anonymous user

2 years ago

Which hall sensor are you using? Actually after wasting 1 week I found out that the sensor I was using cannot work with the circuit always check that it's analogue sensor and not digital. Also there might be a possibility that the electromagnet is not generating enough magnetic field ( increase the current, I use 12V 3amp power supply) also make sure the connections are secure. Be sure to check these before moving on for other things like code, design or electromagnet. Good luck. Regards glitch

Anonymous user

2 years ago

I am using a linear 10 mA, I think the part name is A1302KUA-T from a German distributor. I tested the sensor with a simple code that would light up an LED when in the presence of a small magnetic field to test its orientation and it seemed to work perfectly there, and I also tested it with a DMM to check its output and it was working properly. I also think the electromagnet is not strong enough, as the 12V source generates a 2.3amp when the electromagnet is on, I will try to create an electromagnet with copper wiring and a ferromagnetic screw and test it if it creates a greater magnetic field that the electromagnet I have. Thanks!

Anonymous user

2 years ago

The electromagnet is oriented in the correct position, the problem seems to be that it is not creating an electric field strong enough to levitate the permanent magnet even with the 12V source. I tested it individually it seems to be really strong at distances less than 3cm from its core, but significantly weak at larger distances. I was thinking that the steal casing could be interfering with the electromagnetic lines at the edges of the electromagnet. I will check today that the PWM signal is correct with an oscilloscope, thanks!

Anonymous user

2 years ago

I assume you have the electromagnet oriented with the steel housing side facing up and the pole of the magnet facing down. The permanent magnet must be in the middle of the pole about 15 to 20 mm distant and under the Hall sensor. Since you already have the electromagnet, there is no point making another; it is not the problem provided it is being properly energized. The best way to check that is to confirm the PWM signal is correct and I used an oscilloscope. If you don't have that, then the next best way is to change the Arduino code so that the PWM value alternates between something like 128 and 0 with a delay of at least 125 ms between each value. Then bring a ferrous metal object near the magnet close enough you can the magnetic field "pulsing". That's one way to check the operation. Whenever I build a project, I add each capability one at a time and check each time it works. Trying to do everything with a "big bang" (build it all and turn it on expecting it to work) rarely is successful.

Anonymous user

2 years ago

Typo -- "magnet field" should be "magnetic field"

Anonymous user

2 years ago

You should not expect the field to be all that strong at any distance > 3 cm. If you look at jsirgado's video examples, the permanent magnet is about 20 mm from the electromagnet, which generates a magnet field, not an electric field. The force between two magnets is inversely proportional to the distance squared (~ 1/r^2), so the force really drops off with distance. The A1302KUA is comparable to the SS49E, though the datasheet for the A1302KUA shows a bypass capacitor is used, probably just to keep the readings less noisy. 2.3 A at 12V is a lot of power. My magnet draws less than 1 A and works just fine. I really, really doubt your electromagnet is the problem. Building a bigger, more powerful magnet will not help because you still have to get the PID set up correctly. I recommend hooking everything up as shown, then setting the electromagnet control signal (PWM) to 128 (50%) and running a loop where you read the Hall sensor and print the values to the console. Write down the Hall sensor value with only the electromagnet on, then bring the permanent magnet closer and closer paying attention to the sensor values and how they change. From that you will be able to see how the electromagnet current needs to be changed depending on the position of the permanent magnet. Use that to understand how the PID equation is used to control the PWM setting. As I have said before, tackle the project one step at a time; understand how each element works. You can't expect to just wire things up, add code, and turn it on and have it work.

jsirgado

2 years ago

Hi Jalfonsorobles! I believe the electromagnet is strong enough, the common distance is ~2cm, and 99% of the levitation is made by the permanent magnet, not by the eletromagnet. The electromagnet just avoid the fall. I see the data sheet for the hall effect sensor and looks good too. But please make sure you are using a linear hall effect sensor, not a hall effect switch, you can buy the 49E in the ebay, it cost just some cents, the kit with 10 is just $1.40: https://www.ebay.com/itm/10-pcs-49E-Hall-Element-OH49E-SS49E-Hall-Effect-Sensor-Linear-Switch/253056283580?hash=item3aeb5473bc%3Ag%3ApxMAAOSwvjlZcbiX&_sacat=0&_nkw=hall+efect+sensor+49e&_from=R40&rt=nc&_trksid=m570.l1313 Some tips are: Use big and strong permanent magnets. Keep a good distance between the hall effect sensor and the electromagnet (5mm or MORE). Good news: I am testing a new code to reduce(eliminate) the electromagnet interference in the hall effect sensor. Kind regards Juan.

Anonymous user

2 years ago

Hi, Thanks for sharing your project documents. I built the circuit exactly the same with yours but I could not make it work. I set up levitation value both while magnet was working and not. My neodyium magnets even either pulled by the magnet or pushed (the same pole). What could it be the problem. I am using Arduio UNO rev3. Thanks in advance.

Anonymous user

2 years ago

If you don't mind, I can give you my approach. I used the serial monitor to save the data (time, position of the magnet, sensor read) and then used MATHLAB to generate a polinomical regression. once you have that function, you can use as well the PID module of mathlab to approximate the PID values. I did this because one of the main issues for me was to have a value to start with. In order to get the data this is the setup I used: https://www.youtube.com/watch?v=8bscFQ9FbRo May the force be with you: https://www.youtube.com/watch?v=xiLQuDPk4FU

Anonymous user

2 years ago

Hi, in my opinion, it is very unlikely that the electromagnet is broken. One way to test it is with a multimeter, aproximate the magnet to the hall sensor and check the readings. if the setup is ok, it should be at full power (volts) and decrease as the magnet gets closer to the electromagnet. Most of the problems I had were with the mosfet, it is very sensitive to a wrong polarity (they get burned). So I would test the mosfet first. Regards, 

Anonymous user

2 years ago

Thanks for your quick response. There is 2 reason why it won't work. First, electromagnet is not working properly and second the darlington transistor does not drive the electromagnet. I don't know how to check electromagnet is working properly. My guess is electromagnet is broken. If I directly connect to the source, it is like making short circuit, isn't it? Thanks again for your help. Fabio

jsirgado

2 years ago

Hi fabio001. Some tips, it is not hard: 1 - Recheck if all is right and working, test the components 1 by 1. 2 - Put the hall effect sensor at 5mm or MORE from the electromagnet, remember it reads in both sides the electromagnet affects it. 3 - Use big and strong permanent magnets, they are more stable because the weight and stronger magnetic field. 4 - Use the North in the electromagnet facing the South in the permanent magnet. 5 - To find the levitation value, turn OFF the electromagnet and put the permanent magnet in the position near as possible of the electromagnet without it be attracted(pulled) by it, then read the hall effect sensor value using the Arduino IDE >> Tools >> Serial Monitor. Hardcode the value in the arduino(line 16: int levVal = 228; // Levitation Point Value;) the value for your toy in the place of the 228. 6 - Turn the toy ON, hold the permanent magnet in the position and use the switches for final adjust. If it not work, please read all the documentation and the comments for more tips and for more help see the "Documentation" and the "Makes" in the Thingiverse. Kind regards Juan.

Anonymous user

2 years ago

Hello! Thank you for sharing, im doing a school project and im hoping to build it after lockdown but for now im trying to build it on tinkercad. I have an error pop up when i try and start the code and it seems to have a problem with the value_log(), since im pretty new with arduinos i was wondering if someone could help me. Thanks!

Anonymous user

2 years ago

Hi I did this project, but it didn't work. I am using a BC547 and not a TIP120. Do you think this is the problem? or not? and I using a permanent magnet of HD, I bought neodymium magnet but not enough, can this be a problem?

jsirgado

2 years ago

I saw the datasheet and the BC547 looks good, please verify the voltage and amperage in the electromagnet must to be ~12V and ~0.3A with the hall effect sensor on. The magnets on HDs, are neodymium magnets, must be Ok.

Anonymous user

2 years ago

Hello! I'm a bit of an amateur so bare with me and my dumb questions. 1) What would I need to change if I use a 5V electromagnet instead of a 12V one? (of course, other than a 5V power supply) and would this make it capable of carrying less weight than a 12V one? 2) I know this is silly, but what is that black thing you screwed into your transistor on the Magnetic levitator shield for Arduino nano. https://www.thingiverse.com/make:201420 Thank you!

jsirgado

2 years ago

I'm not sure, but I believe it will work, probably with a small gap. I don´t recommend small permanent magnets, heavy objects are more stable. And you can use the 5V power supply in the arduino too. The "black thing" is an aluminium "U" cooler, a m3 nut and a "mainboard fix" to help in cooling it. You can and I recommend, stick a cooler on it. kind regards Juan.

Anonymous user

2 years ago

Thank you for sharing, it is so cool to see how relatively simple electronics can drive in real time physical things.

Anonymous user

2 years ago

Hi. Im new to this stuff and was wondering what values I would need to adjust for this project when everything is set up? When we pull up the arduino serial monitor, how can we adjust the values needed to fine-tune the levitation and what kinds of things would change those values?

Anonymous user

2 years ago

Additionally, would it be possible to use 2 hall effect sensors? One above the magnet and one below in order to help cancel out the effect of the solenoid magnetic field? Is this something that can be added to the existing code and set up?

jsirgado

2 years ago

The common distance is about ~2cm with big magnets (1 cm cubic at least). 99% of the levitation is made by the permanent magnet, not by the electromagnet. The electromagnet just avoid the fall. The tip is: 1 - Turn off the electromagnet. 2 - Hold the permanent magnet in the nearest position, without it be pulled-up. 3 - Write the number in the serial monitor and put in the code: int levVal = XXX; (Levtation start point). It is a good start. 4 - Adjust the value using the switchs.

jsirgado

2 years ago

Yes! You can add or just move the hall effect sensor for the bottom to reduce the interference or increase the precision, but you need change the code. I have a new code, where I always turn off the electromagnet before read the sensor. I just need time to test all and publish it.

Anonymous user

2 years ago

I built the project and was wondering what the 2 micro switches were being used for?

Anonymous user

2 years ago

You can change the position of at wich point the permanent magnet will be hold

Anonymous user

2 years ago

Hello. I want ask to you, can i use 20mm electromagnet 12v? What i should be change if i use it?

Anonymous user

2 years ago

Hi, I am trying to make this but in serial monitor the anval is coming about 5 to 10 and when I bring a particular pole of the magnet towards the electromagnet, there is a vibration felt in my hands, and when I slowly try to bring it close in order to levitate, it just sticks to the electromagnet, please help....

Anonymous user

2 years ago

Hi! Actually I now know what I doing wrong, I was using A3144 hall effect sensor which turned out to be a digital hall effect sensor so I have ordered a couple of 49e. I hope this was the only mistake and also I am using a custom built electromagnet (400 turn copper wire on 3inch iron bolt) I hope they work now(fingers crossed). Thanks for helping Regards Glitch

jsirgado

2 years ago

Hi Glitch. The vibration is Ok, is the hall sensor turnnig "On" and "Off" the electromagnet in the levitation point. But I believe the values 5 to 10 to anaVal are too small, my toy reads 200 to 270 in the levitation point with big permanent magnets. Try to use anoter 49E sensor(change it) or check the connections. Kind regards Juan.

Anonymous user

2 years ago

Actually I am getting it to lift the magnet but I am not able to adjust the position of the magnet using the push buttons the magnet just wobble and the falls down, any tips?

Anonymous user

2 years ago

Hello, please tell any alternative for the TIP 120, I am not able to levitate the magnet( as soon I bring it closer, it just goes up and sticks), I have BD139, MJE3055T, TIP35C in hand, can any of these work? Also I changed the sensor to 49E and I am using a iron cored electromagnet running at 12 volt 3 ampere all the connections are good and one more thing I am getting about 500-550 as the anaVal in the serial monitor(I did changed the Lev Val accordingly)... Is everything okay in the above mentioned set up...please reply as it a college project and I am running out of time... Hope you understand REGARDS Glitch

Anonymous user

2 years ago

Hola según el video prueba estas dos cosas: 1) Intenta aumentar el valor de la variable "levval" de tal forma que si lo sueltes suceda con mayor probabilidad la caída del imán mas que la subida del imán. La clave es encontrar el valor exacto de la variable "levval" que genera el equilibrio del objeto. 2) Intenta acoplar al iman un objeto muy liviano con base ancha para darle mayor estabilidad. Es muy probable que al añadir este peso se modifique el valor de la variable "levval" que tenias anteriormente. El valor de la variable "levval" es cercano a la condición de caída del objeto. En el video veo que si lo sueltas se pega(intenta aumentar el valor de "levval") Comentas lo resultados!! Atento para ayudar :)

Anonymous user

2 years ago

Hi, Yesterday I tried making it using all the different available transistors mentioned above, TIP35C didn't work( always kept the electromagnet on), Bd139 also didn't work but MJE3055T did worked but the oscillation are jittery the magnet resonates and then either fall or come up to the electromagnet. (See video: https://youtu.be/g1zMD5SZfy4 I got it levitate once in front of camera) Also I did read the data sheets but being in middle of amateur and beginner I wasn't able to see what's needed to check, nevertheless I did made it to work using only a P function(also I added some permanent magnets at the top of electromagnet to increase strength), if you see the above mentioned video do advise me and I will try getting my hands on a TIP120 and make you know how it works. Thanks . Regards Glitch

Anonymous user

2 years ago

Thanks, but I am currently using the non PID version can I use the above mentioned transistors in place of tip 120? Please help me and is the above setup for non PID version ok? Regards Glitch

Anonymous user

2 years ago

Hi! I was from starting using a heatsink with the transistors as I knew how hot can they be, but to my surprise none of them(Arduino nano and MJE) are getting hot even after using it for more than 5 mins. Though I have ordered some tip 120s(I'll notify you about that), also as you mentioned about the integral and derivative, (I and D) how to get their values, I mean whether there is a mathematical way to get the kp, ki and kd or just experimental and if experimental then how(please elaborate on this)? Thanks Regards Glitch

Anonymous user

2 years ago

Taking my own advice, the datasheet for the BD139 shows absolute max Ic of 1.5 A, so not suitable. The minimum current gain for the MJE3055T is not high enough to allow the Arduino to drive it; the most the Arduino might output is 40 mA. The maximum current gain might work, but never assume you can get maximums, only assume minimums. Even if you did get current gain of 100, any fluctuation or spike in the electromagnet current will likely burn out the transistor, maybe even hurt the arduino. The arduino will not like sourcing 30-40 mA for an extended period of time. Plus, you would have to definitely add a heat sink to the transistor. Not recommended. The TIP35C has an even lower current gain, so not usable at all. The TIP120 is the best transistor (Darlington) for the job, though at 3A you may want to have a heatsink. If you like electronic projects, please learn to read datasheets and understand how transistors work. If you have never learned about them, check out Kahn Academy for a simple intro. If you are trying to get a proportional-only version working, you need only to find the right Kp as described previously. Getting the system to be stable in that mode is really tricky and requires a lot of patience. As long as your setup matches jsirgado's including the separation between the hall sensor and the electromagnet, it should work. I've not tried, but if the hall sensor is reversed, the control equation sign may need to be reversed.

Anonymous user

2 years ago

If you already are using a good TIP120, there is no need to change. Otherwise any comparable NPN should work. Read the datasheets; preferably the replacement exceeds the TIP120 specs. It sounds like you have to tune the PID. Start with just the Kp term (comment out the other two) and adjust until the permanent magnet seems to want to float at about 2 cm distance. If you use Serial print statements to track the variable values, be aware that any serial output really slows down the sampling time, which means that adjustments are made too slowly. You can print values to get a feel for what they look like as you adjust Kp, but when you want to do a real test comment out/remove the print statements. Once you have Kp close, then uncomment Ki and start adjusting it, same as above. This approach worked well for me. In my case, for the electromagnet and permanent magnet I chose, I had to start with much higher values for the K's compared to jsirgado's example. I assume that if this is a college project, you're trying to demonstrate PID control in a control theory course. If so, you should be able to compare the theory with your measured results. The hardest part is measuring the force between the magnets, but it can be done. From s-plane analysis it's straightforward to find the K values. regards, sk

Anonymous user

2 years ago

Hi Glitch. You may be lucky with the MJE and it has enough gain (the min is 20, but max is 100). Does it get too warm to touch, or have you put on a heat sink? If it's too warm to touch, better put a heat sink on or you risk burning it out. The momentary levitation shown in the video is typical of a proportional-only closed loop response. There are two problems that are typical. There is usually an average offset between the desired "distance" between the two magnets and what is "measured" by the Hall sensor. This leads to the output of the control equation being always a little too strong or a little too weak. The integral term in the PID equation helps to smooth that out. The second effect is the oscillation that grows until the magnet falls up or down. That is due to the rate of change made to the control equation compared to the actual change experienced. See https://www.youtube.com/watch?v=UR0hOmjaHp0. So, you may find adding those terms back into the control equation will help stablize things. Try making Kp larger or smaller and observe the effect. One way may make it better, the other worse. At this point it all about tuning the K's. Changing to a TIP120 will not necessarily change anything. It's the digital control loop is what is doing all the work.

Anonymous user

2 years ago

Oh, I should have asked if the Arduino processor is getting warm, too. If it is, it is likely the MJE is trying to provide too much current, which causes the Arduino to source a lot of current, probably close to its limit. That's not good for it and sooner or later you'll burn it out. If it getting warm, this is the case and then you really should go to the TIP120. You can get them for very little from Digikey. In Canada they are $1.81 ea and you get next day delivery. I usually keep 25 or more on hand as they are useful. You can get them for less elsewhere, but have to wait longer and they may not be legit.

jsirgado

2 years ago

Hi Glitch. By the video you posted in the youtube I believe you already did. Just put a screw below in the permanent magnet. Remember, Heavy objects are more stable; You can use big and strong permanent magnets or more than one like in the project photo. To reduce the resonate, you can increase the distance between the electromagnet and the hall sensor too, just 1 or 2 millimeters are enough. Great work! Kind regards Juan.

Anonymous user

2 years ago

Can I use a MOSFET instead of the Darlington transistor, particularly the MJE3055T? Thanks

jsirgado

2 years ago

Hi Glitch. I am not sure, but looks fast enough. The best way to know is test it! Kind regards Juan.

Anonymous user

2 years ago

Why my tip122 is so hot? Please advise. Many thank, boss

Anonymous user

2 years ago

Hi my friend. Please help me. I followed your circuit bút I use Tip122 replace Tip120. I don't know Tip122 is very hot, I could not power on in 30 seconds. Please tell me the reason. Extremly thanks for your help

Anonymous user

2 years ago

Hi friends. I followed the circuit but I replaced Tip102 by tip122. However, this ones is very hot after few seconds. Please help me to resolve this proplem. Many thanks

Anonymous user

2 years ago

Hello! I hope you are well and still creating things! I am trying to recreate this project and I am having several issues. My email is roel.olvera@gmail.com . If you do not mind maybe having a zoom call with me to figure this out, that would be much appreciated. I understand your time is valuable. Best, Roel

Anonymous user

2 years ago

Funciona!!! Lo probé con la version on/off y funciona!! Muchas gracias por el post, una recomendación es colocar el imán permanente junto con un objeto de base ancha para mejorar la estabilidad y el peso. Yo pegue un iman circular de 2mm de altura a un vaso de plastico y funciona perfectamente. Acople mas vasos de plastico y mejoro mucho mas!

Anonymous user

2 years ago

Had a quick question, as I am using a 5V electromagnet and cut out the diode and power supply (My power source is my computer). I can't seem to get levitation even when going through a whole range of values with the buttons. I feel a singular small pulse when i pull the magnet in range of the hall sensor, and a single pulse when I pull it away. I am using a stack of 4 small neodymium magnets. My question is, do you think I need a stronger electromagnet? (It's noteable to mention before I soldered anything and with a different hall sensor of the same type (A1325) I would feel constant vibration when I brought the magnets in range)

jsirgado

2 years ago

Hi! 99% of the levitation is made by the permanent magnet. Not by the electromagnet, the electromagnet just avoid the fall. But if the electromagnet is too weak the permanent magnet will fall. (may be it is the problem)! The pulses are a good signal, all the electronics and the code are working... It means the sensor is reading the permanent magnet field and turnnig On/Off the electromagnet. I saw the datasheet for the (A1325) and looks good, 5V and it is fast. My tip is go for 12V in the electromagnet.

Anonymous user

2 years ago

Thanks so much for this. Is it okay if I use your code for my Access Course project? I will credit you for sure. I won't be making any money out of it I'm just trying to get to university XD.

jsirgado

2 years ago

Great news! Thank you.

Anonymous user

2 years ago

thanks for sharing

Anonymous user

2 years ago

Great Project - cant wait to get one on my desk in the office

Anonymous user

2 years ago

I, Good job. I did one as well: https://youtu.be/RqrPMbACC7s It took me a few months to calibrate the PID, I guess you know about it as well

jsirgado

2 years ago

Great job, nice work. Big electromagnet and big gap! ;-) Thanks.

Anonymous user

2 years ago

Hello, Many thanks for sharing your project which is awesome. Can you tell me why did you use a high power transistor? Could not arduino do it by it self. Thanks.

Anonymous user

2 years ago

Can you elaborate, how electromagnet's magnetic field did not effect such a sensitive sensor that is fairly close to the em.

jsirgado

2 years ago

Hi vefa. Sorry, I do not know if I really understood the question. The electromagnet needs 12V, the arduino accept up to 12V in the V (in) but works in 5V and 3.3V not 12V. (Erratum: Arduino up to 16V in the RAW input). We need the transistor to control the 12V in the Electromagnet. I used the TIP120 because it is cheap, fast enough, has a good range, is common and easy to find. You can use others transistors and others linear hall effect sensors with no problem. But with the TIP120, you can customize your toy using a strong electromagnet to a bigger gap, with the same electronics. Kind regards Juan.

jsirgado

2 years ago

Hi vefa. Good question! Yes the electromagnet affects the hall effect sensor a lot. But there is a trick here. When the electromagnet is ON the hall effect sensor always turns it OFF, but in the next loop, just after some milliseconds the arduino reads again, this time the correct value without the interference of the electromagnet and adjust the permanent magnet position. The true is that you need 2 cycles to control the permanent magnet, but uses just one. Tips: 1 - To find the correct value for the levitation in your toy you need turn OFF the electromagnet. 2 - If the hall effect sensor is too close to the electromagnet the interference will be too big and the toy will not work or the permanent magnet will resonate and fall. 3 - If you put the hall effect sensor below the electromagnet you will have a much better control over the levitation. Great work. Kind regards Juan.

Anonymous user

2 years ago

Thanks, I am going to make one for my grandson. Perhaps it will get him interested in electronics!

Anonymous user

2 years ago

I made it, but evidently I did something wrong, the hall effect sensor is face down, I've tried both programs but I can't get the magnets to levitate, they keep going all the way up to the electromagnet. I've changed the values in the program from one extreme to the other and it does not make any difference. What should I look at?

jsirgado

2 years ago

Hi paulbrandt2. Ok! 4 tips. 1 - Recheck if all is right and working, test the components 1 by 1. 2 - Put the hall effect sensor at 5mm or MORE from the electromagnet, remember it reads in both sides. 3 - Use big and strong permanent magnets, they are more stable because the weight and stronger magnetic field. 4 - Turn off the electromagnet and put the permanent magnet in the position near as possible of the electromagnet without it be attracted(pulled) by it, then read the hall effect sensor value using the Arduino IDE >> Tools >> Serial Monitor and hardcode the value in the arduino(line 16: int levVal = 228; // Levitation Point Value;) the value for your toy in the place of the 228. Use the switchs for final adjust. Please, let me know the progress. If it not work, I can help more! It is not easy, but I believe it is not so hard. Kind regards Juan.

Anonymous user

2 years ago

My analog read on serial monitor read 510-512 with off electromagnet is that right? I build the circuit exactly the same with yours.

jsirgado

2 years ago

Hi Polwan. I believe it is correct. It is never the same, each toy have one difrerente value, because it depends of the hall effect sensor sensitivity and position and the permanent magnet size, weight and power. Kind regards Juan.

Anonymous user

2 years ago

Can i see serial monitor in your arduino ide when the magnet is levitate thats my email orangjahat172@gmail.com. Thanks

jsirgado

2 years ago

Hi Polwan. I sent the email with the Arduino IDE - Log. No video yet. Kind regards Juan.

jsirgado

2 years ago

Hi Polwan. This week I will try to do a video and post it in the Youtube. Find the right value and position are the hard work here. But is relativity easy to adjust the permanent magnet position after you understand the process. And I will send to you some examples of my serial-monitor log when the permanent magnet it is levitating. Please be patient. Kind regards Juan.

Anonymous user

2 years ago

Can you please explain the purpose of those micro switches in the circuit?

Anonymous user

2 years ago

i beleive it is to raise/lower the magnets but im not 100% sure.

toby356

2 years ago

Wildflowers provide seeds, nectar, pollen, and leaves as a source of food and life, especially for pollinators that have small home ranges or that depend on one or two specific host plant species, such as the Mission blue butterfly.

Anonymous user

3 years ago

Thank you for sharing the project, I did everything as you said it but I baought a bigger electromagnet. Now I don't know what exactly the PID values mean and in my serial monitor I can only see some weird looking signs sometimes. Can you help me there?

Anonymous user

4 years ago

I built the project and was wondering what the 2 micro switches were being used for?

Anonymous user

2 years ago

You can change the position of at wich point the permanent magnet will be hold

puggo

4 years ago

How do I know which face is down or up for the hall effect sensor?

Anonymous user

2 years ago

The curved side of the hall effect should be faced down.

Anonymous user

4 years ago

Hello! I hope you are well and still creating things! I am trying to recreate this project and I am having several issues. My email is roel.olvera@gmail.com . If you do not mind maybe having a zoom call with me to figure this out, that would be much appreciated. I understand your time is valuable. Best, Roel

Anonymous user

4 years ago

Why my tip122 is so hot? Please advise. Many thank, boss

Anonymous user

4 years ago

Hi friends. I followed the circuit but I replaced Tip102 by tip122. However, this ones is very hot after few seconds. Please help me to resolve this proplem. Many thanks

Anonymous user

4 years ago

Hi my friend. Please help me. I followed your circuit bút I use Tip122 replace Tip120. I don't know Tip122 is very hot, I could not power on in 30 seconds. Please tell me the reason. Extremly thanks for your help

beckhamh

5 years ago

Hello! Thank you for sharing, im doing a school project and im hoping to build it after lockdown but for now im trying to build it on tinkercad. I have an error pop up when i try and start the code and it seems to have a problem with the value_log(), since im pretty new with arduinos i was wondering if someone could help me. Thanks!

Anonymous user

5 years ago

Can you please explain the purpose of those micro switches in the circuit?

beckhamh

2 years ago

i beleive it is to raise/lower the magnets but im not 100% sure.

Anonymous user

5 years ago

thanks for sharing.. i connected everything as in schematic but how do you find the value. I read the comment to use serial monitor but mine just shows the value for the switches, hall doen not show anything and tried 4 new 49e hall sensors. i also used multimeter to test connection between hall pin and arduinoboard and its fine

Anonymous user

2 years ago

I've the same problem I don't know to do it too

Anonymous user

5 years ago

Hello. I want ask to you, can i use 20mm electromagnet 12v? What i should be change if i use it?

Anonymous user

5 years ago

Great Project - cant wait to get one on my desk in the office

Anonymous user

5 years ago

Hi I did this project, but it didn't work. I am using a BC547 and not a TIP120. Do you think this is the problem? or not? and I using a permanent magnet of HD, I bought neodymium magnet but not enough, can this be a problem?

jsirgado

2 years ago

I saw the datasheet and the BC547 looks good, please verify the voltage and amperage in the electromagnet must to be ~12V and ~0.3A with the hall effect sensor on. The magnets on HDs, are neodymium magnets, must be Ok.

anizzawang

5 years ago

This project is amazing, and now i am struggling to look for something i can research on related to Quantum Physics, maybe you can help me with this, thank you. God bless.

jsirgado

2 years ago

I do not have projects with quantum physics yet... My tip is look in Youtube there is a lot of things there. I also sugest the "The Action Lab" channel in the Youtube. It is not extreme educational, but have good samples that you can do at home. Thanks!

Anonymous user

6 years ago

Hi. Im new to this stuff and was wondering what values I would need to adjust for this project when everything is set up? When we pull up the arduino serial monitor, how can we adjust the values needed to fine-tune the levitation and what kinds of things would change those values?

jsirgado

2 years ago

Yes! You can add or just move the hall effect sensor for the bottom to reduce the interference or increase the precision, but you need change the code. I have a new code, where I always turn off the electromagnet before read the sensor. I just need time to test all and publish it.

jsirgado

2 years ago

The common distance is about ~2cm with big magnets (1 cm cubic at least). 99% of the levitation is made by the permanent magnet, not by the electromagnet. The electromagnet just avoid the fall. The tip is: 1 - Turn off the electromagnet. 2 - Hold the permanent magnet in the nearest position, without it be pulled-up. 3 - Write the number in the serial monitor and put in the code: int levVal = XXX; (Levtation start point). It is a good start. 4 - Adjust the value using the switchs.

Anonymous user

2 years ago

Additionally, would it be possible to use 2 hall effect sensors? One above the magnet and one below in order to help cancel out the effect of the solenoid magnetic field? Is this something that can be added to the existing code and set up?

AvisCantrix

6 years ago

Thanks so much for this. Is it okay if I use your code for my Access Course project? I will credit you for sure. I won't be making any money out of it I'm just trying to get to university XD.

jsirgado

2 years ago

Great news! Thank you.

Anonymous user

6 years ago

Had a quick question, as I am using a 5V electromagnet and cut out the diode and power supply (My power source is my computer). I can't seem to get levitation even when going through a whole range of values with the buttons. I feel a singular small pulse when i pull the magnet in range of the hall sensor, and a single pulse when I pull it away. I am using a stack of 4 small neodymium magnets. My question is, do you think I need a stronger electromagnet? (It's noteable to mention before I soldered anything and with a different hall sensor of the same type (A1325) I would feel constant vibration when I brought the magnets in range)

jsirgado

2 years ago

Hi! 99% of the levitation is made by the permanent magnet. Not by the electromagnet, the electromagnet just avoid the fall. But if the electromagnet is too weak the permanent magnet will fall. (may be it is the problem)! The pulses are a good signal, all the electronics and the code are working... It means the sensor is reading the permanent magnet field and turnnig On/Off the electromagnet. I saw the datasheet for the (A1325) and looks good, 5V and it is fast. My tip is go for 12V in the electromagnet.

Anonymous user

6 years ago

Hi jsirgado, I am having a problem with the levitating part. I duplicated your project Except that I am using 5V electromagnet, linear hall effect sensor module and SS8050 transistor. I found the new setpoint but I believe that Arduino or Electromagnet is reacting slowly to the change which breaks the balance. I am using the non-PID code for testing (PID also didn't work). From your experience, how do I make the reaction of the system faster?

jsirgado

2 years ago

Hi Sultan. I do not find the frequency of work for the SS8050, you need a fast transistor. You can try a big, have and strong magnet, heavy objects are more stable and the strong electromagnetic field will help with the stability. The PID version is very hard, you need find the correct value(levitation point) with the non-PID version and then with the correct value, tune the PID version. If you still have problems after all, please just send your email to me and I will send you a "new TEST version" of the non-PID code, that I believe is more stable and can avoid resonance. Kind regards Juan.

Anonymous user

6 years ago

Hello! I'm a bit of an amateur so bare with me and my dumb questions. 1) What would I need to change if I use a 5V electromagnet instead of a 12V one? (of course, other than a 5V power supply) and would this make it capable of carrying less weight than a 12V one? 2) I know this is silly, but what is that black thing you screwed into your transistor on the Magnetic levitator shield for Arduino nano. https://www.thingiverse.com/make:201420 Thank you!

jsirgado

2 years ago

I'm not sure, but I believe it will work, probably with a small gap. I don´t recommend small permanent magnets, heavy objects are more stable. And you can use the 5V power supply in the arduino too. The "black thing" is an aluminium "U" cooler, a m3 nut and a "mainboard fix" to help in cooling it. You can and I recommend, stick a cooler on it. kind regards Juan.

Anonymous user

6 years ago

I wanted to create a code for this project in which I could put the magnet (which will float) directly underneath the hall sensor and the electromagnet would immediately turn on so the magnet would be touching the hall sensor (and not yet levitating). At this point the magnet would be 0mm away from the hall sensor. Then, after ~5 seconds, the distance between the hall sensor and magnet would slowly increase (by ~1mm every second until it reached an ideal, target distance (~20 mm)). This way, you could simply attach the magnet to the hall sensor easily and then it would levitate after so you wouldn't have to play with placing the magnet a specific distance away from the hall sensor initially. If this is possible, what should I change from the original Levitator.ino code?

jsirgado

2 years ago

Hi greenlight123. I believe you can do it. But you will need a strong electromagnet. The same code can do it, just create an interval "for {}" changing the value of "levval" from start point(top) to end point(bottom). For this vesion of the toy it is less than 2mm, too far the permanent magnet will fall, too close it will stick in the electromagnet. There are others options like: 1 - Remove the iron core from the electromagnet. 2 - Control(alternate) the polarity of the electromagnet. 3 - etc. But will be hard work. Kind regards Juan.

Anonymous user

6 years ago

Thank you for sharing this awesome project. I wanted to reduce the size and, more importantly, cost for this project. What would you suggest? Is it possible to use an ATtiny 85 microcontroller rather than an arduino and/or not use micro switches?

Anonymous user

2 years ago

I think you can reduce the cost for sure. If you go for a lower clock speed, it may be more challenging to get the PID loop working. If you mean the ATtiny 85, and not the 85V, you should be fine as long as you run it >= 10 MHz. If you want to keep the ability to change the gap between the magnets and avoid the switches, maybe a cheap potentiometer is the way to go. The largest cost is the electromagnet, so you can either try and find less expensive on ebay, Aliexpress, and others, or make your own. There is nothing special about the one I chose except that it arrived first in the mail. I am sure you can think of other areas to cost-reduce. In the end, it's always going to be a bit of a custom project.

Anonymous user

6 years ago

Hello. What is range of motion the magnet can move up and down? Thank you

Anonymous user

2 years ago

With my version I never really tested that, but I would say that maybe 10 mm. Certainly you will not get anything like 50+ mm.

jsirgado

6 years ago

Hi guys! I found an other levitator in the site and it have a PID function too. The code is more complex, but have a lot of comments and default values. The goal is the same: a TARGET(know value), kP, kI, kD and an INTERVAL. Maybe it can help everybody with trouble with my PID version. https://create.arduino.cc/projecthub/chanhj/magnetic-levitation-8c3ad0?ref=similar&ref_id=83650&offset=4 Kind regards Juan

Anonymous user

6 years ago

Can I use a tip 122 instead of tip 120?

jsirgado

2 years ago

Hi Glitch. I saw the datasheet for both, tip120 and tip122 and I believe it will work fine. The difference is that the tip120 supports up to 60V in the pins 1-Base and 2-Collector and the tip122 up to 100V in the pins 1 and 2. All others parameters look be the same: https://www.onsemi.com/pub/Collateral/TIP120-D.PDF Same for the tip121, up to 80V(DC) in the pins 1 and 2. But attention: A safety voltage for "normal humans" is up to 48V(DC). 100V is a lot of voltage(DC) please be careful. Kind regards Juan.

jsirgado

2 years ago

Do not forget! The limite for all, TIP120, TIP121 and TIP122 are 65 WATTS. Regards Juan.

Anonymous user

6 years ago

Hello, please tell any alternative for the TIP 120, I am not able to levitate the magnet( as soon I bring it closer, it just goes up and sticks), I have BD139, MJE3055T, TIP35C in hand, can any of these work? Also I changed the sensor to 49E and I am using a iron cored electromagnet running at 12 volt 3 ampere all the connections are good and one more thing I am getting about 500-550 as the anaVal in the serial monitor(I did changed the Lev Val accordingly)... Is everything okay in the above mentioned set up...please reply as it a college project and I am running out of time... Hope you understand REGARDS Glitch

jsirgado

2 years ago

Hi Glitch. By the video you posted in the youtube I believe you already did. Just put a screw below in the permanent magnet. Remember, Heavy objects are more stable; You can use big and strong permanent magnets or more than one like in the project photo. To reduce the resonate, you can increase the distance between the electromagnet and the hall sensor too, just 1 or 2 millimeters are enough. Great work! Kind regards Juan.

Anonymous user

2 years ago

Hola según el video prueba estas dos cosas: 1) Intenta aumentar el valor de la variable "levval" de tal forma que si lo sueltes suceda con mayor probabilidad la caída del imán mas que la subida del imán. La clave es encontrar el valor exacto de la variable "levval" que genera el equilibrio del objeto. 2) Intenta acoplar al iman un objeto muy liviano con base ancha para darle mayor estabilidad. Es muy probable que al añadir este peso se modifique el valor de la variable "levval" que tenias anteriormente. El valor de la variable "levval" es cercano a la condición de caída del objeto. En el video veo que si lo sueltas se pega(intenta aumentar el valor de "levval") Comentas lo resultados!! Atento para ayudar :)

Anonymous user

2 years ago

Hi, Yesterday I tried making it using all the different available transistors mentioned above, TIP35C didn't work( always kept the electromagnet on), Bd139 also didn't work but MJE3055T did worked but the oscillation are jittery the magnet resonates and then either fall or come up to the electromagnet. (See video: https://youtu.be/g1zMD5SZfy4 I got it levitate once in front of camera) Also I did read the data sheets but being in middle of amateur and beginner I wasn't able to see what's needed to check, nevertheless I did made it to work using only a P function(also I added some permanent magnets at the top of electromagnet to increase strength), if you see the above mentioned video do advise me and I will try getting my hands on a TIP120 and make you know how it works. Thanks . Regards Glitch

Anonymous user

2 years ago

Thanks, but I am currently using the non PID version can I use the above mentioned transistors in place of tip 120? Please help me and is the above setup for non PID version ok? Regards Glitch

Anonymous user

2 years ago

Hi! I was from starting using a heatsink with the transistors as I knew how hot can they be, but to my surprise none of them(Arduino nano and MJE) are getting hot even after using it for more than 5 mins. Though I have ordered some tip 120s(I'll notify you about that), also as you mentioned about the integral and derivative, (I and D) how to get their values, I mean whether there is a mathematical way to get the kp, ki and kd or just experimental and if experimental then how(please elaborate on this)? Thanks Regards Glitch

Anonymous user

2 years ago

Hi Glitch. You may be lucky with the MJE and it has enough gain (the min is 20, but max is 100). Does it get too warm to touch, or have you put on a heat sink? If it's too warm to touch, better put a heat sink on or you risk burning it out. The momentary levitation shown in the video is typical of a proportional-only closed loop response. There are two problems that are typical. There is usually an average offset between the desired "distance" between the two magnets and what is "measured" by the Hall sensor. This leads to the output of the control equation being always a little too strong or a little too weak. The integral term in the PID equation helps to smooth that out. The second effect is the oscillation that grows until the magnet falls up or down. That is due to the rate of change made to the control equation compared to the actual change experienced. See https://www.youtube.com/watch?v=UR0hOmjaHp0. So, you may find adding those terms back into the control equation will help stablize things. Try making Kp larger or smaller and observe the effect. One way may make it better, the other worse. At this point it all about tuning the K's. Changing to a TIP120 will not necessarily change anything. It's the digital control loop is what is doing all the work.

Anonymous user

2 years ago

Oh, I should have asked if the Arduino processor is getting warm, too. If it is, it is likely the MJE is trying to provide too much current, which causes the Arduino to source a lot of current, probably close to its limit. That's not good for it and sooner or later you'll burn it out. If it getting warm, this is the case and then you really should go to the TIP120. You can get them for very little from Digikey. In Canada they are $1.81 ea and you get next day delivery. I usually keep 25 or more on hand as they are useful. You can get them for less elsewhere, but have to wait longer and they may not be legit.

Anonymous user

2 years ago

Taking my own advice, the datasheet for the BD139 shows absolute max Ic of 1.5 A, so not suitable. The minimum current gain for the MJE3055T is not high enough to allow the Arduino to drive it; the most the Arduino might output is 40 mA. The maximum current gain might work, but never assume you can get maximums, only assume minimums. Even if you did get current gain of 100, any fluctuation or spike in the electromagnet current will likely burn out the transistor, maybe even hurt the arduino. The arduino will not like sourcing 30-40 mA for an extended period of time. Plus, you would have to definitely add a heat sink to the transistor. Not recommended. The TIP35C has an even lower current gain, so not usable at all. The TIP120 is the best transistor (Darlington) for the job, though at 3A you may want to have a heatsink. If you like electronic projects, please learn to read datasheets and understand how transistors work. If you have never learned about them, check out Kahn Academy for a simple intro. If you are trying to get a proportional-only version working, you need only to find the right Kp as described previously. Getting the system to be stable in that mode is really tricky and requires a lot of patience. As long as your setup matches jsirgado's including the separation between the hall sensor and the electromagnet, it should work. I've not tried, but if the hall sensor is reversed, the control equation sign may need to be reversed.

Anonymous user

2 years ago

If you already are using a good TIP120, there is no need to change. Otherwise any comparable NPN should work. Read the datasheets; preferably the replacement exceeds the TIP120 specs. It sounds like you have to tune the PID. Start with just the Kp term (comment out the other two) and adjust until the permanent magnet seems to want to float at about 2 cm distance. If you use Serial print statements to track the variable values, be aware that any serial output really slows down the sampling time, which means that adjustments are made too slowly. You can print values to get a feel for what they look like as you adjust Kp, but when you want to do a real test comment out/remove the print statements. Once you have Kp close, then uncomment Ki and start adjusting it, same as above. This approach worked well for me. In my case, for the electromagnet and permanent magnet I chose, I had to start with much higher values for the K's compared to jsirgado's example. I assume that if this is a college project, you're trying to demonstrate PID control in a control theory course. If so, you should be able to compare the theory with your measured results. The hardest part is measuring the force between the magnets, but it can be done. From s-plane analysis it's straightforward to find the K values. regards, sk

Anonymous user

6 years ago

Funciona!!! Lo probé con la version on/off y funciona!! Muchas gracias por el post, una recomendación es colocar el imán permanente junto con un objeto de base ancha para mejorar la estabilidad y el peso. Yo pegue un iman circular de 2mm de altura a un vaso de plastico y funciona perfectamente. Acople mas vasos de plastico y mejoro mucho mas!

jalfonsorobles

6 years ago

Hello! Thank you so much for sharing this project. I have build the project but am having difficulties making the magnet levitate. I am using a similar electromagnet as the one you showed. However, it cannot levitate the permanent magnet. I believe that electromagnet has a steel casing and this affects the magnetic field near the edges of the electromagnet. Would you have any suggestions? I am considering making an electromagnet myself if it could fix the issue.

jsirgado

2 years ago

Hi Jalfonsorobles! I believe the electromagnet is strong enough, the common distance is ~2cm, and 99% of the levitation is made by the permanent magnet, not by the eletromagnet. The electromagnet just avoid the fall. I see the data sheet for the hall effect sensor and looks good too. But please make sure you are using a linear hall effect sensor, not a hall effect switch, you can buy the 49E in the ebay, it cost just some cents, the kit with 10 is just $1.40: https://www.ebay.com/itm/10-pcs-49E-Hall-Element-OH49E-SS49E-Hall-Effect-Sensor-Linear-Switch/253056283580?hash=item3aeb5473bc%3Ag%3ApxMAAOSwvjlZcbiX&_sacat=0&_nkw=hall+efect+sensor+49e&_from=R40&rt=nc&_trksid=m570.l1313 Some tips are: Use big and strong permanent magnets. Keep a good distance between the hall effect sensor and the electromagnet (5mm or MORE). Good news: I am testing a new code to reduce(eliminate) the electromagnet interference in the hall effect sensor. Kind regards Juan.

Anonymous user

2 years ago

Which hall sensor are you using? Actually after wasting 1 week I found out that the sensor I was using cannot work with the circuit always check that it's analogue sensor and not digital. Also there might be a possibility that the electromagnet is not generating enough magnetic field ( increase the current, I use 12V 3amp power supply) also make sure the connections are secure. Be sure to check these before moving on for other things like code, design or electromagnet. Good luck. Regards glitch

Anonymous user

2 years ago

Typo -- "magnet field" should be "magnetic field"

Anonymous user

2 years ago

You should not expect the field to be all that strong at any distance > 3 cm. If you look at jsirgado's video examples, the permanent magnet is about 20 mm from the electromagnet, which generates a magnet field, not an electric field. The force between two magnets is inversely proportional to the distance squared (~ 1/r^2), so the force really drops off with distance. The A1302KUA is comparable to the SS49E, though the datasheet for the A1302KUA shows a bypass capacitor is used, probably just to keep the readings less noisy. 2.3 A at 12V is a lot of power. My magnet draws less than 1 A and works just fine. I really, really doubt your electromagnet is the problem. Building a bigger, more powerful magnet will not help because you still have to get the PID set up correctly. I recommend hooking everything up as shown, then setting the electromagnet control signal (PWM) to 128 (50%) and running a loop where you read the Hall sensor and print the values to the console. Write down the Hall sensor value with only the electromagnet on, then bring the permanent magnet closer and closer paying attention to the sensor values and how they change. From that you will be able to see how the electromagnet current needs to be changed depending on the position of the permanent magnet. Use that to understand how the PID equation is used to control the PWM setting. As I have said before, tackle the project one step at a time; understand how each element works. You can't expect to just wire things up, add code, and turn it on and have it work.

Anonymous user

2 years ago

I assume you have the electromagnet oriented with the steel housing side facing up and the pole of the magnet facing down. The permanent magnet must be in the middle of the pole about 15 to 20 mm distant and under the Hall sensor. Since you already have the electromagnet, there is no point making another; it is not the problem provided it is being properly energized. The best way to check that is to confirm the PWM signal is correct and I used an oscilloscope. If you don't have that, then the next best way is to change the Arduino code so that the PWM value alternates between something like 128 and 0 with a delay of at least 125 ms between each value. Then bring a ferrous metal object near the magnet close enough you can the magnetic field "pulsing". That's one way to check the operation. Whenever I build a project, I add each capability one at a time and check each time it works. Trying to do everything with a "big bang" (build it all and turn it on expecting it to work) rarely is successful.

jalfonsorobles

2 years ago

The electromagnet is oriented in the correct position, the problem seems to be that it is not creating an electric field strong enough to levitate the permanent magnet even with the 12V source. I tested it individually it seems to be really strong at distances less than 3cm from its core, but significantly weak at larger distances. I was thinking that the steal casing could be interfering with the electromagnetic lines at the edges of the electromagnet. I will check today that the PWM signal is correct with an oscilloscope, thanks!

jalfonsorobles

2 years ago

I am using a linear 10 mA, I think the part name is A1302KUA-T from a German distributor. I tested the sensor with a simple code that would light up an LED when in the presence of a small magnetic field to test its orientation and it seemed to work perfectly there, and I also tested it with a DMM to check its output and it was working properly. I also think the electromagnet is not strong enough, as the 12V source generates a 2.3amp when the electromagnet is on, I will try to create an electromagnet with copper wiring and a ferromagnetic screw and test it if it creates a greater magnetic field that the electromagnet I have. Thanks!

Anonymous user

6 years ago

Hi, I am trying to make this but in serial monitor the anval is coming about 5 to 10 and when I bring a particular pole of the magnet towards the electromagnet, there is a vibration felt in my hands, and when I slowly try to bring it close in order to levitate, it just sticks to the electromagnet, please help....

jsirgado

2 years ago

Hi Glitch. The vibration is Ok, is the hall sensor turnnig "On" and "Off" the electromagnet in the levitation point. But I believe the values 5 to 10 to anaVal are too small, my toy reads 200 to 270 in the levitation point with big permanent magnets. Try to use anoter 49E sensor(change it) or check the connections. Kind regards Juan.

Anonymous user

2 years ago

Hi! Actually I now know what I doing wrong, I was using A3144 hall effect sensor which turned out to be a digital hall effect sensor so I have ordered a couple of 49e. I hope this was the only mistake and also I am using a custom built electromagnet (400 turn copper wire on 3inch iron bolt) I hope they work now(fingers crossed). Thanks for helping Regards Glitch

Anonymous user

2 years ago

Actually I am getting it to lift the magnet but I am not able to adjust the position of the magnet using the push buttons the magnet just wobble and the falls down, any tips?

Anonymous user

6 years ago

Can I use a MOSFET instead of the Darlington transistor, particularly the MJE3055T? Thanks

jsirgado

2 years ago

Hi Glitch. I am not sure, but looks fast enough. The best way to know is test it! Kind regards Juan.

Polwan

6 years ago

I want to use pid version for my projects. What method do you use to find pid value

Polwan

2 years ago

Sorry i ask you again. In your script with pid if (digVal < 0) digVal=0; if (digVal > 255) digVal=255; Whether 255 on digVal > 255 is maximum pwm or your levitation value/setpoint?

jsirgado

2 years ago

Hi Polwan. You are welcome! Sorry the comment over the lines is not helpfull... (Ok, is really bad). ;-) The values 0 and 255 in the "digVal" are the limits(Min and Max) to write in the digital pin, it control the power in the electromagnet. My "levVal" is 262 (levitation point) in the start and the analog read "anaVal/Setpoint" must to be near it. The PID function Add or Subtract values in the digVal(digital write between 0 and 255, power of the electromagnet) to keep the permanent magnet near 262, the target value in the hall effect sensor anaVal(analog read between 0 and 1023). I will try to do some tests and post all to help. Tip: 1 - Use the "No PID" code version to find a good levVal, and hard code it in the "PID" code version. 2 - Use the switches for fine tune. I hope this helps. Any doubt or problem, just let me know. Kind regards Juan.

jsirgado

2 years ago

Hi Polwan. I just started with small values then changed and tested all a lot of times. To be honest I just did my first stable levitation in day 3. There is a lot of methods, I believe the best way is collect some data and make a Graphic, the user asap3210 did it and posted some videos, they are above in the comments. And there is this site with some methods and tips to do it: https://robotics.stackexchange.com/questions/167/what-are-good-strategies-for-tuning-pid-loops Kind regards Juan.

Anonymous user

6 years ago

Anyone interested can see my version based on jsirgado's at [Hackaday](https://hackaday.io/project/159566-discovere-magnetic-levitator)

jsirgado

2 years ago

Great work in the Hackaday! Thank you for sharing and for the support. The PID code is now correct. Kind regards Juan.

Anonymous user

2 years ago

https://hackaday.io/project/159566-discovere-magnetic-levitator is the full link in case people miss the embedded link above...

Anonymous user

6 years ago

Hii..I am student of bechlor of technology (BTech) ..I am in 2nd yr ...and I want to make a project related with levitation. ..I want to make a prototype machine on levitation. ..plz plz help me on this ....I search everywhere but I can't find right things for it ...so plz help me and send me some details for making my project .......I will really appreciate your help ...plz reply

Anonymous user

2 years ago

Since I posted all the design files, parts, and source code, what more do you need?

Anonymous user

2 years ago

Thnks eeknud but actually I did not find your post ..idk where it is 😅...I just read ur perious comment

Anonymous user

2 years ago

Or can you just provide me some images of real circuit connection of project ...plz

Anonymous user

2 years ago

Thank you very much for such help ...

Anonymous user

2 years ago

Where is your recent post ? Can you plz send me some detail to make a project type levitation machine

Anonymous user

2 years ago

It can't help ..I need detail information for construction of my project

Anonymous user

2 years ago

should be at the bottom of this page. I can see it.

Anonymous user

2 years ago

See my most recent post.

Anonymous user

2 years ago

Also, I believe he meant the post starting with: "The Levitator_PID.ino source has the variable setpoint, which is never changed once initialized. It should be changed in the check for the up/down button..." (also the only main post that he made) That's assuming you have problems with software. If you actually have a problem with circuit connection you should probably practice on a simple circuit with breadboard first. I don't have a picture of the original circuit (breadboard) but have one of a slight modification that I tried out before. (sorry about the quality, only one I have on hand right now) Will send a protoboard picture (original circuit, should be more clear than ones I have on hand) later in day. https://imgur.com/ExOFNRK https://drive.google.com/open?id=1FkBThKEqvwgGF_6evo1_W2iNXQjoIxkY schematic pcb

Anonymous user

2 years ago

Just buy the parts from suggested sites, then replicate the given breadboard circuit? Make sure to position the hall sensor and electromagnet correctly - use the 3d printed stand. It's all laid out in front of you, all you have to do is order parts and assemble it.

jsirgado

2 years ago

Hi people. I just see it now! Thank's all for the support. Now the PID version of the code is correct too. No "safe mode" yet sorry, I need test all again. Kind regards Juan.

jsirgado

2 years ago

Hi Vaibhavr2107. I believe it is a relative easy task even for beginners. There is a lot of information(all you need) in this "Page" https://create.arduino.cc/projecthub/jsirgado/magnet-levitation-with-arduino-eeeee4 And lot of tips in the "Comments" of the page. The project was first published in the Thingiverse site, there is much more information and tips there, if you need: 1 - Body for 3D printer(Parts) https://www.thingiverse.com/thing:1392023 2 - Board (Electronics) http://www.thingiverse.com/thing:1392530 3 - Body Sample(Make) https://www.thingiverse.com/make:201394 4 - Electronics Sample(Make) https://www.thingiverse.com/make:201420 Kind regards Juan.

Anonymous user

6 years ago

Hello, Will the PID code make the magnets levitate with more stability? I've tried the simple code, but it always seems to start shaking and stick to the electromagnet after a little while, maybe around 5-6 seconds. Is it a hardware problem (the electromagnet and hall sensor are positioned in the 3d printed stand), did I not adjust it enough (rough estimate of around 400 right now), or should I switch to the PID code?

jsirgado

2 years ago

I believe you can do it without using the PID version. I recomend first do it with "NO PID", then after try the PID version. Tips to avoid resonate: 1 - Try to put the hall effect sensor at 5mm or MORE from the electromagnet, remember it reads in both sides the electromagnet affects it, dismount all, clean the house for the sensor, bend the legs like the images, try again. 2 - Use big and strong permanent magnets, they are more stable because the weight and stronger magnetic field. 3 - Increase the value in 2 or 3 using the "switch +", I believe that the permanent magnet can be to close to the electromagnet. With my toy and the normal code(No PID), I do stable levitations with 2x 20mm x 5mm cylinder permanent magnets, or with 1x 10mm x 10mm cube permanent magnet with a 8mm screw atached to it, please see the videos. Kind regards Juan.

Anonymous user

6 years ago

The Levitator_PID.ino source has the variable `setpoint`, which is never changed once initialized. It should be changed in the check for the up/down button. In addition, the up/down button should be debounced in code by waiting a few milliseconds and then checking to see if the button is still pressed. The PID parameters will have to be adjusted depending on the electromagnet used and the mass of the levitating magnet plus whatever its attached to.

Anonymous user

2 years ago

Regarding point 2, waiting 250 ms after detecting an initial switch activation is not the same as de-bouncing the switch. After the initial check for the switch press, delay 5-10 ms, then check again that the switch is still pressed. Jack Ganssle provide a good page on this http://www.ganssle.com/debouncing.htm

jsirgado

2 years ago

Hi eeKnud. You are correct. 1 - Yes, the code is wrong, sorry! You need change the value of the variable "setpoint" and not of the variable "levVal" when the switches are pressed, the "levVal" is just the start point for "setpoint", I will try to correct it and add the safe-mode in the code and update all in the site as soon as possible. 2 - No, but you can change all. The program waits 250 milliseconds(1/4 of a second) every time the switches are pressed to make easy for beginners. 3 - Yes, you need find the correct values for "dt", "Kp", "Ki", "Kd" and "levVal" for your toy(hard to do...). Thanks! Kind regards Juan.

Polwan

7 years ago

My analog read on serial monitor read 510-512 with off electromagnet is that right? I build the circuit exactly the same with yours.

jsirgado

2 years ago

Hi Polwan. I believe it is correct. It is never the same, each toy have one difrerente value, because it depends of the hall effect sensor sensitivity and position and the permanent magnet size, weight and power. Kind regards Juan.

Anonymous user

7 years ago

Hi, Thanks for sharing your project documents. I built the circuit exactly the same with yours but I could not make it work. I set up levitation value both while magnet was working and not. My neodyium magnets even either pulled by the magnet or pushed (the same pole). What could it be the problem. I am using Arduio UNO rev3. Thanks in advance.

jsirgado

2 years ago

Hi fabio001. Some tips, it is not hard: 1 - Recheck if all is right and working, test the components 1 by 1. 2 - Put the hall effect sensor at 5mm or MORE from the electromagnet, remember it reads in both sides the electromagnet affects it. 3 - Use big and strong permanent magnets, they are more stable because the weight and stronger magnetic field. 4 - Use the North in the electromagnet facing the South in the permanent magnet. 5 - To find the levitation value, turn OFF the electromagnet and put the permanent magnet in the position near as possible of the electromagnet without it be attracted(pulled) by it, then read the hall effect sensor value using the Arduino IDE >> Tools >> Serial Monitor. Hardcode the value in the arduino(line 16: int levVal = 228; // Levitation Point Value;) the value for your toy in the place of the 228. 6 - Turn the toy ON, hold the permanent magnet in the position and use the switches for final adjust. If it not work, please read all the documentation and the comments for more tips and for more help see the "Documentation" and the "Makes" in the Thingiverse. Kind regards Juan.

Anonymous user

2 years ago

Thanks for your quick response. There is 2 reason why it won't work. First, electromagnet is not working properly and second the darlington transistor does not drive the electromagnet. I don't know how to check electromagnet is working properly. My guess is electromagnet is broken. If I directly connect to the source, it is like making short circuit, isn't it? Thanks again for your help. Fabio

Anonymous user

2 years ago

If you don't mind, I can give you my approach. I used the serial monitor to save the data (time, position of the magnet, sensor read) and then used MATHLAB to generate a polinomical regression. once you have that function, you can use as well the PID module of mathlab to approximate the PID values. I did this because one of the main issues for me was to have a value to start with. In order to get the data this is the setup I used: https://www.youtube.com/watch?v=8bscFQ9FbRo May the force be with you: https://www.youtube.com/watch?v=xiLQuDPk4FU

Anonymous user

2 years ago

Hi, in my opinion, it is very unlikely that the electromagnet is broken. One way to test it is with a multimeter, aproximate the magnet to the hall sensor and check the readings. if the setup is ok, it should be at full power (volts) and decrease as the magnet gets closer to the electromagnet. Most of the problems I had were with the mosfet, it is very sensitive to a wrong polarity (they get burned). So I would test the mosfet first. Regards, 

Polwan

7 years ago

Can i see serial monitor in your arduino ide when the magnet is levitate thats my email orangjahat172@gmail.com. Thanks

jsirgado

2 years ago

Hi Polwan. I sent the email with the Arduino IDE - Log. No video yet. Kind regards Juan.

jsirgado

2 years ago

Hi Polwan. This week I will try to do a video and post it in the Youtube. Find the right value and position are the hard work here. But is relativity easy to adjust the permanent magnet position after you understand the process. And I will send to you some examples of my serial-monitor log when the permanent magnet it is levitating. Please be patient. Kind regards Juan.

esamali

7 years ago

Nice

Isolino

7 years ago

Hello I've been looking for a long time, schematics for this project, but my intention is to do levitation in reverse, a levitron, Let the magnetic field form up, not down like this. You can help me in this, I do not know if I can adapt yours from this, to mine. Thank you

jsirgado

2 years ago

Hi Isolino! No, the materials I mentioned are for 4 electromagnets. I will make some blue prints and send to you. Please attention: I believe it will work. But I never did one. Kind regards Juan.

jsirgado

2 years ago

Hi Isolino. It is a differente project but is the same idea. Look at this toy in the youtube, I think it is what you wanna: https://www.youtube.com/watch?v=6klN93yWnd8 To build a similar toy "I BELIEVE", you need, 4 strong electromagnets, 4 transistors, 2 linear hall effect sensors, 4 diodes 4007N, 4 resistors 1K ohm, 4 switchs, and an arduino, the permanent magnets in the base for bigger gap are optional. 1 - Create 4 schemes for the electromagnets like the image above in my toy (ports D5, D6 and D10, D11). 2 - Create 2 schemes for the linear hall effect sensors (ports A1 and A2) and the switches (ports D4, D7 and D8, D12) like the image above in my toy. 3 - Mount the 4 eletromagnets aligned with the center, with a little gap 10mm between each other. 4 - Mount the 2 linear hall effect sensors with 10mm to 15mm out of the center, 1 to the left or rigth and the other to the front or back. It will allow read the X and Y position for the permanent magnet. 5 - Alter the code to read 2 linear hall effect sensors, control 4 electromagnets and alter the center values for X and Y with the 4 switches 2 for X value and 2 for Y value. 6 - Turn all ON, hold the permanent magnet in the correct position and hard code the linear hall effect sensors values in the arduino code. 7 - Use the switches for fine adjust. Obs: For this model all the electromagnets will be ON, just turn OFF the electromagnet opposite to the center value for X or Y. Try it and if you need more help, just let me know. Kind regards Juan.

Isolino

2 years ago

Hello Thanks for the help you are giving me, I will communicate you all the steps of the project, and provide images of yourself, over time. For better communication, and if you want to send me your drawings, we'll email you if you can. isolinoliveira@hotmail.com Thank you very much

Isolino

2 years ago

Hello again For my project, I will use 4 reels, the materials you mentioned, I will need to increase the 4 times?

Anonymous user

7 years ago

Very nice, I built a similar project (http://johann.langhofer.net/electronics). My problem was stability, preventing the system from oszillation. Finally I came up with a simple slution (no PID controller). Thanks for sharing

jsirgado

2 years ago

Hi Javalang. I saw your project in the link and is great! Nice work! If I make a new one, I will include some upgrades like in your project: 1 - Curver arms for better view; 2 - Hall effect sensor in the bottom for more stable levitation; 3 - Big, really big eletromagnet, maybe without an iron core just copper; 4 - Include "safe mode" in the code, in case of permanent magnet drop. 5 - And I will test the aluminium/copper in the bottom as diamagnetic. Thank you very much!

vefa

7 years ago

Hello, Many thanks for sharing your project which is awesome. Can you tell me why did you use a high power transistor? Could not arduino do it by it self. Thanks.

vefa

2 years ago

Can you elaborate, how electromagnet's magnetic field did not effect such a sensitive sensor that is fairly close to the em.

jsirgado

2 years ago

Hi vefa. Good question! Yes the electromagnet affects the hall effect sensor a lot. But there is a trick here. When the electromagnet is ON the hall effect sensor always turns it OFF, but in the next loop, just after some milliseconds the arduino reads again, this time the correct value without the interference of the electromagnet and adjust the permanent magnet position. The true is that you need 2 cycles to control the permanent magnet, but uses just one. Tips: 1 - To find the correct value for the levitation in your toy you need turn OFF the electromagnet. 2 - If the hall effect sensor is too close to the electromagnet the interference will be too big and the toy will not work or the permanent magnet will resonate and fall. 3 - If you put the hall effect sensor below the electromagnet you will have a much better control over the levitation. Great work. Kind regards Juan.

jsirgado

2 years ago

Hi vefa. Sorry, I do not know if I really understood the question. The electromagnet needs 12V, the arduino accept up to 12V in the V (in) but works in 5V and 3.3V not 12V. (Erratum: Arduino up to 16V in the RAW input). We need the transistor to control the 12V in the Electromagnet. I used the TIP120 because it is cheap, fast enough, has a good range, is common and easy to find. You can use others transistors and others linear hall effect sensors with no problem. But with the TIP120, you can customize your toy using a strong electromagnet to a bigger gap, with the same electronics. Kind regards Juan.

Anonymous user

7 years ago

I made it, but evidently I did something wrong, the hall effect sensor is face down, I've tried both programs but I can't get the magnets to levitate, they keep going all the way up to the electromagnet. I've changed the values in the program from one extreme to the other and it does not make any difference. What should I look at?

jsirgado

2 years ago

Hi paulbrandt2. Ok! 4 tips. 1 - Recheck if all is right and working, test the components 1 by 1. 2 - Put the hall effect sensor at 5mm or MORE from the electromagnet, remember it reads in both sides. 3 - Use big and strong permanent magnets, they are more stable because the weight and stronger magnetic field. 4 - Turn off the electromagnet and put the permanent magnet in the position near as possible of the electromagnet without it be attracted(pulled) by it, then read the hall effect sensor value using the Arduino IDE >> Tools >> Serial Monitor and hardcode the value in the arduino(line 16: int levVal = 228; // Levitation Point Value;) the value for your toy in the place of the 228. Use the switchs for final adjust. Please, let me know the progress. If it not work, I can help more! It is not easy, but I believe it is not so hard. Kind regards Juan.

ekaggrat

7 years ago

is it possible to change the height of the suspending magnet in realtime? like you start on the top and then slowly move it towards the bottom and then pull up again? i cant find anyone doing it..

jsirgado

2 years ago

Hi ekaggrat! Yes, I saw a video of it in the youtube(differente toy). With this toy you can do it pressing the switches + and - or creating a new function in the arduino to control the permanent magnet position, but I believe the range is very small. To work better, I recommend a really strong electromagnet and maybe remove the iron core for a bigger range: (from the electromagnet to the ground) ;-). You can also try change the tension/current in the electromagnet and/or the frequency in the arduino. Be careful... Kind regards Juan.

Anonymous user

7 years ago

Thanks, I am going to make one for my grandson. Perhaps it will get him interested in electronics!

Anonymous user

7 years ago

thanks for sharing

Anonymous user

7 years ago

Wingardium Leviosa !!!

Anonymous user

7 years ago

How can the magnet stabilise itself without using PID?

jsirgado

2 years ago

Hi arvinwu168 and Mat13. The no PID version (fixed value), how it works: The eletronics just turn on the electromagnet when the permanent magnet is falling and then turn off before the permanent magnet rise too much(just tenths of a millimeter). Because the electromagnet is turned on and off a hundred times per second the permanent magnet stay in place. The linear hall effect sensor 49E is extreme precise and sensitive, for those who look it, is like the permanent magnet were standing. Kind regards Juan.

jsirgado

2 years ago

Yes, for sure! There are 2 versions of the firmware for Arduino: 1 - Easy Levitation. Levitator.ino - Fixed value (Just change the value with the switches). 2 - Hard to do... Levitator_PID.ino - PID function (You need find the correct PID values for your toy, but you can adjust the seed with the switches). Sorry if it is not clear in the project. kind regards Juan.

Anonymous user

2 years ago

the "simple code" is a P function (no I, no D): turn on or off the electromagnet proportionnaly to the distance. Well done @jsirgado! Thanks for sharing

Anonymous user

2 years ago

Could you explain how, like the process? For all of the project I have seen they use PID, so I am very curious how the magnet is able to stabilise with a simple code. Thank you :) Good job btw

paulofreitasnobrega

7 years ago

Hello! I realized that the design of your fritzing project is more elegant than normal. Could you tell me if this is a specific version of fritzing or a package of parts?

paulofreitasnobrega

2 years ago

Thanks for the feedback. The image was very nice.

jsirgado

2 years ago

Hi Paulo Freitas Nobrega! Sorry, the original project was made in the Fritzing last version, no external packages, but the image above was edited using PaintBrush, just to make it more clean and simple for beginners. Abraços! ;-)

lumek

7 years ago

Thank you for sharing, it is so cool to see how relatively simple electronics can drive in real time physical things.