I have to control one electromagnet (like this one, see the image above) with PWM from a micro controller (like the teensy board).

enter image description here

In the label there are only those information:

  • 12V
  • 400N

If I've got it right I need an external power supply with 12V and a MOSFET (like IRL or IRF or similar).

I'm not an expert and I've never used electromagnets but 400N seems quite a lot to me. Which are the possible risks? Is there a risk to damage the micro controller board? or the electromagnets? Are there any other kind of risks to take in account with electromagnets?

EDIT: I'm using the electromagnets to play with ferrofluid and obtain stunning images, like the ones in this video. You can find a lot more if you google it.


  • \$\begingroup\$ How about providing a link to the exact electromagnet - the one you have provided says 80 kg lifting magnet and does not mention 400 newtons as far as I can tell. \$\endgroup\$
    – Andy aka
    Aug 30, 2016 at 12:33
  • \$\begingroup\$ Maybe you tell us a bit more about why you have to use PWM. Naturally electromagnets have quite an inductivitiy and so the current waveform might not be as you expect \$\endgroup\$
    – PlasmaHH
    Aug 30, 2016 at 12:54
  • \$\begingroup\$ @Andyaka I have updated the link with the one I took, but there is no N in the bay page, it is written in the label \$\endgroup\$
    – nkint
    Aug 30, 2016 at 13:13
  • \$\begingroup\$ So you have gone from an English link to the same link but in Italian as far as I can tell and my original comment still stands. \$\endgroup\$
    – Andy aka
    Aug 30, 2016 at 13:20
  • 1
    \$\begingroup\$ @nkint: Please don't link to eBay items. Once that link goes dead your question is useless. Instead post the relevant details and photo in your post. You can put the eBay link in as well as a reference. \$\endgroup\$
    – Transistor
    Aug 30, 2016 at 15:00

4 Answers 4


Switching inductive loads with MOSFETs is dangerous, because the inductance will continue to "push" current into your FET, after you've turned it off. (You will find a lot of information regarding this online, just Google "switching inductive loads" or so).

Another point to consider is that your current raise is exponential and the resulting power need not be proportional to your duty cycle. The resulting current will somewhat look like this: Voltage/Current-Diagram

The current will drop faster when you are reducing the magnetic reluctance (i.e. when you are using the magnet to lift stuff).

If you are really trying to implement this, you should probably use the actual current as feedback to your controller.


First, that link says 80 kg. That requires about 800 N to lift on earth.

There is no spec on that page that indicates the current required at 12 V. You need to know this to design the circuit. If you can't dig around to find the spec, then you will need to measure a sample. DC current is strictly due to the voltage applied to the DC resistance of the coil. You can use a ohmmeter, or otherwise measure the current and voltage at some operating point. The current will scale linearly with voltage, so you can compute what it will be at 12 V.

Once you know the current, you pick a switching transistor that can handle it and the voltage. A low side N-channel MOSFET is the obvious choice. At such a low voltage, they are available with quite low on resistances. This is important since the FET on resistance (Rdson) not only causes a voltage drop, but will cause power dissipation in the FET proportional to the square of the current. The easiest would be a FET that has low enough Rdson that the dissipation is low enough at your current to not require a heat sink.

For example, let's say the magnet draws 5 A at 12 V (it's DC resistance is 2.4 Ω). A 20 mΩ FET would dissipate (5 A)2(20 mΩ) = 500 mW. A TO-220 case, for example, would get hot in free air, but should be able to handle it. Check the FET datasheet carefully to see what the dissipation will be, the temperature rise due to that dissipation, and whether that resulting temperature is acceptable or not.

PWM is good for modulating the coil current. However, make sure the flyback catch diode is rated for the current. At this low voltage, use a Schottky for the lower forward drop and therefore less wasted power.

Make sure the PWM period is short enough so that the current changes only a little during one period. Think of the rippling current as the average DC plus a AC component. Only the DC component produces the magnetic field you want. The AC component only causes additional I2R heating and thereby wasted power.

Fortunately a magnet like this has substantial inductance, so even modest PWM frequencies will have sufficiently short periods. For example, let's say the magnet coil has 10 mH inductance (just picked something out of the air, may not match your magnet). (12 V)(40 µs)/(10 mH) = 48 mA. That is how much the current would change thru the coil when 12 V is applied to it for 40 µs. That's small compared to the 5 A we used as example above. Again, you have to determine the real numbers and do your own calculations. The worst case is a square wave with the on time being half the PWM period. For a 40 µs PWM period, the on time would be 20 µs, and the ripple 24 mA peak to peak.

40 µs for the PWM period is the highest I'd use. That's 25 kHz and just above the audible range, but still "slow" for any competent microcontroller and FET driver switching time. You should be able to do 50-100 kHz without any real drawback.


80kg is about 800N, not 400N.

The power is listed at 13W implying a current of just over an amp, so I'd choose a FET and flyback diode rated at 2A. The diode will be doing a considerable amount of work due to the high inductance.

You'll then have to tune the PWM frequency so that the FET does not spend too much of its time switching. You may need a FET driver buffer for high-frequency PWM.

The other obvious risk is that large magnets may cause injury. You don't want to suddenly apply 400N to your fingers.


The switch must be rated for the current and the voltage. MOSFETs are easier these days. I think that you should use one. Try to get a logic level device or low threshold device if you can. This means that the micro could drive the gate through just a simple gate resistor. It is very important to use a freewheel diode when driving a solenoid, they store a lot of inductive energy. It's best to use a fast diode like a schottky for the freewheel diode. If your PWM is at audio frequencies you may hear the solenoid hum at the low end and scream at the midrange and squeal at the top end. 20KHz operation is the generally accepted way of mitigating audible noise.


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.