Arduino PWM for Solenoids?

I was hoping to change the force that a solenoid provides. I've seen a similar layout to the one listed here: link. However, will the setup, with a transistor, work with PWM for variable force? Also, does increasing the PWM frequency increase the force, and does decreasing the PWM frequency decrease the force?

PWM uses a fixed frequency. The variable parameter is the duty cycle. 0 - 255 for most Arduinos.
As long As the solenoid doesn't get all up into iron, yes. Force can be controlled.

I don't see why it won't work. However you should know solenoid force varies significantly as the core moves away from the coil.

Transistor will work but you would be better off using a MosFet. While transistors are not obsolete, for switching Mosfet's have pretty much taken over.

Force is not a function of frequency.
Within reason you can increase or decrease frequency. However the low limit in frequency is when the PWM frequency starts to be as long as the solenoid takes to move.

Because energy is stored in the solenoid coil you must put in some protection for the MosFet.
Options:

  1. Put a diode across the coil (cathode connected to V+) .

  2. Put a diode and a Zener across the coil. This will in the coil releasing faster.

Than you for your response! My bad, I didn't do my research and I thought PWM changes frequency for some odd reason. I'll probably go with option 2 as I want to provide a semi constant force(in a haptic feedback system). Do any formulas exist for calculating the optimal diode and zeners for a certain solenoid?

At these frequencies any diode will do. The Zener is there to protect the MosFet switching element. The Zener can be anything between not there to about 80% of the MosFet breakdown voltage.

However after 2x the solenoid voltage not much can be gained.

A typical spec sheet for a MosFet.
image

IT does and it doesn't. At the instant the pulse width changes, the apparent frequency has to change for only that instant.
Paul

As you found, No changing PWM doesn't change frequency. To change the frequency you have to change the period.
In either case, the effect on the solenoid in zero / minimal.

Hmm, but changing the duty cycle, or the 0-255 parameter in AnalogWrite should do the trick, right?

Yes.

Unfortunately the function was named AnalogWrite instead of PWMWrite

void PWMWrite(uint8_t pin, int duty_cycle) {
    analogWrite(pin, duty_cycle);
}

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