I want to drive a coil with a PID controller on an Arduino. I already made it on my computer, so the PID itself is not a problem.

The coil has a resistance of a little less than 1 Ω, an inductance of 10 μH and needs 40 A to reach of field of 1 mT. I need the field generated by the coil to be very stable, so it is DC current. I need a stability around 50 ppm. I have a power supply that is able to supply power to the coil (36 V, 40 A).

My problem is: how to amplify the command from the Arduino to give power to the coil? I read a lot about people using a MOSFET with PWM, but I wonder what the output signal is. Is it stable or does it have the same shape as the PWM? Maybe the coil helps to stabilise the current.

I know the Arduino Uno doesn't have a analog output, but I can use another board or a DAC.

Maybe this is not the right component to use, so do you have any idea what would be the best?


  • 1
    \$\begingroup\$ Whether this is the right way to do it would be easier to answer if you gave some idea of the application. However in many applications, PWM drive into an inductor smoothed by the inductor will be good enough. [What matters: average field strength over x S, or max induced error currents from the switching wavefronts?] The other option is a programmable power supply, which will probalby end up looking like pwm into an inductor anyhow... \$\endgroup\$
    – 2e0byo
    Sep 7, 2022 at 10:25
  • 4
    \$\begingroup\$ If you have feedback from a sensor, you don't need a current source, you can PWM a voltage source, the closed loop will compensate for the wire resistance changes from self heating. Realize that switching 40 A is not trivial, the design details are important. \$\endgroup\$
    – Mattman944
    Sep 7, 2022 at 11:50
  • 1
    \$\begingroup\$ @louisld can you give a bit more detail? Stabilised at 5ppm over what timescale? And what metric? is 5ppm the pk-pk error, or the maximum distance from the setpoint? Again it would probably help to know what you want to do with this, at least generally. \$\endgroup\$
    – 2e0byo
    Sep 7, 2022 at 12:20
  • 1
    \$\begingroup\$ Also not only is switching 40A far from trivial, switching 40A into an inductive load is really not going to be trivial. You PWM it by disconnecting the power from the inductor. What you're basically designing is a switched-mode power supply, with no (electrical) load and magnetic feedback. It'll probably be a bit easier than designing a 40A SMPSU as you probably won't have massive transients and sudden loads to handle (you still haven't told us what you're doing with this field...) but the switching + snubbing will still be hard. Maybe have a look at some SMPSU designs? \$\endgroup\$
    – 2e0byo
    Sep 7, 2022 at 12:24
  • 2
    \$\begingroup\$ 10 uH is small, so unless you add some smoothing (another inductor in series), or use a ridiculously high frequency, PWM will have a lot of ripple. I am liking @glen_geek approach a lot. Set your power supply to 41 A, shunt 1 A. I might use an NPN with resistor in linear mode to minimize ripple. Assuming that efficiency isn't that important. \$\endgroup\$
    – Mattman944
    Sep 7, 2022 at 13:16

2 Answers 2


Here is a solution based on @glen_geek 's idea. Set your lab power supply to current limit at 41 A. Set the voltage high enough so it will be in current limit for all conditions (~40V).

This circuit will shunt the excess 1 Amp of current away from the coil. The emitter resistor reduces the sensitivity to the transistor gain.

I am assuming a DAC with 5V output, you will probably want to reduce R4 if you have a DAC with a lower output. And note that you will need to invert your PID output in software, a larger voltage will reduce the coil current. About 3V from the DAC will cause 1 A of current flow. More than 3V will cause more current to flow in the shunt circuit and therefore less in your coil.

The circuit will dissipate about 40 Watts in heat, about evenly split between Q2 and R3. You need a large heat sink, a rough estimate would be something about as big as a textbook. Both hot components could share the same heatsink. A fan may be necessary also.

50 PPM is a challenge, the DAC needs enough resolution to assure that one count is less than this. Since this circuit is only adjusting about 1/40th of the range, a 14-bit DAC will give about 15 PPM per count (marginal IMO). Use a 16-bit DAC.

Realize that this is just a first cut, you need more detailed calculations and/or simulations and/or testing.

I am assuming that your lab power supply has an analog control loop. It can still have digital controls, as long as a DAC is the input to the analog control loop. If it has a digital control loop, the granularity will likely kill this whole concept.

Be sure that whatever you use to measure the magnetic field has sufficient resolution. This could easily be your weak point in the system.


simulate this circuit – Schematic created using CircuitLab

enter image description here

Edit: I built the circuit. My lab supply only goes up to 31V. The voltage level to get 1 amp is slightly different from the simulation, the simulation would be more accurate if I used the exact transistor.

What is most important is that the slope of the line near your operating point is reasonably straight. The PID controller works best if the system is linear. It is easier to make a linear system with a bipolar transistor (NPN) than with a MOSFET.

These are the largest heatsinks that I have in my stash (4 x 5 inches). The heatsink with the resistor gets quite warm, about 55 degC. The resistor itself is about 10 degC warmer. You can't hold your hand on it, but human reaction time allows you to remove your hand before you are seriously burned. This is the maximum temperature that I like to run my heatsinks.

enter image description here

enter image description here

  • \$\begingroup\$ Thank you for your clear answer. I will try to build this circuit and give you feedback when I am done. The magnetometer has a resolution of 10nT so it is fine. \$\endgroup\$
    – louisld
    Sep 8, 2022 at 8:43
  • \$\begingroup\$ A linear system with a MOSFET is easy... if you get a MOSFET suitable for linear applications. Unfortunately, most of the discrete MOSFETs on the market are designed for switching applications, and have unusably high transconductance. (at least, unusable without a feedback loop). \$\endgroup\$
    – Hearth
    Sep 17, 2022 at 16:10

I finally built the circuit and tested it. It works pretty well except that it may lack some precision because of the ADC and DAC resolutions.

For the DAC I used a MAX541 that can communicate with the Arduino using SPI. The reference voltage of the DAC needs to be 2.5 V so I built a resistor bridge with two capacitors. When measuring voltage I get less than 2 V. As the voltage offset of the Darlington transistor (TIP142) is 1.2 V, the output of the DAC was too low. So I added an op-amp (MCP6292) with a gain of 3.

circuit schematic

circuit photo

Circuit response


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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