I am following a hackster project on magnetic levitation here - https://www.hackster.io/jsirgado/magnet-levitation-with-arduino-eeeee4

However, I have followed everything but still, it's not working.

Here are changes to the circuit I made:

  1. The electromagnet which I am using is that of 5V instead of 12V
  2. The transducer which I am using is ss8050 instead of TIP120
  3. Hall sensor is tapped just at the bottom of the electromagnet

Electromagnet link - https://shop.edwinrobotics.com/widgets/1568-5v-electromagnet-25-kg-holding-force-p4020.html


The best I can do is to make the magnet jump up and down fast but it never levitates. Have tried changing PID setting from the project as aggressive and mild but still didn't achieve the final result.

I need advice from an expert to tell me what I am doing wrong here. All components are in good condition and 5v electromagnet is strong enough.

So what am I missing here?

  • 1
    \$\begingroup\$ "... but still, it's not working." What is not working? Does the electromagnet work when you connect it directly to the 5 V supply? Does it work on a 12 V supply? If not, what is the resistance of the coil? What is the current rating of your power supply? Put all the information into your question and remove the code if that's not the problem. Explain clearly what you expect to happen and what does happen. Give voltage and current readings. \$\endgroup\$
    – Transistor
    Mar 30, 2019 at 17:38
  • \$\begingroup\$ It will fail unless you use the correct parts and voltages. Substitutions must have similar or better specs. not worse. or lower current rating and lower input power \$\endgroup\$ Mar 30, 2019 at 17:43
  • \$\begingroup\$ Magnetic levitation schemes like this are inherently unstable, so with constant excitation to the electromagnet the magnets will always either fall away or jump to the electromagnet. This means that the only sign of levitation that you'll get is just a hint: you'll see a markedly different ("markedly" as in 1/4 inch or so) distance at which the permanent magnets will fall away from the electromagnet with no excitation, and the distance at which the permanent magnets will fall away with 5V drive. \$\endgroup\$
    – TimWescott
    Mar 30, 2019 at 17:49
  • \$\begingroup\$ @SunnyskyguyEE75 the electromagnet, at least, looks like it'll do the job, as long as the drive circuit is adequate for higher current at the lower voltage. \$\endgroup\$
    – TimWescott
    Mar 30, 2019 at 17:52
  • \$\begingroup\$ electromagnet works and it's designed for 5v only \$\endgroup\$
    – suu
    Mar 30, 2019 at 19:31

1 Answer 1


enter image description here

All CMOS drivers have an Ron resistance with a wide tolerance, for Vout="1","0"

\$ ~~~R_{on}=\frac{(Vdd-Voh)}{Iol} ,\frac{V_{ol}}{I_{ol}}\$ 3.3V logic family is 25 Ω, and 5V logic family is 50 Ω ±50%


- if using 3.3V logic which is a 25 Ohm driver
- to NPN @ 60 mA base current with specs of VBE(sat)=1.2V @ 80mA, Vbe (on)= 1V @ 10mA
- Choose Rs = 10 Ohms from 60mA=(3.3V-1.2V)/(Ron+Rs) 2.1V/60mA=35 Ohms
- driver Pd= 60mA*3.3V = 200mW shared by driver, Rs and Vbe

- if using 5V logic which is Ron= 50 Ohm driver
- Choose Rs = 13 Ohm from 60mA=(Vdd-Vbe)/(Ron+Rs)


simulate this circuit – Schematic created using CircuitLab

  • \$\begingroup\$ Would any other experts like to weigh in on my solution? \$\endgroup\$ Mar 30, 2019 at 20:41
  • \$\begingroup\$ oops I forgot the clamp diode \$\endgroup\$ Mar 30, 2019 at 20:43
  • \$\begingroup\$ Why is the first part of your post a screenshot? \$\endgroup\$
    – user39382
    Mar 31, 2019 at 4:03
  • \$\begingroup\$ I liked the colours invoked with the editor more. Did you like how I pulled out the relevant specs and then concluded the issue was the driver base R meanwhile the 5x 25kg electromagnet is due to it's surface area and only 2x in this situation \$\endgroup\$ Mar 31, 2019 at 6:44
  • \$\begingroup\$ I am using 5v external power supply for the electromagnet, will the circuit still be the same? \$\endgroup\$
    – suu
    Mar 31, 2019 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.