using solenoid with mosfet

Hello guys i am using solenoid with rf540n mosfet but when i apply a current to gate from arduino my solenoid vibrates or some time my solenoid start automatically when gnd of solenoi is connected to src to drain

The IRF540N is not a logic level mosfet. You need a "logic level" mosfet that turns on with the 5V from the Arduino. Do you have a resistor to GND to keep the mosfet off while the Arduino output is not yet set as output ?

Peter_n covered it, I think.

IRF540 is not logic level (though it apparently kinda works well enough on smaller loads at logic levels, hence why ebay is full of IRF520/540 modules). Those are not ideal FETs.

These should all be rated for logic level gate voltage. (ya, just copy/paste into address bar)

http://www.digikey.com/product-search/en?pv606=19&FV=fff40015%2Cfff8007d%2C1c0002%2C1c0003%2C1c0006%2C1c003e%2C1c00c5%2Cefc0005%2Cefc0007%2Cefc0008%2Cefc0009%2Cefc000a%2Cefc000b%2Cefc000c%2Cefc000d%2Cefc000e%2Cefc000f%2Cefc0012%2C142c001f%2C142c002a%2C142c004e%2C142c0051%2C142c0092%2C142c015a%2C142c025a%2C142c0317%2C142c0368%2C142c0472%2C142c047a%2C142c048a%2C142c0490%2C142c049c%2C142c0516%2C142c05e5%2C142c05ef%2C142c0607%2C142c0608%2C142c0613%2C142c0734%2C142c07af%2C142c0912%2C142c095f%2C142c0a1a%2C142c0a6f%2C142c0ae5%2C142c0afd%2C142c0bc0%2C142c0bc1%2C142c1099%2C142c17fd%2C142c1da5%2C142c1da7&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=500

When you say it "vibrates", what do you mean? Is the solonoid doing it's normal movement like you turned it on? Or just moving a little?

When this happens, does the Arduino reset? (try something really simple, like setting the pins, turning on the LED, then waiting 10 seconds, turn off the LED and try to fire solonoid. Or something like that - the idea being simply to make sure the current drawn by the solonoid isn't resetting the Arduino (inductive loads often do that sort of thing if they're on the same power source as the microcontroller).

If you have nothing (or a high-impedance pin) connected to the gate of a MOSFET, that pin will float in response to ambient electromagnetic fields (like any other floating pin). But the voltage on the gate controls the fet, so if the voltage on it floats up, it will turn on. This is generally undesirable - so put a pulldown resistor between gate and ground, to make sure it stays low (and the fet off) when you're not putting a voltage on the gate.

Finally, one does not apply a "current" to the gate of a MOSFET. FETs are voltage controlled, you apply a voltage to the gate. BJT's are current controlled.

DrAzzy: Peter_n covered it, I think.

IRF540 is not logic level (though it apparently kinda works well enough on smaller loads at logic levels, hence why ebay is full of IRF520/540 modules). Those are not ideal FETs.

These should all be rated for logic level gate voltage. (ya, just copy/paste into address bar)

http://www.digikey.com/product-search/en?pv7=62&pv7=3&pv7=197&pv7=2&pv7=6&pv959=5&pv959=7&pv959=8&pv959=9&pv959=10&pv959=11&pv959=13&pv959=14&pv959=12&pv959=18&pv959=15&pv1291=1162&pv1291=2671&pv1291=2789&pv1291=1302&pv1291=1138&pv1291=1844&pv1291=1146&pv1291=1168&pv1291=1180&pv1291=42&pv1291=31&pv1291=1967&pv1291=2813&pv1291=6141&pv1291=1555&pv1291=872&pv1291=81&pv1291=602&pv1291=2399&pv1291=2586&pv1291=146&pv1291=7591&pv1291=7589&pv1291=3008&pv1291=1543&pv1291=791&pv1291=346&pv1291=78&pv1291=3009&pv1291=1509&pv1291=2322&pv1291=1519&pv1291=1544&pv1291=4249&FV=fff40015%2Cfff8007d&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=500

When you say it "vibrates", what do you mean? Is the solonoid doing it's normal movement like you turned it on? Or just moving a little?

When this happens, does the Arduino reset? (try something really simple, like setting the pins, turning on the LED, then waiting 10 seconds, turn off the LED and try to fire solonoid. Or something like that - the idea being simply to make sure the current drawn by the solonoid isn't resetting the Arduino (inductive loads often do that sort of thing if they're on the same power source as the microcontroller).

If you have nothing (or a high-impedance pin) connected to the gate of a MOSFET, that pin will float in response to ambient electromagnetic fields (like any other floating pin). But the voltage on the gate controls the fet, so if the voltage on it floats up, it will turn on. This is generally undesirable - so put a pulldown resistor between gate and ground, to make sure it stays low (and the fet off) when you're not putting a voltage on the gate.

Finally, one does not apply a "current" to the gate of a MOSFET. FETs are voltage controlled, you apply a voltage to the gate. BJT's are current controlled.

my solenoid just moving a little.btw can u tell me simple mosfet that work with logic level i was following this tutorial http://playground.arduino.cc/Learning/SolenoidTutorial and i tried with rf640n also but its seems look like its dead

...btw can u tell me simple mosfet that work with logic level

follow the link DrAzzy gave to you ;)

saifkazi: my solenoid just moving a little.

Please answer the followup question, as it's critical for solving your problem!

When this happens, does the Arduino reset? (try something really simple, like setting the pins, turning on the LED, then waiting 10 seconds, turn off the LED and try to fire solenoid. Or something like that - the idea being simply to make sure the current drawn by the solenoid isn't resetting the Arduino (inductive loads often do that sort of thing if they're on the same power source as the microcontroller).

I provided a link to a digikey catalog. Copy/paste that really really long URL into address bar, and it will present a filtered list of logic level MOSFETs in TO-220 package (nice big through-hole pins, easy to solder to, use in breadboard, or stuff the pins into Dupont jumpers)). Any of those will work to switch a load under control of an Arduino, and any of those where the "Vds" is higher than the supply voltage for the Solenoid, and "Id" is higher than the current the solenoid draws (see it's specs) will work for switching that solenoid.

DrAzzy: Please answer the followup question, as it's critical for solving your problem!

When this happens, does the Arduino reset? (try something really simple, like setting the pins, turning on the LED, then waiting 10 seconds, turn off the LED and try to fire solenoid. Or something like that - the idea being simply to make sure the current drawn by the solenoid isn't resetting the Arduino (inductive loads often do that sort of thing if they're on the same power source as the microcontroller).

I provided a link to a digikey catalog. Copy/paste that really really long URL into address bar, and it will present a filtered list of logic level MOSFETs in TO-220 package (nice big through-hole pins, easy to solder to, use in breadboard, or stuff the pins into Dupont jumpers)). Any of those will work to switch a load under control of an Arduino, and any of those where the "Vds" is higher than the supply voltage for the Solenoid, and "Id" is higher than the current the solenoid draws (see it's specs) will work for switching that solenoid.

yes my arduino got reset . why is that ?

Several possibilities spring to mind:

If you power the solenoid from the same supply then perhaps the solenoid uses more current than the supply can give, so the voltage drops as the relay switches on.

Or you are lacking a freewheel diode across the relay winding, causing damaging voltage spikes into the supply and the MOSFET

Or the load you are switching with the relay is high current and the transients from its switching are generating enough EMI to affect the Arduino (or its effect on the mains supply is causing a brief voltage drop to the Arduino's supply)