Arduino Forum

Using Arduino => General Electronics => Topic started by: Terraviper-5 on Oct 28, 2012, 06:38 pm

Title: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Oct 28, 2012, 06:38 pm
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: https://www.dropbox.com/s/s9jxmo9yb9ae98r/test%20sketches_bb.png

Datasheets:
https://www.dropbox.com/s/3osm1rfnk05ezbn/irlb8721pbf.pdf
https://www.dropbox.com/s/1q9g79o092lpf1b/LTV-8x6.pdf
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Oct 28, 2012, 06:48 pm
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Oct 28, 2012, 07:26 pm
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?


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 (http://www.mikrocontroller.net/attachment/61816/opto.gif)
But I dont understand how optocoupler will survive the high voltage.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: runaway_pancake on Oct 28, 2012, 08:02 pm
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
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Oct 28, 2012, 08:12 pm
Oh my, I didnt know that optocoupler is going to complicate things so much.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Oct 28, 2012, 08:13 pm
Put the opto-coupler where R3 is, and parallel it with a zener (or a Esaki diode).

Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: runaway_pancake on Oct 28, 2012, 08:16 pm
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Oct 28, 2012, 08:18 pm
Quote
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?

Quote
But how come it worked for led?

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

Quote
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.

Quote
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Oct 28, 2012, 08:33 pm

Quote
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?

Quote
But how come it worked for led?

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

Quote
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.

Quote
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: jwatte on Oct 28, 2012, 09:45 pm
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

Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Oct 28, 2012, 11:53 pm

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:
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




Thank you for explanation. The optocoupler has collector and emitter, so it must be the BJT type.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Oct 29, 2012, 12:29 am
Quote
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: jwatte on Oct 29, 2012, 04:01 am

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 :-)
If the opto-coupler can't take the voltage, a Zener and a resistor can fix that in a pinch.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Oct 29, 2012, 09:12 am
Quote
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Oct 29, 2012, 12:27 pm
Quote
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).
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Oct 29, 2012, 01:08 pm
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Oct 29, 2012, 01:31 pm
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 15, 2012, 09:10 pm
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:
(http://shrani.si/f/h/Hu/4lXjCcWK/graphic.png)

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!
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Dec 15, 2012, 09:31 pm
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.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 15, 2012, 11:23 pm

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.

Quote

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.

Quote

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?
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Dec 16, 2012, 12:15 am
Quote
But I still got problems:


I think you may save a lot of time / money by buying a ready-made board.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 16, 2012, 12:18 am

Quote
But I still got problems:


I think you may save a lot of time / money by buying a ready-made board.



But then I wouldn't learn anything :\ And I already bought all the components :( True though, this thing is taking far too long.
I successfully made it without the optos, im having trouble now when Im trying to add them with a separate power supply since 24 V is too much for the FET's (which have max 20V).
A pre-made boards like Arduino Motor Shield R3 usually have only two outputs, and I need three. If I bought two of these, it would cost me 45 € + shipping, while these components cost me 10 € max. Sure I could probably find one with more outputs, but shipping would still be the problem (as its expensive and I cant get those things in my country).

I cant believe that I have so much trouble assembling such a simple circuit...
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: runaway_pancake on Dec 16, 2012, 12:37 am
Quote
"I cant believe that I have so much trouble assembling such a simple circuit..."


It's always a deceptively easy looking prospect.  (:
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Dec 16, 2012, 12:41 am
Quote
But then I wouldn't learn anything


Sure.

Try this:

from the mcu pin: use a small value resistor (330 or 390 ohm for example) to the opto's anode. its cathode to ground.
on the opto's phototransistor side: a 1k resistor from the 7v source to the phototransistor's collector. Its emitter to ground.
the mosfet: its gate to the phototransistor's collector. Its source to ground. Its drain to the load, parallel'd by a diode (pay attention to the polarity). The other end of the load to the 24v source.

If you cannot make that out or make it work, you should just buy a ready-made board.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dhenry on Dec 16, 2012, 12:43 am
Note: depending on the load and diode used, such an arrangement will have a lot of rf noises. I would put a bead on the mosfet's drain.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Dec 16, 2012, 12:57 am
Quote
Isnt the FET gate same as opto's emitter, since the two are connected?
Do you mean drain by collector?

I mean:-
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.

Quote
Do you mean to the - of the 24V?

Yes.
Quote
But that makes all three optos connected, if one opens all three FETs open.

No. Each FET gate should be connected to the collector. Each emitter should be connected to the same ground.

The circuit as you drew it is just not going to work. Transistors work with current flow, there is no where for the current to flow if you connect the emitter directly to the FET's gate because a FET has such a high input impedance.

Please ignore dhenry he is our resident idiot.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: jwatte on Dec 16, 2012, 02:01 am
Quote
Transistors work with current flow


This is kind-of ambiguous, because every component "works with" current flow of some sort, or it wouldn't be a very useful component. I think I know what you meant, but someone new to electronics might not.

This is basic stuff. I feel it will help anyone who's not yet clear on it and reads this thread:

BJTs (NPN and PNP transistors) work such that the flow through Collector-Emitter is proportional to flow through Base times the amplification factor, with polarity depending on the type. Thus, a BJT transistor needs current flowing through the base to let current flow through the controlled path.

FETs (N-channel and P-channel transistors) work such that flow through Source-Drain is proportional to the charge built up between the gate and the source. The gate is like a capacitor, so while a small amount of current will flow into it to build up that charge, no current will flow through the gate once it's built up, and the MOSFET will still conduct. The only reason to keep the gate voltage on is to replenish leakage current from the gate. This is also why disconnected (floating) MOSFET gates may stay turned on after disconnection, or even spuriously turn on, or off, if there is not enough impedance to either gate voltage or ground.

This is also why it's OK-ish to leave a BJT base floating when you're not driving it -- no current flows, so it will not conduct. But for a FET, that's not true. You must make it so that the gate is ALWAYS connected to either a voltage, or ground. Typically, you do this through a pull-up or pull-down, depending on what you want the default condition to be.

For an opto-coupler that pulls the gate up to turn it on (N-channel FET) you need to also keep a pull-down to ground to the gate, so that the gate turns off when the opto-coupler is not transmitting current. Perhaps a 2 kOhm pull-down will be sufficient, if you're not trying to switch the FETs at too high an on/off frequency.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Dec 16, 2012, 10:04 am
Quote
This is kind-of ambiguous, because every component "works with" current flow

No a FET as you point out works on voltage, there is no current involved in making it work. Leakage current is just that: current that leaks, it is not current that makes it work.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 16, 2012, 02:27 pm

I mean:-
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.


Oh, now I get it (I read the sentence wrong). Do you mean like this?

(http://shrani.si/f/3w/TS/y0685l2/grphc2.png)

Quote

The circuit as you drew it is just not going to work. Transistors work with current flow, there is no where for the current to flow if you connect the emitter directly to the FET's gate because a FET has such a high input impedance.


I though that if I connect a 7.5 V power supply through the optos and to the gates of FETs, the optos will block the path when they are off, and when they are on, they will let the current through and to the gates of the FETs, which will then turn on. At first I though about using the 24V supply for this too, but then I saw the limit on the FETs : +-20V absolute max.
Probably stupid thinking, seemed logical to me though since I know very little about electronics (for now).


The gate is like a capacitor, so while a small amount of current will flow into it to build up that charge, no current will flow through the gate once it's built up, and the MOSFET will still conduct.


Ohh, so thats why the solenoids stayed on (when I reconnected the pwr, ofc) even if I turned off the power and then turned it on again.

Quote

For an opto-coupler that pulls the gate up to turn it on (N-channel FET) you need to also keep a pull-down to ground to the gate, so that the gate turns off when the opto-coupler is not transmitting current. Perhaps a 2 kOhm pull-down will be sufficient, if you're not trying to switch the FETs at too high an on/off frequency.


Im actually not sure if my optos are pullup or pulldown. I didnt know where I can get this information. grumpy_mike mentioned they are pulldown on previous page

No prob about the frequency, they will work slowly :)

So basically, I add a connection between the gate of FET and -ve of 24V source (trough 2kOhm resistor)? Wont that transmit power to all other FETs as well, so when one is open, all are open?


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


That means they are actually inverse of what I need?
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dc42 on Dec 16, 2012, 02:45 pm
Looking at your schematic in reply #7, it shows the mosfet drain and source terminals the wrong way round. But I think you must have wired them up the right way round, otherwise the solenoids would be permanently on.

What you need to do to get that circuit working is:

1. Connect a pulldown resistor between the gate terminal and the source terminal of each mosfet. 470 ohms is about the right value.

2. Do away with R4, you don't need it because you are supplying the optocouplers with only 7.5V and it will prevent enough voltage getting to the mosfets gates (once you have added the pulldown resistors). Connect the collectors of the opto isolators direct to +7.5V instead.

One problem with using opto isolators with mosfets is that opto isolators turn off quite slowly. This in turn means that the mosfets they are connected to turn off slowly, which causes them to dissipate more power. Probably not a problem if you are just turning the solenoids on and off, but a problem if you want to use PWM.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 16, 2012, 04:51 pm

Looking at your schematic in reply #7, it shows the mosfet drain and source terminals the wrong way round. But I think you must have wired them up the right way round, otherwise the solenoids would be permanently on.

What you need to do to get that circuit working is:

1. Connect a pulldown resistor between the gate terminal and the source terminal of each mosfet. 470 ohms is about the right value.

2. Do away with R4, you don't need it because you are supplying the optocouplers with only 7.5V and it will prevent enough voltage getting to the mosfets gates (once you have added the pulldown resistors). Connect the collectors of the opto isolators direct to +7.5V instead.

One problem with using opto isolators with mosfets is that opto isolators turn off quite slowly. This in turn means that the mosfets they are connected to turn off slowly, which causes them to dissipate more power. Probably not a problem if you are just turning the solenoids on and off, but a problem if you want to use PWM.


Like this?

(http://shrani.si/f/23/y/VuT0vmq/gfx3.png)

How slow is that? Because true that I am only turning the solenoids on and off, but they have to be on for like only 80 millis, because I am striking the bells with them and if they are on too long then the bell sound gets dimmed (just remembered that now). I got this working without the optos, but it did not feel right since I read that if diode doesn't react quickly enough, some voltage might leak and slowly destroy Arduino Pins. Id rather see the optos destroyed, since they are so cheap. Even if all is ok, I want the optos just to be on the safe side. On the other hand, what is the alternative to optos, that turns off fast (enough), if I may ask? About power dissipation, they will not be on for longer periods, so that is not a problem for now. I have planned though to make another circuit for swinging the bells, which would use PWM to smooth out the edges when brushed motors reverses direction. The heat problem would start to pester me then, I would guess?
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dc42 on Dec 16, 2012, 04:58 pm
Yes, like that.

The speed at which the opto turns off will be of the order of 100us or better, so fast enough for your application.

The 2.2K resistors connected between the opto isolators and the Arduino pins are too high in value. Try about 220 or 330 ohms instead. Before you connect the solenoids, check that when the Arduino output is HIGH, the mosfet gate voltage rises to around 7V, and drops to zero when the pin goes LOW again.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 16, 2012, 08:02 pm
Wired up as you said, tested without Arduino (from 5V AC-DC adaptor), and it worked. Further testing will follow :D Thank you, sir! Will have to measure current at FET base, as you said, tomorrow.
What I still dont understand is how doesnt power from one optocoupler go through the pulldown resistor onto negative lead and then leak in on other pulldown resistor and activate the other FET.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Dec 16, 2012, 08:20 pm
Quote
What I still dont understand is how doesnt power from one optocoupler go through the pulldown resistor onto negative lead and then leak in on other pulldown resistor and activate the other FET.

Because once the current is at the negative lead it is home, it won't go anywhere else but into the battery. This is because it can only flow where there is a voltage difference to drive it.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: jwatte on Dec 16, 2012, 08:31 pm


I mean:-
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.


Oh, now I get it (I read the sentence wrong). Do you mean like this?


Not at all like that. You are grounding your gates; there is no chance those FETs will turn on.

Also, there is no such thing as a "collector" of a FET. There are collectors on BJTs, and on phototransistors.

Each of the FET gates should have a resistor going to ground, and the phototransistor going to control voltage. That means that, with no photo action, the gates are pulled to the ground, and the FETs are not conducting. When the phototransistor is conducting, there will be voltage pulled up to positive. Exactly how much depends on the resistance of the phototransistor and of the pull-down resistor. I would try a 1 kOhm pull-down and see how that goes. As long as you don't drive these guys at PWM rates (just on/off,) that'll probably be fine.

Edit: I see on the next page you actually got it right with the revision.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 16, 2012, 09:24 pm

Not at all like that. You are grounding your gates; there is no chance those FETs will turn on.


Ofcourse, *facepalm*, how could i be so stupid >.<

Quote

Also, there is no such thing as a "collector" of a FET. There are collectors on BJTs, and on phototransistors.


Yes, that's whats been bothering me. I did not know what exactly grumpy_mike meant with collector, so I looked on Wiki and saw that its the drain.

Quote

I would try a 1 kOhm pull-down and see how that goes.


Then the resistors Im currently using could be too low value? I calculated I = 7.5/470 and it comes out around 20 mA.

Quote

As long as you don't drive these guys at PWM rates (just on/off,) that'll probably be fine.


And what could I do to also allow PWM? Cooler or some better component?

This is the latest version: (if anyone will be reading this thread in the future). If any mistakes show up, I will update.

(http://shrani.si/f/3T/l/4eYb0dU7/gfx4.png)

And here is a video: http://www.youtube.com/watch?v=7T6uwoXUbP8&feature=youtu.be
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Dec 17, 2012, 12:54 am
Quote
I did not know what exactly grumpy_mike meant with collector, so I looked on Wiki and saw that its the drain.

Wehe I said the collector I meant the collector. There is only one component with a collector and that is the output of the opto isolator.

If you are determine to miss represent what I said I am out of here.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 17, 2012, 10:27 am

Quote
I did not know what exactly grumpy_mike meant with collector, so I looked on Wiki and saw that its the drain.

Wehe I said the collector I meant the collector. There is only one component with a collector and that is the output of the opto isolator.

If you are determine to miss represent what I said I am out of here.


Sorry Sir, I meant no disrespect, but you said


... and the FET gates should be connected to the collector of the FETs.


and I wasnt sure what the collector was at FETs, so I went on Wiki and saw

Quote

All FETs have source, drain, and gate terminals that correspond roughly to the emitter, collector, and base of BJTs.


so I assumed that collector was the drain. Nothing else. Sorry if I said something wrong. Its quite possible that I only understood the sentence wrong.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: jwatte on Dec 17, 2012, 07:42 pm
Quote
And what could I do to also allow PWM? Cooler or some better component?


The danger with your pull-down resistor being as low as 470 ohm is that the optocoupler may not be able to pull the gate high enough to fully turn on the MOSFET. There are two concerns with driving MOSFETs for high power:
1) Get a high enough gate voltage to drive it all the way on. This is often a voltage that's twice the rated "Vgs threshold" voltage -- 10V is not uncommon. 7.5V can do it for many devices, too.
2) Get enough current to turn it on quickly. You want ideally several amperes for a handful of nanoseconds in the really high-power cases. Working with milliamperes means it will take much longer to turn on the device, which is still often OK, as long as your duty cycle is long (so, no PWM in that case.)

The problem is that the photo transistors aren't high-current drivers. If you want to drive heavy loads with PWM, you want a dedicated MOSFET gate driver circuit, such as the International Rectifier series: http://www.irf.com/product-info/cic/fsgatedriverics.html or ST microelectronics: http://www.digikey.com/product-detail/en/TD351IN/497-4440-5-ND/725331
Note that those drivers, in turn, ONLY allow PWM; they don't work well with prolonged 100% on cycles, because of the way the gate boost capacitor works.
Sadly, most of these chips are going obsolete, because power switching is going all surface mount and integrated controllers now. Something like the FAN7390N would make a nice driver chip, too.

The driver chips can replace both your opto coupler and your pull-down resistor.

Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Dec 17, 2012, 10:52 pm

Quote
And what could I do to also allow PWM? Cooler or some better component?


The danger with your pull-down resistor being as low as 470 ohm is that the optocoupler may not be able to pull the gate high enough to fully turn on the MOSFET. There are two concerns with driving MOSFETs for high power:
1) Get a high enough gate voltage to drive it all the way on. This is often a voltage that's twice the rated "Vgs threshold" voltage -- 10V is not uncommon. 7.5V can do it for many devices, too.
2) Get enough current to turn it on quickly. You want ideally several amperes for a handful of nanoseconds in the really high-power cases. Working with milliamperes means it will take much longer to turn on the device, which is still often OK, as long as your duty cycle is long (so, no PWM in that case.)

The problem is that the photo transistors aren't high-current drivers. If you want to drive heavy loads with PWM, you want a dedicated MOSFET gate driver circuit, such as the International Rectifier series: http://www.irf.com/product-info/cic/fsgatedriverics.html or ST microelectronics: http://www.digikey.com/product-detail/en/TD351IN/497-4440-5-ND/725331
Note that those drivers, in turn, ONLY allow PWM; they don't work well with prolonged 100% on cycles, because of the way the gate boost capacitor works.
Sadly, most of these chips are going obsolete, because power switching is going all surface mount and integrated controllers now. Something like the FAN7390N would make a nice driver chip, too.

The driver chips can replace both your opto coupler and your pull-down resistor.


Thank you for those insights, I will surely consider them next time I'm building something.

I can easily boost the voltage from 7.5 V to 9 V or 12 V.  That would raise current from 16 mA to 19 mA or 25.5 mA, still well within range of 50 mA,

(http://shrani.si/f/2x/lH/1p8rOtsT/53342.png)

which is max. Of course I would have to account for voltage fluctuations from the adaptor, since those loads are very small, but that shouldn't raise the current to more than 32 mA (with those resistors).

Quote

The danger with your pull-down resistor being as low as 470 ohm is that the optocoupler may not be able to pull the gate high enough to fully turn on the MOSFET.


But isn't lower resistor -> more current -> better switching? Please, correct my logic. Or did you mean low current?

Quote

You want ideally several amperes for a handful of nanoseconds in the really high-power cases.


Wow, that's is high. Then again, when I checked the specs I was surprised when I saw

(http://shrani.si/f/3o/HO/3iK8SrnS/untitled.png)

that allowed Gate -> Source current was 62 A.

Quote

Note that those drivers, in turn, ONLY allow PWM; they don't work well with prolonged 100% on cycles, because of the way the gate boost capacitor works.


If drivers cant work 100% on cycles and optocouplers are too slow for PWM, is there any way to have both, PWM and 100% on cycles?
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dc42 on Dec 17, 2012, 11:30 pm
1. How much current do your solenoids take?

2. Which optocoupler are you using?

Depending on the answers, you may be able to use low-frequency PWM (e.g. at the Arduino default frequency of 490Hz) in that circuit as it is, or by changing a few component values.

Other alternatives are:

1. Do away with the opto isolators, if a common ground between the Arduino and the 24V supply is acceptable. You can drive a logic level power mosfets from an Arduino output pin through a 100 ohm resistor. This is OK for low-frequency PWM if the power being switched is not too high.

2. Use a TC4420 or TC4429 mosfet driver between the opto isolator and the mosfet gate. These can provide 6A peak gate current, and work with or without PWM.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: jwatte on Dec 18, 2012, 01:36 am
Quote
that allowed Gate -> Source current was 62 A.


That's allowable Drain -> Source current, with the stipulation that the Gate/Source voltage is 10 V. This tells me that a 5V driver will not "open" the MOSFET fully, and you will see a higher Rdson than the specified value. That being said, if your solenoids are just drawing a few amps, that probably doesn't matter much.

Quote
But isn't lower resistor -> more current -> better switching? Please, correct my logic. Or did you mean low current?


You need both high current AND high voltage, and the high voltage is more important than the high current for large loads, whereas the high current is needed for quickly switching on/off.

Quote
If drivers cant work 100% on cycles and optocouplers are too slow for PWM, is there any way to have both, PWM and 100% on cycles?


There are drivers that can work 100%, as long as they are only used as low-side drivers. Looking at your schematic again, I think that's what you're doing, so I think you're good, as long as the 7.5V can be used as your gate voltage.
The kind of driver I'm talking about can generate a higher gate voltage (even higher than your VDD!) by charging a capacitor, but that capacitor slowly discharges and thus it needs the down-cycle to re-charge.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Feb 08, 2013, 09:18 pm
Okay I have now tested the circuit operation for a month and established that it works. Now I want to move it from a protoboard onto perfboard and since Im going to permanently solder it together, I came across a few things that I *might* be able to improve before doing that.
First, I saw that h-bridges have capacitors on them to smooth out voltage spikes caused by the motor. Its usually 10uF caps. From what I have seen, none of the solenoid driver examples for Arduino I find online have them. Is there any special reason for that or is it left out to leave the example circuit as simple as possible?
Second thing, I want to get rid of the additional power supply (7.5 V) because its very impractial for such a simple circuit to require two adaptors. With Arduino, they need three: 5V, 7.5V and 24V. Here I bump onto a problem: The max gate voltage for FET is +- 20 V (and this goes for most FETs I find in stores), so I cant directly use the 24V power supply for switching. The optoisolators have max collector-emmiter voltage 80, so they dont have a problem with this. What can I do to be able to use the power supply for solenoid also for switching the FET? Voltage regulator? Any ideas? What is usual practice for this kind of things?
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Feb 08, 2013, 09:46 pm
Supply decoupling in the form of capacitors is always a good idea
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html (http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html)

Replace the 7.5V supply with the 24V one and have a separate resistor of 1K going from each opto collector to the +24V. In that way then the opto is turned on the FET only gets a proportion of the 24V determined by 1K and 470R in a potential divider.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dc42 on Feb 08, 2013, 09:48 pm

First, I saw that h-bridges have capacitors on them to smooth out voltage spikes caused by the motor. Its usually 10uF caps. From what I have seen, none of the solenoid driver examples for Arduino I find online have them. Is there any special reason for that or is it left out to leave the example circuit as simple as possible?


If you mean capacitors between the positive supply and ground, then yes, this is a good idea. These capacitors are usually much larger than 10uF, more like 1000uF.


Second thing, I want to get rid of the additional power supply (7.5 V) because its very impractial for such a simple circuit to require two adaptors. With Arduino, they need three: 5V, 7.5V and 24V. Here I bump onto a problem: The max gate voltage for FET is +- 20 V (and this goes for most FETs I find in stores), so I cant directly use the 24V power supply for switching. The optoisolators have max collector-emmiter voltage 80, so they dont have a problem with this. What can I do to be able to use the power supply for solenoid also for switching the FET?


If you are using the schematic you posted earlier (i.e. opto isolators driving the mosfets, with 470 ohm pulldown resistors), then all you need to do is connect 680 ohm resistors in series with each opto isolator output. These, in conjunction with the 470 ohm pulldown resistors, will create voltage dividers that reduce the gate voltage from 24V to about 10V.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Feb 09, 2013, 08:47 pm
Thank you both! Please tell me if I put it right (I omitted the other two instances because I will solder each separately so that if there comes a need to add another solenoid I will just solder up another one):

(http://shrani.si/f/1G/hB/1XyQYxTV/1.png)

Could you please tell me how to calculate the voltage at the gate? I was thinking, if I at any time later for any reason wish to use this driver for, example, 12 V motor, the gate voltage will also drop, yes? To about 5-6 V? This means I can only use 12 - 24 V motors here? How are drivers usually designed so that they can be used for as wide voltage range as possible? (I hope I am not asking too much).
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: dc42 on Feb 09, 2013, 10:30 pm
The 470uF andf 0.1uF capacitors are in the wrong place. They need to be connected directly across the 24V supply (but physically close to the mosfet). Otherwise, the schematic is OK.

Unless you are using fast PWM, the diodes in parallel with the solenoids do not need to be Schottky diodes - ordinary silicon rectifier diodes will do.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Feb 09, 2013, 10:30 pm
You do draw your schematics in a very odd way.
I would connect those capacitors across the supply not the solenoid.

Quote
if I at any time later for any reason wish to use this driver for, example, 12 V motor, the gate voltage will also drop, yes?

Yes.

Quote
How are drivers usually designed so that they can be used for as wide voltage range as possible?

They are more complicated with a regulator giving you that extra voltage source you had in the first place.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Terraviper-5 on Feb 10, 2013, 12:34 am

You do draw your schematics in a very odd way.


Yeah, its about time I read some tutorial on how to make schematics.

Anyways, I have read around a little bit, found out that multiple smaller caps are better than one big.

Also, if I leave the circuit online 24/7, the caps will be charged all the time even if they are only used for small fraction of that time. Will because of that their life expectancy be smaller? Should I add another FET that will block the entire power supply when its not needed? (sorry if the question sounds stupid, Im later planning on building a h-bridge and am accumulating knowledge for later also)

Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: Grumpy_Mike on Feb 10, 2013, 12:42 am
There is nothing wrong with the capacitor values, it is just that you have them in the wrong place.
Title: Re: help connecting Arduino UNO to n-ch MOSFET via Optocoupler
Post by: retrolefty on Feb 10, 2013, 01:45 am


You do draw your schematics in a very odd way.


Yeah, its about time I read some tutorial on how to make schematics.

Anyways, I have read around a little bit, found out that multiple smaller caps are better than one big.

Also, if I leave the circuit online 24/7, the caps will be charged all the time even if they are only used for small fraction of that time. Will because of that their life expectancy be smaller? Should I add another FET that will block the entire power supply when its not needed? (sorry if the question sounds stupid, Im later planning on building a h-bridge and am accumulating knowledge for later also)




That can be the case when the cap is being used to bypass noise to ground for sensitive loads, but your solenoid does not give a hoot about what little extra noise that smaller cap might be bypassing to ground. The big cap is just to have a little extra initial current available to drive the solenoid load on, in case the power supply is not a 'stiff' one. In simple passive loads like a solenoid you don't even require a regulated power supply, just filtered with enough current capacity to handle the solenoid load. But yes move the cap(s) to be across the PS +/-.

Lefty