Controlling an Electromagnet with Arduino


I am trying to use an Arduino(Mega) to control an electromagnet strength.
In the end of the day, I will need to control the strength in 3 levels (High/ Low/ Off), I don't know yet what Voltage I will use for each level (Off is 0V of course).

My electromagnet is a 12V electromagnet. the High level will be at least 8 - 10V (possibly the full 12V strength).

I tried controlling the electromagnet with a DC motor driver L298N (with PWM signal from the Arduino to the Enable pin).
It worked well but when the PWM is not in 100%, the electromagnet vibrates and it causes noise with the bracket (really small vibrations, not visible by the naked eye, I only hear the noise from the bracket).

I would like to hear if you have any idea for a method to control the electromagnet strength with an Arduino (or solving the vibrations problem with the L298N).

Thank you.

Welcome to the Arduino forum, but you really need to review the basics of electromagnetism. It is controlled by ELECTRIC CURRENT, not voltage. Your design need to take that into consideration.

Can You post a link to the data sheet of that electromagnet? Or tell how much current it uses at 12 volt?
A wiring diagram might be of help.

The frequency of the PWM signal is 490 Hz or 980 Hz. Those frequencies are audible. You can change those frequencies to an inaudible range.

You may be better off using a logic level MOSFET to drive the electromagnet. The L298 is ancient and inefficient technology. The Darlington output drivers dissipate quite a bit of energy as heat.

Thank you for the response, the current is a direct function of the voltage (V=RI), this is why i AM referring to voltage.
the electromagnet resistance is ~30 Ohm.
I did not found any data sheet, this is the electromagnet:

Thank you very much, can you please give me more information about the MOSFET solution?

Yes, but in this case we have an inductive load and the current also depends on the inductance of the magnet and the switching frequency. With a power supply of 12 volts and a resistance of 30 ohms, a maximum current of 0.4 amps is obtained at saturation of the magnetic circuit. I guess a field effect transistor like the SI2300 is a good choice.

Thanks for the response,
the SI2300 comes in a package that is not compatible with my project.
I did a little research on the MOSFET option and I found someone do a similar thing with the IRF520, do you think it can work for my situation?
Thank you.

IRF520 is not a logic level device which means that it will not fully turn on with 5V. IRL520 is a logic level device (Rds(on) is 0.27Ω at 5V Vgs and Id of 5.5A).

Like @groundFungus says, MOSFET is needed to be a logical level type. I prefer IRLZ44N, but IRL520 is also suitable. For IRLZ44N Rds(on) is 0.025 Ohm at Vgs 5V and Id 25A.

@groundFungus @flashko
Because of inventory problems in my country, I could only find this two MOSFETs:

Are they compatible as well?
thank you

Yes, both is Logic Level MOSFET.

May I ask why you think a PWM solution and mosfets will work well? An electromagnet needs a constant current supply. NOT a PWM. Otherwise it will just buzz and be less effective.

Simplest way is to use a relay and a 12DC supply. You can use a MOSFET but why?, when a relay is perfect for that?
You will need a small mosfet and flyback diode to switch the relay coil on and off. But that's it.
A relay is smaller and cheaper and easier than a mosfet with its necessary heatsink.

I don't know if you have realised it, but most constant-current supplies nowadays use an inductor as the main element.

Yes, buzzing is exactly the problem the OP describes, so the solution is to shift the PWM frequency into the ultrasonic range. But there is no suggestion that PWM would be "less effective" than any other approach. Altering the "effectiveness" of the electromagnet is exactly what the OP is requiring. :sunglasses:

Using a constant-current regulator and altering its current setting by program control is certainly a possibility, but said constant-current regulator will necessarily include an inductor. As you already have an inductor in the electromagnet, you might as well use it and simplify the overall circuit. Note that a commutating diode is a critical component of the PWM control.

Why not use a logic level MOSFET and controll it via a digital output pun that is either On or Off? The MOSFET + 2 resistor solution takes less space and uses less current.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.