using 4n35 optocoupler as a switch
#1
Posted 24 November 2011 - 11:03 AM
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#2
Posted 24 November 2011 - 01:14 PM
#3
Posted 24 November 2011 - 02:05 PM
Thanks for the extensive reply, very helpful. Actually it looks like I don't even need an optocoupler after all.
I thought it'd do for a simple low current switch. Well, nothing is obvious in electronics :-)
Thus I've ripped off from an old circuit board a NPN 8050 transistor. From the datashet it looks like it should work.
Now, here is my new layout.
Netduino pin 7 through 470 resistor to base.
Netduino 3.3V to emiter
8050 collector to C328R.
If I omit C328R (for testing) and measure the voltage between collector and GND I get ~5.5V (on) and ~3.6V (off). I'd expect something like 3.3V and 0V.
Any idea where does 5.5V come from? I'd test with camera but with these voltages I am cautios
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#4
Posted 24 November 2011 - 02:44 PM
Even without opto, you need two transistors (NPN+PNP). Using the opto, just the PNP.
Take a look at the NPN symbol: the arrow is directed outgoing the emitter. The arrow indicates the current flow, thus you can't connect the emitter of a NPN to a positive source: it won't work.
You must follow the above instructions.
If you don't like the transistors, you may solve your problem with a trick, unless the camera requires many current.
You can pick a 74HC04: it's a 6-NOT gates. Drive *ONE* NOT using the Netduino port, then connect all the remaining 5 NOTs in parallel, as cascade of the first one.
Supply your camera with the super-NOT...
Cheers
#5
Posted 24 November 2011 - 03:38 PM
Nope!
Even without opto, you need two transistors (NPN+PNP). Using the opto, just the PNP.
OK. I'll go with an opto + PNP.
Take a look at the NPN symbol: the arrow is directed outgoing the emitter. The arrow indicates the current flow, thus you can't connect the emitter of a NPN to a positive source: it won't work.
You must follow the above instructions.
Right, my bad. Can't I just switch the pin where camera is attached to? I mean can't I use NPN and connect camera to the emitter and voltage to the collector?
In other words, aren't NPN and PNP the same, taken granted that you switch C and E?
If you don't like the transistors, you may solve your problem with a trick, unless the camera requires many current.
You can pick a 74HC04: it's a 6-NOT gates. Drive *ONE* NOT using the Netduino port, then connect all the remaining 5 NOTs in parallel, as cascade of the first one.
Supply your camera with the super-NOT...
LOL. I'll take the easiest route I guess.
I made a Fritzing sketch based on your suggestion. Two questions:
- is it correct? (white is Pin 7, black is GND and red is 3.3V)
- can I use NPN instead of PNP and just switch C and E?
Attached Files
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#6
Posted 24 November 2011 - 03:48 PM
Nope!
Even without opto, you need two transistors (NPN+PNP). Using the opto, just the PNP.
Can you clarify one more thing for me. As I browsed around I mostly see using one transistor for the switch functionality,
i.e.
Sample switch
Cheers
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#7
Posted 24 November 2011 - 04:11 PM
Good point the article: there are many useful images. This one for example...
The Netduino output will drive the "High Active Switch" pin.
Now, image the PNP (right) base ("Low Active Switch" pin) to the NPN (left) collector lead.
Also, substitute the left-side LED+RC, with your camera.
Finally, we agree on Vcc=+3.3V.
Oh, well...
=== Netduino out: OFF ===
there's no voltage, thus no current flowing through the NPN base. The NPN is off, thus no current flowing through its C-E leads. Since you have a opto-transistor, the missing light on the led stops any C-E current, as stated.
Now, have a look at the PNP E-B route: why the hell the current should flow from the PNP E (+3.3V), through the B, then RB, then RC? It's much like a water pipe: no fall, no flow...
Thus, the PNP is also off, and no current are flowing through the E-C route of the PNP.
Your camera is unpowered.
=== Netduino out: ON ===
There's voltage across the NPN RB route, thus current through B-E. That current will be enough to "close" the NPN, thus C-E are almost the same point (0.1-0.2V).
This time, the current may flow from the PNP E, thru B, thru RB, thru the closed NPN.
The PNP is also closed, and similarly the E-C leads are nearly the same point.
On the PNP C lead there's a voltage very close to 3.3V, thus...
...your camera is powered!
Hope now it's cleared!
Cheers
#8
Posted 24 November 2011 - 09:38 PM
Also, substitute the left-side LED+RC, with your camera.
You mean on the right, since I am attaching camera to PNP's collector?
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#9
Posted 25 November 2011 - 04:36 AM
Yes.You mean on the right, since I am attaching camera to PNP's collector?
Anyway, you should test how much current your camera requires. Probably won't be an issue, but maybe the resistor value should be adjusted.
Cheers
#10
Posted 25 November 2011 - 07:35 AM
Yes.
Anyway, you should test how much current your camera requires. Probably won't be an issue, but maybe the resistor value should be adjusted.
Cheers
Camera specs say it requires 60mA. I guess that shouldn't be a problem.
If I understand correctly dual transistor scheme is required to avoid the voltage drop when a single transistor is used?
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#11
Posted 25 November 2011 - 08:13 AM
Okay, about the current.Camera specs say it requires 60mA. I guess that shouldn't be a problem.
If I understand correctly dual transistor scheme is required to avoid the voltage drop when a single transistor is used?
Let's suppose the (PNP) transistor's current gain (called "hFE") at least 100. It means we must flow through its base (via E) a current *greater* than:
Ib > Ic / hFE = 60mA / 100 = 600uA
Now, when the NPN is closed, the PNP base current is flowing from Vcc (PNP E), thru PNP B, thru RB, thru NPN (being much like a short).
So, you have a small voltage drop on PNP E-B (about 0.7V), but all the remaining voltage is across RB...
Also:
RB = (Vcc-Veb) / Ib = (3.3-0.7) / 600u = 4.3K
Thus, the PNP RB resistor must be *less than* 4.3K.
As you may see, the suggestion at-first-glance I gave you yesterday was partially incorrect. However, the above calculation is pessimistic, thus you may use a normal 4.7K resistor.
Two stages...
Your primary goal is to amplify the current, without reversing the polarity of the output, that is when the Netduino output goes low, your appliance should be unpowered. Vice versa, when the output goes high, the camera should be 3.3V powered.
The "common-emitter" pattern amplifies the available current, without any voltage attenuation. BTW, it amplifies the voltage as well. The counterpart of this circuit is that acts like a NOT-gate, thus you must use a couple of these stages to revert the polarity.
Anyway, the double stage is not just because the polarity.
You can't power your camera through a resistor, because it would drop the voltage, proportionally to the current flowing thru. The "well-done" switch is on the "hot" supply (+), as shown here for instance.
You may *avoid* the first (NPN) stage (in your case the 4n35), when ALL the followings match:
- you accept to drive your appliance using a negative logic (NOT'ed);
- the Vcc (PNP emitter) is tied at the same supply of your driving logic (i.e. Netduino port);
- the PNP current amplification is enough (see above).
Cheers
#12
Posted 25 November 2011 - 08:58 AM
You may *avoid* the first (NPN) stage (in your case the 4n35), when ALL the followings match:
1. you accept to drive your appliance using a negative logic (NOT'ed);
2. ]the Vcc (PNP emitter) is tied at the same supply of your driving logic (i.e. Netduino port);
3. the PNP current amplification is enough (see above).
First, let me tell you, that your help (and patience ) is greatly appreciated.
1. I don't care that much. NOT is fine by me if it makes things easier.
2. I am using a 3.3V pin from Netduino to power the camera. I assume this is OK.
3. Pin 7 is capable (per specs) of 16mA. Camera is supposed to use max 60mA. 8550 Hfe min is 85, that makes plenty of current, correct?
I guess I don't even need that additional resistor from Vcc to Pin 7 (the one that makes sure that there is no current flowing when off).
4. I've calculated Rb as (3.3V - 0.92) / (60mA / 85) = 3.371K. AFAIK it can be a lower value, thus 1K will still work (but perhaps use more current than required). Or it can be a slightly value, because the calculation is worst case scenario. So, the higher the value less current is used but there is no problem if more current is used (apart from draining the battery sooner).
So, I've attached another sketch, this time using a single PNP. Rb is put as 4.7K but I can use 1K just fine.
Attached Files
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#13
Posted 25 November 2011 - 09:24 AM
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
#14
Posted 25 November 2011 - 12:32 PM
#15
Posted 25 November 2011 - 01:13 PM
Miha Markic, Microsoft MVP C#
Righthand .net consulting and software development
http://blog.rthand.com/
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users