0

Motor shield v2 and solenoid
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Motor shield v2 and solenoid

by leo3linbeck on Thu Sep 18, 2014 9:13 pm

Greetings!

I am using AFMSv2 to drive a solenoid. It is a 12v solenoid, rated at 400mA. The leads of the solenoid are wired into one of the channels of the MS (2 leads). I use the setSpeed() method, using 170 as the speed, to initialize the channel, and then use run(FORWARD) to activate the solenoid, and run(RELEASE) to deactivate it.

Anyway, everything works fine, but when the solenoid activates, there's a faint high-pitch whine. And over time, the solenoid gets very hot (and in one case started sticking in the activated position). I put an ammeter on it, and it appears that the current is spiking to 1-2A when the solenoid is activated.

I measured the resistance of the solenoid, and it's about 5 ohms. So when the run(FORWARD) method is called, voltage goes to about 8V (12V * 170 / 255), which calculates to about 1.6A of current. This is 4 times the rated current of the solenoid.

Like I said, the solenoid works, but I'm concerned that I'm missing something. I tried adding a 25 ohm resistor in series on one of the leads (taking the circuit resistance to 30 ohms, which should give 400mA at 12V), and cranked the speed up to 255 (to get 12V), but the solenoid failed to activate.

Any advice would be greatly appreciated. Cheers,
L3

leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2 and solenoid

by franklin97355 on Thu Sep 18, 2014 9:29 pm

The motor shield was not designed for solenoids and as you found does not work well. The speed is set using PWM (the squeal you heard) and delivers the full voltage on the high pulses. I think I read somewhere that using 255 is full stop so you might try 254 instead. If you plan to run solenoids I'd recommend looking into something like a MOSFET or relay instead.

franklin97355
 
Posts: 20637
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Motor shield v2 and solenoid

by leo3linbeck on Thu Sep 18, 2014 9:33 pm

Appreciate the reply. I'm running at 170 rather than 255, but I get what you're saying. I was originally going to use MOSFETs, etc. but saw postings here that said the MS could run solenoids.

I guess there's a difference between "could" and "should." ;-)

Thanks again. Cheers,

L3

leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2 and solenoid

by adafruit_support_bill on Fri Sep 19, 2014 5:52 am

The shield can drive your solenoid. But a full H-bridge is a bit of overkill. The H-bridge is composed of 4 MOSFETs, and you really only need one.

In any case, the whine is from the PWM pulses and you will get that whether you use the shield or a standalone MOSFET. You will need to reduce your PWM duty cycle (setSpeed()) to keep within the current limitation of both the shield and the solenoid.

Solenoid specifications are not always consistent between manufacturers and you have to read between the lines a bit. Rated voltage just means the max voltage the windings can handle. If does not mean it will tolerate that continuously. The current rating and coil resistance are the more important numbers. In the case of your solenoid, feeding it max voltage will cause it to grossly exceed the max current.

A common way to drive a solenoid is to give it a brief pulse of max voltage - to overcome the effect of the coil inductance and get the solenoid started. After that brief pulse, you would reduce the PWM duty cycle to a much lower level to hold the solenoid in place - but at a safe current level. With a 5 ohm coil, 400mA would be only about 2 volts - or 12v with about a 17% duty cycle. With a 'speed' range of 0-255, that would be about 42. (somehow I knew that would be the answer ;)

400mA will probably still keep the solenoid pretty warm. If you don't require the full holding force, you can reduce the PWM duty cycle further.

To get rid of the whine, you could go the standalone MOSFET route and change the PWM frequency. If you increase the frequency above 20KHz, it will be inaudible to most humans.

adafruit_support_bill
 
Posts: 73052
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield v2 and solenoid

by leo3linbeck on Tue Sep 23, 2014 8:46 pm

Thanks so much! I did this, and it worked like a charm. Did a 12V pulse for 80ms to get the solenoid moving, and then dropped the voltage down to about 1.5V, and it held the solenoid jes fine. No heat build up, very limited whine.

The only disappointment is not setting the speed to your suggestion of 42, thus not using the answer to every question in the universe. ;-).

Your support is AWESOME and much appreciated. Cheers,

L3

leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Please be positive and constructive with your questions and comments.