# Driving 12V hand wound solenoid using PWM

I'm trying to drive a hand wound solenoid (140 turns of 0.8mm enamel copper wire, 4cm long) with a 12V/2A power supply. I need to control the intensity of the force generated by the solenoid, so I'm using a PWM signal generated from an ESP32, with a frequency of 1kHz. An IRF540N N-channel MOSFET is used as a switch, driven by an MCP1416 MOSFET driver, using 12V as the gate voltage. The PWM signal from the ESP32 is fed to the input pin of the mosfet driver. The solenoid has a 1N4007 flyback diode.

The problem I'm facing is that the diode and the solenoid get really hot. I tried to change the flyback diode, like someone suggested in other posts with an ultrafast one, like the RHRP1560 or BYR29 but nothing changed.

What solution could I adopt to resolve at least the diode problem?

• What is the resistance of your solenoid? You don't have that many turns and the wire is fairly thick. Dec 12, 2023 at 20:01
• I would want to see the current. If you don't have a current probe, you must improvise. Put a 0.1 ohm resistor in series with the MOSFET Source pin (after R1). Dec 12, 2023 at 20:05
• Use many more turns of finer wire. Dec 13, 2023 at 2:05
• The solenoid resistance is 0.4 Ohms, also I measuered the voltage across the solenoid and it drops from 12V to 5.5V when its on. The current passing through is ~3.7A. So there's around 20W power generated. Dec 13, 2023 at 12:42
• 140 turns is pretty low for a solenoid. Try an order of magnitude or two more. Dec 13, 2023 at 15:37

One technique that can help with keeping the solenoid cool is by having two different modes that you power it. The first one is the pull in state. This is where you give it the maximum amount of current that it needs to pull the solenoid in. After the solenoid is pulled in you do the second mode which is the hold in state. In the hold in state, you apply significantly less current.

The pull in state should only last a few milliseconds. The hold in state is where it's going likely be running the longest and be the main contributor to parts getting hot. Once the solenoid is fully pulled in, the magnetic field is stronger and therefore requires less current to keep it held in. Using less current will help keep the all of the parts cooler.

Here's an example: Apply 2A (pull in current) to the solenoid to pull it in. After it is fully pulled in, apply 0.5A (hold in current) continuously until you want to turn it off.

The are made up numbers just so you'll have to run tests on what the minimum amount of current you need to keep it pulled in reliably. The same goes for how it takes the solenoid to pull in which is how long you'll need to run the pull in current for.

• Unfortunatly I cannot use this method because its not moving anything, I only need it to generate a magnetic field with the intensity I decide through the PWM signal. Dec 13, 2023 at 12:44
• Oh okay. Sorry this couldn't help you. This is not a solenoid btw. What is this being used for? Dec 13, 2023 at 17:17
• No worries I appreciated the help, also I should have used the correct term coil in this case. I'm using it for a magnetic levitation project, thus the PWM control. Dec 13, 2023 at 20:16

The problem causing both the solenoid and the diode to heat up is that your solenoid has far too few turns and too low resistance. You should increase the number of turns by one or two orders of magnitude, and use thinner wire.

How much current can your power supply provide? Design the solenoid to produce the maximum desired magnetic field at some current much lower than that, and choose the wire gauge such that the resistance of the solenoid alone provides that current at your power supply voltage or slightly below it, then add a series resistor to compensate if needed.

Using a fast-recovery diode is also essential for PWM control. A Schottky diode is probably your best bet, as they're instant-recovery. A FRED would work too, if you need a pn diode. Make sure it's rated for sufficient average forward current!

• Thanks, I'll try to wind a bigger coil with thinner wire and actually make some calculations. I'll let you know if this works. Dec 13, 2023 at 20:18