Go Down

Topic: simple MOSFET circuit to drive solenoid (Read 2454 times) previous topic - next topic

scary

Mar 22, 2012, 07:48 am Last Edit: Mar 22, 2012, 07:57 am by scary Reason: 1
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.

Code: [Select]
// 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
fear my badger

ea123

#1
Mar 22, 2012, 12:24 pm Last Edit: Mar 22, 2012, 02:50 pm by ea123 Reason: 1
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.

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

retrolefty


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

scary

#4
Mar 22, 2012, 11:42 pm Last Edit: Mar 22, 2012, 11:52 pm by scary Reason: 1
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.
fear my badger

MarkT

And you have a flyback diode across the solenoid to prevent it frying everything else in the circuit?
[ I won't respond to messages, use the forum please ]

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

scary


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!  :smiley-mr-green: XD :smiley-mr-green: XD
fear my badger

Go Up