simple MOSFET circuit to drive solenoid

Hello, I'd really appreciate some advice on this circuit I'm trying to make.

The Ruggeduino is meant to be controlling the MOSFET through pin 8 (blue wire). I have 12V on the rail of the breadboard (black/yellow, bottom right) to drive the solenoid (left, fed by yellow/blue, datasheet attached). The MOSFET datasheet is here. A 47K resistor pulls down the MOSFET's gate pin.

My code is just a proof-of-concept to test the MOSFET and valve but the valve does nothing. It works fine if I connect it straight to 12V.

// set the pin that will control the valve
int ValvePin = 8;

void setup() {
    // set the digital pin as output:
  pinMode(ValvePin, OUTPUT);    
  
  // start the pin on LOW
  digitalWrite(ValvePin, LOW);  
}

void loop(){

digitalWrite(ValvePin, LOW);

delay(5000);

digitalWrite(ValvePin, HIGH);


delay(5000);
}

I can measure voltage switching from the I/O pin but it only gets up to 2.4V at high and won't drop below 0.17V on low. In response the voltage between drain and source pins of the MOSFET switches between 10.4V and 12.1V which is odd as I thought it would be off by default. Also, despite this voltage, the valve still doesn't switch. Its not a particularly heavy current drain so I am broadly stumped for answers here. I have duplicated this problem with a Duemilanove too.

I presume I am doing something stupidly wrong. Can someone throw me a bone?

Thanks,
Scary

225T031 3-way solenoid valve NResearch.pdf (106 KB)

Hi,
I see that your load (the solenoid) is connected between MOSFET source and ground. Usually the N-MOSFET configuration as a switch is done with the load between +12V and the MOSFET drain, with the source pin connected to ground.
Moreover when switching on/off an inductive load you should place a diode in parallel with the load (inverse polarity) to protect the MOSFET from voltage spikes.

You should also havr a ~480 ohm resistor to the gate, you can fry the pin from continously driving the very capacitave gate of the mosfet without the limit resistorresistor, idk if the ruggedduino has it built in or not, i think it has poly fuses which wont protect from that

winner10920:
You should also havr a ~480 ohm resistor to the gate, you can fry the pin from continously driving the very capacitave gate of the mosfet without the limit resistorresistor, idk if the ruggedduino has it built in or not, i think it has poly fuses which wont protect from that

Every I/O pin on a ruggeduino is 'protected' with a series 220 ohm resistor. This will be fine for directly interfacing a N-channel mosfet wired as a low side switch.

Lefty

Hi, thanks for all the replies. I have switched the valve for an LED and the 12V supply for 5V from the Ruggeduino to simplify things. Nothing changed. There is still conductivity between the drain and source pins when there is no voltage to the gate pin. I have now switched the MOSFET for a transistor and it seems to work as intended so I will press on with the transistor. I think the loads should be okay.

I won't forget to add the diode either. Thanks ea123.

And you have a flyback diode across the solenoid to prevent it frying everything else in the circuit?

If it helps I've been messing around with mosfets and solenoids as well, although in a more limited manner.

If it helps the thread is here

MarkT:
And you have a flyback diode across the solenoid to prevent it frying everything else in the circuit?

Hee hee, I do now. I suspect that was my major fail with the MOSFET circuit. Ho hum, application solved for now though. Many thanks to all contributors, you guys saved my bacon once again! :grin: XD :grin: XD