5v Solenoid and Mosfet Drama

Hello everybody,and thanks for your attention.

I am having a terrible time with a 5v solenoid circuit. I am trying this circuit: http://i.stack.imgur.com/p6WtJ.png I am using this solenoid: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Robotics/ZHO-420S.pdf Using this diode: 1N4007 http://www.diodes.com/datasheets/ds28002.pdf This MOSFET: http://www.onsemi.com/pub_link/Collateral/NTD5867NL-D.PDF The resistor is 1k and the gate is connected to a logic output of Arduino. I am using a voltage source of 5V. The solenoid gets stuck in the on (pulled) position if I use the circuit. If I feed it with the source (@ the same 5V) and turn it on and off, the solenoid goes back to its original position without problems. I guess the problem is the mosfet I have chosen but I have no clue on why. It seems like it does not go completly off and therefore some current still activates the solenoid. Any ideas? Best, Diego

Show us your code.

// Per.

dmelladom: The solenoid gets stuck in the on (pulled) position if I use the circuit. Any ideas?

Can't see your picture (at work, "filtered"), but, given that it's staying "on" I wonder whether you have the Gate pulled down [a resistor from Gate to Gnd, 5K to 10K?].

[quote author=Runaway Pancake link=topic=189736.msg1403657#msg1403657 date=1380036192]

Can't see your picture (at work, "filtered"), but, given that it's staying "on" I wonder whether you have the Gate pulled down [a resistor from Gate to Gnd, 5K to 10K?]. [/quote]

OP have a 1K pull-down on the gate-input, so that's 5 mA - shouldn't be a problem.

Although i would recommend putting in between 10 and 100Kohm instead.

It must be a code-problem.

// Per.

Hi! Thanks for your fast answers. Here it is my code:

const int ledPin =  13;      // the number of the LED pin

const int outPin =  0;      // the number of the LED pin

int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 200;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
  pinMode(outPin, OUTPUT);      

void loop()

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   
    if (ledState == LOW)
      ledState = HIGH;
      ledState = LOW;

    digitalWrite(ledPin, ledState);
    digitalWrite(outPin, ledState);

I am using the LED in the board just to mirror the signal.

Sorry for disagree: I feel like it has more to do with the mosfet :S. Is RG too high¿

Again, thanks a lot for your time. Best, Diego

You cannot use Digital 0 & 1 - they are reserved for Serial communication.

Try changing the Digital 2, and try again.

// Per.

The same. After 5 push-pull periods, it gets stuck again :frowning:
Thanks for your tip, using port 0 was a bad idea anyway!

Firstly you need to add a 150 or 220 ohm resistor from the Arduino pin to the gate - don't drive it directly, its a highly capacitive load and it takes the pin current above the abs-max during transients.

A 10k pulldown is good, won't lose too much gate drive voltage - its only purpose is to hold the MOSFET off during Arduino reset.

The diode isn't the best choice, a faster switching diode will clamp inductive transients better, but it still ought to basically work.

You have the MOSFET connected correctly? No loose connections? What's the supply? (note you shouldn't be using the Arduino 5V rail on the solenoid itself, that could cause havoc).

A circuit diagram or photo of the setup would be helpful.

Hi MarkT! Right now I can not upload a picture, but trust me, the MOSFET is properly connected and there is nothing loose :) I am using an external power supply for the solenoid, and I have tried several voltages, from 3.5V to 9V, and it changes nothing. I will try the series resistor for the gate tomorrow and uptdate the thread! Best, Diego

maybe you’ve just wired the mosfet wrong Drain <–> Source : if you connect the drain where source should be … it will be always “on” :wink:

Hi again!
Thanks for your attention. I think I did not explain it correctly: the problem is not that the solenoid is always on: it goes on and off correctly 3 or 4 times and then gets stuck. Every circuit (5 components, indeed) are correctly set.
My feeling is that the MOSFET is not operating in the correct zone, that’s why I asked if the mosfet I am using was a good election or not.
Or that something (I don’t know what) is not discharging properly. Maybe the soleonid is not good enough or maybe the spring in the solenoid is not strong enough, that’s why I attached the datasheet in the first post of the thread.

Again, thanks a lot everybody for your attention and kindness.


and when the solenoid gets stuck, is the Led still blinking ? what happens if you slow down the process (increase interval value) ?

Yep, the LED is still blinking. If I slow down the process, lets say 1 per second (hence 2 seconds cycle) the same happens, but a little later.

Anyway, I need it to run at 250ms per cycle approximately.

Best, Diego

OK, it was just to see what happened ;)

Does the mosfet get hot ? maybe you could try with a lower resistor value and add a series resistor as MarkT suggested. and also a faster diode (MarkT suggested that too ;) )

I am on it right now :) :)

Also I may try using the transistor to turn on-off a higher current, no-logic transistor. I will write back in a couple of hours! Thanks everybody!!!

No improvements. The MOSFET is not hot. I used a 555Ohms (I had nothing smaller in the hundresds). I am using now a source with less max output current and seems to be more stable, but after a while, the same problem happens. :( :(

Are you sure that the solenoid is able to move that fast? You are only turning it on for 0.2 seconds, and off for 0.2 seconds. The flyback diode (which is necessary to protect the mosfet) will slow down the process of turning the solenoid off. This may or may not be significant, depending on the inductance of the solenoid (and other things).

As the solenoid heats up, its resistance will increase and the current it passes will be less. This will make it less effective at pulling in.

I suggest you try increasing the delays to give e.g. 1 second on and 1 second off, and see if that helps.

If the flyback diode is causing the solenoid to release too slowly, you can speed it up by adding a resistor in series with the flyback diode. For example, a resistor equal in value to the resistance of the solenoid will almost halve the time taken for the current to decay - but it will also cause the peak voltage on the mosfet drain to be about double the supply voltage. So check the voltage rating of the mosfet before you try this. There are active circuits you can use to make the current decay faster than a resistor alone will.

Sounds like good tips :) Let me try'em

Best, Diego

No good :( I guess the solenoids are a bit crappy :(

In what way does the solenoid get stuck? Is the voltage of the power supply holding up? What (if anything) do you have the solenoid mechanically connected to?