Hi guys,
maybe a stupid question - please don't bite
I want to control the optocoupler circuit with a transistor, but there are few other things that messes the whole situation.
If the switch is released:
a) the LED should be turned OFF.
b) the logical state on PD2 should be HIGH.
c) the optocoupler should be connected with ground.
How to achieve the third thing by not spoiling the other two?
Connect the optocoupler like the LED - so long as the total current is below 40mA (lets say 10mA for LED, 20mA for
optocoupler), then it will work as you want.
The transistor isn't necessary for a normal opto coupler which wants 10 to 20mA or so.
If a transistor was wanted then you'd need a PNP transistor doing high-side switching of the opto coupler, but
just driving it direct from the pin seems simpler here.
[edit: doh, what was I thinking, the current flows through the push-button, no need to limit to 40mA, just choose
the right series resistor for 5V and the intended current. (don't try to share it with the LED's series resistor).]