Driving a DC motor with a TIP120 controlled by Optocoupler 4N35 to Arduino PWM

Hi!
I have a question about how to correctly wire this situation: I would like to drive a DC motor via a TIP120 via an optocoupler connected to my Arduino. I want to separate the motor circuit from the Arduino part, hence the optocoupler. I am doing this all for exercise and learning to deal with the different parts.
I already successfully hooked up the motor to an arduino via PWM pin and TIP120 (after a tutorial on instructables.com) and now I would like to know how to best do a circuit separation.
My problem is that I know from the data sheet that the 4N35 can tolerate more than 30V but no more than 100mA sustained current. I would like to know how to calculate the resistance in front of the 4N35 so that it can control the TIP120 without getting damaged. I attached a sketch of my intended circuit and I am well aware, that the circuit could be wrong and it is not possible to connect it like that. It is my first idea on how to connect the devices.
Can someone tell me if the circuit below will work as intended and if yes how to properly secure the 4N35?
The DC motor will either be a PC fan or a simple DC motor.
I've read about other circuits that use a 4N35 connected to a relay switching AC and, yes I could probably also use a relay to switch DC but I would like to know if I can do without a relay and if so how.
Cheers,
VR

P.S.: I am pretty new to electronics in general and Arduino, so please be kind ;).

Ohms Law
E = I x R ==> R= E/I==> (12-0.9)/0.075=148 =approx. 150 ohms (4N35 Collector /TIP120-Base Resistor)
E= I x R ===> R =E/I===> (5-1.2)/0.025=152= approx. 150 ohm (4N35 Led resistor)

TIP120 is a Darlington, so it has heaps of current gain: hFE >= 1000 says the data sheet. It can also survive at most 5A of collector current, which means that you don't need much more than 5mA (5A/1000) into the base to drive the full load current.

If you want to drive a big load (near the full 5A rating), budget for maybe 10mA base current, but if your load is smaller (well under 1A) then you could happily use about 2mA of base current to saturate (fully turn on, i.e. have minimal voltage drop across) the TIP120. The base current is the number you need to choose in order to select the base resistor for the TIP120. Say you have a 12V 1A load, you might choose 5mA base current; don't forget to take into account the voltage drops in the optocoupler and TIP120:

R = (Vload - (Vbe_TIP120 + Vce_opto)) / Ib = (12 - (2.5 + 0.3))/0.005 = 1840 => use 1k5 or 1k8.

Now you need to select the LED resistance between the arduino and opto. The 4N35 has an optical current transfer ratio of about 1 (see Figure 6 in the datasheet) so we need AT LEAST 5mA through the LED in order to get 5mA through the optotransistor and saturate it. In practise you want about twice as much to account for manufacturing variation and ensure that the optotransistor is properly saturated, so aim for about 10mA if you're planning on 5mA into in the TIP120's base.

R = (Vcc - Vf_opto) / Iopto = (5-1.5)/0.01 = 350 => use 330R.

An AVR can source 40mA per pin, so this is quite OK; some other micros cannot.

Hi and thanks for your replies!
@polyglot: Thanks a lot, now I know better which values to look for in the data sheets (esp. where to find the voltage drops) and how to calculate the correct resistances. As a beginner, it is hard to know which are the correct values in the data sheets to base the calculation on and I still have to learn how and when to use the R=U*I law to calculate the resistances.
I am still puzzled as to which part defines the resistance in a circuit and how. From what I understand, in this case we use a resistance to reduce the current that goes to the opto but in another example (a voltage divider) the resistance changes the voltage. Doesn't the resistance in front of the opto also reduce the voltage going to it (not talking about the 'voltage drop' in the components themselves - from what I understand many components have some kind of voltage drop like diodes, transistors etc.)? So it might seem a very very stupid question: a resistance can control voltage and amperage?

Sorry, it's textbook time. Get an intro to circuit analysis book and read up about how the sum of currents into a node/net is zero and the sum of voltages around a loop is zero. Those two rules (applied to every node and every cycle) in conjunction with individual device behaviors will give you a bunch of simultaneous equations to solve that will tell you how a whole circuit behaves.

Yes, an R in series with a diode controls the current because the voltage across the diode while conducting is basically constant. Same goes for collector current if the transistor is saturated.

When you make a voltage divider and assume that no current leaves the junction of the two resistors, you're saying that the currents through the two resistors is equal and therefore their voltage ratio matches their resistance ratio. That current will be defined by the sum of the resistances and the total input voltage. So the resistors together define the current and each resistor defines the voltage across itself due to that current.

The voltage divider thing like that doesn't happen (much) with a diode because the voltage/current curve of the diode is so nonlinear; changing the current with the resistor does practically nothing to the diode voltage, therefore the resistor's voltage is also near constant too.

Hey, thanks for pointing me to 'circuit analysis' and the two laws (Kirchhoff's circuit laws as I now found out ;)). I guess I'll have to spend some time understanding these laws and how different parts react differently (I read about ohmic / linear and non-ohmic / non-linear devices). And thanks again for your explanations!

To follow up on your explanations:
I don't understand the following:

an R in series with a diode controls the current because the voltage across the diode while conducting is basically constant. Same goes for collector current if the transistor is saturated.

From what I understand for example about LEDs, you use a resistor to 'reduce the voltage' going to a LED. So in your example, if I understand correctly, the R in series would result in a dropped voltage before the diode and current across the diode would remain the same and a voltage drop would happen in the diode (because of how it is built).

i.e. (+)----Resistor->(voltage drop)----Diode->(voltage drop)-----(-)
What happens to the currents at each of these steps? Do they drop 'in proportion to the resistance' or do they simply stay the same?

From Kirchhoffs current law's perspective: since no current leaves the circuit (there are no nodes to other parts of the circuit) the current stays the same and only the voltage changes? As you can see, I am still very puzzled but I am learning :wink:

google ohm's law.
Once you start applying that to everything you see then it will make sense, especially the previous post about the transistor in saturation and led forward voltage drop...

You're overthinking it.
You have a source voltage, that can supply all the current needed. Call it Vs. Let's say its 5V.

You have an LED that turns on when its forward voltage Vf is reached. Vs > Vf or the LED won't light. Let's say Vf is 2.5V, typical for a Red LED.

I see a transistor was mentioned, lets say NPN, so drive current into the base to allow current flow from Collector to Emitter - in this case the Emitter will be connected to Gnd.
When turned full on, i.e. saturated, and current is flowing, the transistor will have a voltage from Collector to Emitter, Vce. Let's say that is 0.5V.

So wire it up: +5 to LED anode, cathode to resistor, other side of resistor to transistor Collector, and Emitter to Gnd.
Now you have a path from +5 to Gnd so current can flow.

Now we do a little math.
Vs = Vf + Vr + Vce, or the total voltage across the 3 components, LED-Resistor-Transistor.
Throw in Ohms Law: Voltage = Current x Resistance, or V=IR. The same current will flow thru all 3 parts - it has no place else to go. So we can sub in IR for Vr.
Vs = Vf + IR + Vce, and rearranging:
Vs - Vf - Vce = IR
If you want I to = 20mA, then we can solve for R:
(Vs - Vf - Vce)/I = R
(5V - 2.5V - 0.5V)/.02 = 100 ohm

Make more sense now?
You should get a copy of my book.

Can look at the NPN base to emitter the same way, that is typically 1 diode voltage drop.
Vs = arduino output
Vbe= 0.7V
Solve for 20mA to make the transistor turn fully on and saturate - check your transistor data sheet to see what it really is.
(Vs - Vbe)/Ib = R,
(5V - 0.7V)/.02 = 215 ohm

Good stuff. This post should be required reading for all Newbies

Or my book, covers a lot of basic stuff in more detail.

Well then that should be required reading and you gave administer the forum certification tests....

There's an interesting write up on how much heat gets dissipated...

2A load --> 2.0W
6A load --> 9.6W

http://forums.parallax.com/showthread.php/71139-Darlington-Transistor-vs.-MOSFET

Might need a heatsink, or a revised circuit using a logic level mosfet.

EDIT (more test data):
Collector voltage (drop from collector to emitter) = .774 V
Voltage across load resistor = 13.0 V
Current though load and transistor = 1.33 A
Power delivered to load resistor = 17.3 W
Power turned to heat in the transistor = 1.03 W
TIP120 Temperature = 191 deg F
Temperature rise over ambient = 120 deg F

Logic Leve, Low Rds, N-channel MOSFET is always a good choice for sinking current thru motors.
The diode should be across the motor too, not the transistor.

5mOhm MOSFET, 6A current. P = I^2 * R = 180mW

CrossRoads, that MOSFET is at the top of my list (less than 20 cents ea /1000) and runs cool. However, last winter, with that "polar vortex" thing going on, I was really starting to like the TIP120.

:slight_smile: Got me LOL

Voltagerunner:
To follow up on your explanations:
I don't understand the following:

an R in series with a diode controls the current because the voltage across the diode while conducting is basically constant. Same goes for collector current if the transistor is saturated.

From what I understand for example about LEDs, you use a resistor to 'reduce the voltage' going to a LED. So in your example, if I understand correctly, the R in series would result in a dropped voltage before the diode and current across the diode would remain the same and a voltage drop would happen in the diode (because of how it is built).

i.e. (+)----Resistor->(voltage drop)----Diode->(voltage drop)-----(-)
What happens to the currents at each of these steps? Do they drop 'in proportion to the resistance' or do they simply stay the same?

From Kirchhoffs current law's perspective: since no current leaves the circuit (there are no nodes to other parts of the circuit) the current stays the same and only the voltage changes? As you can see, I am still very puzzled but I am learning :wink:

An R in series with an LED does not reduce the voltage across it, it controls the current. LEDs are not resistors, so ohms law does not apply to them, ohms law applies only to resistors. You can Google the voltage/current relationship of a diode and it's interesting but for the purpose of designing a simple circuit, you just consider the diode to have a fixed forward voltage.

The voltage across the resistor is the supply voltage less the diode forward voltage, so you use ohms law the calculate the resistor current. Kirchoff's current law tells you that the resistor current and the LED current are identical (because no other currents enter/leave the R/diode connection), so that means you have good control over the diode current.

If you connect a diode to a pure voltage source, you will get "infinite" current through it until it fails (in milliseconds). Try it sometime with a red LED and a car battery (which can source lot of current), but wear goggles because some LEDs eexplodexplode.

i.e. (+)----Resistor->(voltage drop)----Diode->(voltage drop)-----(-)
What happens to the currents at each of these steps? Do they drop 'in proportion to the resistance' or do they simply stay the same?

No current change in a series circuit.

Analogy (water pipe): Resistor = Constriction (kink, shut-off valve, reducer), Diode = One way valve
i.e. (+)----Constriction->(pressure drop)----One way valve->(pressure drop)-----(-)
No current change in a series pipe.