help connecting Arduino UNO to n-ch MOSFET via Optocoupler

Hi!

I am trying to control a solenoid with Arduino Uno. I want it to go through an optocoupler with darlington driver just in case something goes wrong. Before I try it with solenoid, I wanted to see if everything works with a LED. So I first connected it the same way as in image below, just without the MOSFET (optocoupler acted as transistor, since there isn't so much current) and it worked. Then I tried it with just the MOSFET and without the optocoupler, and again it worked. Then I tried the configuration in the image, and it didnt work. Sometimes the led was on, sometimes off, nothing like Arduino was telling it to do. My guess is that optocoupler doesnt have enough power to turn on the MOSFET, but I really need some help from more experienced users to really identify the problem. Thank you for your time!

Image: Dropbox - Error - Simplify your life

Datasheets:

The transistor in an opto coupler can only pull down, so there is nothing to supply the voltage to the FETs gate.
You can put a pull up resistor on the gate of the FET to the positive supply.
Alternatively you can put the transistor of the opto between the +ve and the gate and pull down the gate to ground.

Please excuse my n00bishness, but wont the power from the supply be too much for the gate of the FET? When using solenoid it will be 15V+. Or will the FET take it?

Grumpy_Mike:
The transistor in an opto coupler can only pull down, so there is nothing to supply the voltage to the FETs gate.

But how come it worked for led? If it pulls down, shouldnt the led then be on when its supposed to be off and off when its supposed to be on?

Edit: Ok, I found this image
But I dont understand how optocoupler will survive the high voltage.

Just wanted to say that's probably going to be OK, but others just looking at it need to know that VG will be about 1/3 of supply: (680?/1680?) * 24V = 9.7V

Oh my, I didnt know that optocoupler is going to complicate things so much.

Put the opto-coupler where R3 is, and parallel it with a zener (or a Esaki diode).

T-5,
You're OK there, I was just doing a little explaining for others that R2 and R3 make a voltage divider when the opto output turns on.

but wont the power from the supply be too much for the gate of the FET?

What does the data sheet say the maximum gate voltage is?

But how come it worked for led?

Because you were pulling current through the transistor not outputting a voltage.

Ok, I found this image
I dont understand how optocoupler will survive the high voltage.

Look at the data sheet for the opto, but 24V is not a very high voltage for a transistor.

Put the opto-coupler where R3 is, and parallel it with a zener (or a Esaki diode).

Don't, our dear henry specializes in trying to confuse beginners, it makes him happy.

Grumpy_Mike:

but wont the power from the supply be too much for the gate of the FET?

What does the data sheet say the maximum gate voltage is?

But how come it worked for led?

Because you were pulling current through the transistor not outputting a voltage.

Ok, I found this image
I dont understand how optocoupler will survive the high voltage.

Look at the data sheet for the opto, but 24V is not a very high voltage for a transistor.

Put the opto-coupler where R3 is, and parallel it with a zener (or a Esaki diode).

Don't, our dear henry specializes in trying to confuse beginners, it makes him happy.

I think its 20V, but I might be looking at a wrong thing.

Oh, that makes sense. Sorry for my beginner stupidities.

It says: Vemittercollector = 6, Vcollectoremmiter = 80 (if again im looking at the right thing). Its says thats absolute maximum.

I have schottky diodes, so Id rather try some other configuration than this anyway.

If it has emitter and collector, it is not a MOSFET, it's a BJT (a k a "70's transistor.")

BJTs let current through between collector and emitter when there is also a current (the right way) through the base. This means that there will always be current flowing through the base in addition to the switched current when it is on. This make it easy to switch them on and off with a single switch -- current flows, transistor on; current interrupted, transistor off.

MOSFETS let the current through one way ("body diode" direction) always, with some body diode resistance. However, when you charge the gate capacitor (meaning apply a voltage and a short spike of current) they will conduct equally well in both directions. When wired with the controlled voltage against the body diode (normal,) this means they are "off" when the gate voltage is low, and "on" when the gate voltage is high. This actually saves power, because there is no "wasted" current through the gate, other than when switching state.

However, this also makes a MOSFET annoying to switch, because you need to actively pull it UP (charge) when turning on, and DOWN (discharge) when turning off. (This is for N-channel; P-channel is approximately inverse.) Thus, a simple make-or-break switch won't work, unless you replace one of the "pull" directions with a resistor. The output of the Arduino is already switched both ways -- it either ties to VCC, or to ground, so it can drive a gate directly. The output of an optocoupler is not, though, hence this confusion.

For a MOSFET, the allowable voltage from source to gate (what controls the built-in gate capacitor) is different from the allowable voltage from source to drain (the controlled voltage.) A typical low-voltage device might allow 20V from source (0-reference) to gate, and 30 volts from source (0-reference) to drain. (IRLB8721 for example -- popular 30V D/S device with 4.5V recommended gate voltage and 20V max G?S voltage) Here's an example data sheet showing those voltages:
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CDEQFjAA&url=http%3A%2F%2Fwww.adafruit.com%2Fdatasheets%2Firlb8721pbf.pdf&ei=IZiNUKaZM8LtiwKghYHADA&usg=AFQjCNGUrxQ2jGVS0ZaY7Mic2FOCkETjEQ

jwatte:
If it has emitter and collector, it is not a MOSFET, it's a BJT (a k a "70's transistor.")

BJTs let current through between collector and emitter when there is also a current (the right way) through the base. This means that there will always be current flowing through the base in addition to the switched current when it is on.

MOSFETS let the current through one way ("body diode" direction) always, with some body diode resistance. However, when you charge the gate capacitor (meaning apply a voltage and a short spike of current) they will conduct equally well in both directions. When wired with the controlled voltage against the body diode (normal,) this means they are "off" when the gate voltage is low, and "on" when the gate voltage is high.

For a MOSFET, the allowable voltage from source to gate (what controls the built-in gate capacitor) is different from the allowable voltage from source to drain (the controlled voltage.) A typical low-voltage device might allow 20V from source (0-reference) to gate, and 30 volts from source (0-reference) to drain. (IRLB8721 for example -- popular 30V D/S device with 4.5V recommended gate voltage and 20V max G?S voltage) Here's an example data sheet showing those voltages:
Redirect Notice

Thank you for explanation. The optocoupler has collector and emitter, so it must be the BJT type.

It says: Vemittercollector = 6, Vcollectoremmiter = 80 (if again im looking at the right thing). Its says thats absolute maximum.

The first bit is the negative voltage limit so the emitter should not be more than 6V above the collector, you only get this if you wire it up the wrong way.
The collector emitter voltage is the maximum you can have so 24V is well within the limit in the circuit you want to use it in.

Terraviper-5:
Thank you for explanation. The optocoupler has collector and emitter, so it must be the BJT type.

Yeah, I don't know of any MOSFET optocouplers (a MOSFET light transistor?) I thought you meant the data sheet for the transistor you're trying to switch. You have to make sure you don't break that device, too :slight_smile:
If the opto-coupler can't take the voltage, a Zener and a resistor can fix that in a pinch.

I don't know of any MOSFET optocouplers

Yes you can get opto couplers with FET outputs as well as couplers with SCR and Triac outputs. Do a search in any major distribuitors.

so it must be the BJT type.

All opticouplers are of bjt type: as a minority carrier device, bjts are a lot more sensitive to light than a majority carrier device (mosfet for example).

You should look at the datasheet for your device.

Generally, the If specification is between 5ma - 20ma - I typically do 10ma to maximize ctr. Your runs at ~20ma, so it is properly done.

The phototransistor side is not. The ctr is generally 50 - 150%, and I typically design for 50%. That means your phototransistor side's Ic is about 10ma - likely lower with earlier opto-couplers. At 10ma, your Vgs, fully on, is about 7v - not bad but not great either.

Outputting on the emitter is not common: it is often done for speed or to reduce ctr. Most of the times, the output is done on the collector - it produces sharper on/off behaviors. If you look at your datasheet, it shows that as well.

I would put the opto-coupler on the bottom and use a zener to protect the gate.

I put this simulation together to get you a comparison between two approaches to switching.

The plot is about power dissipation on the mosfet, switching a 12amp / 24v load.

The emitter output approach dissipates about 14w over the mosfet 50% of the time. The collector approach dissipates 14w for about 2.5% of the time. That means that you can run the mosfet (to220) without heat sink in the 2nd approach but not the 1st approach.

So try not to output on the emitter.

Thank you for explanation.
Sorry it took me so long to answer, I have been very busy and did not have much time for this project. Now I have assembled this:

But I still got problems: To test the circuit before I connect Arduino to it, I connected a 5V power supply where Arduino pins should be. It activated the motors, but when I disconnected, the motors were still on. They were also still on if I disconnected the main power and then reconnected it. Only after disconnecting the MOSFETs from Optocouplers did the solenoids return to off-state. Im probably missing something important that I do not see because Im a newb. I again ask for your help!

PS: I know that I should put separate resistors for each OC, but they will not be all online at the same time.

Thank you!

What a very confusing way to draw a schematic.

The emitters of the optos should be connected to ground, the -ve of your 24V source and the FET gates should be connected to the collector of the FETs.

Grumpy_Mike:
What a very confusing way to draw a schematic.

Sorry, I have made very few schematics and am still learning how to make them better.

The emitters of the optos should be connected to ground

Do you mean to the - of the 24V? But that makes all three optos connected, if one opens all three FETs open.

the -ve of your 24V source and the FET gates should be connected to the collector of the FETs.

Isnt the FET gate same as opto's emitter, since the two are connected?
Do you mean drain by collector?