Reading the output of a transistor

Hello,

I have a device that has the following output stage:

I am not very familiar with transistors. I'm not sure how I would wire this up on the Arduino side.

The C and E of each optocoupler is exposed for me to detect when the base has activated.
I thought of doing a common emitter with INPUT_PULLUP (like the below) but it doesn't appear to be working.

Should I instead be aiming for something like
or

I'm not sure what pull resistor values I should be using, or if the value matters.

I am using an Arduino Micro.
Any advice would be greatly appreciated. Thank you.

The lower left, I think. Emitter to ground, collector to an input with the internal pullup enabled (pinMode(inputPin, INPUT_PULLUP). No external resistor required. Input will be LOW when the LED in the opto-isolator is on (lit) and Vcc when LED is off (dark).

I thought of doing a common emitter with INPUT_PULLUP (like the below) but it doesn't appear to be working.

That is right, if it is not working you have not wired it like you think you have. Maybe a bad connection,

Okay great. Thanks all. I thought it should have worked. Will need to check in more detail to see what's going wrong.
Is there some basic diagnosing I can do with the C and E connections? Like if I test resistance with a multimeter, it should react shouldn't it?

Thanks again.

clam-:
Is there some basic diagnosing I can do with the C and E connections? Like if I test resistance with a multimeter, it should react shouldn’t it?

Yes:

  • If you can access the “A” and “K” pins on the Opto [unclear from the diagram], then using a Multimeter, measure the voltage across the “A” and “K” pins. There are two conditions to test for:
  • Current flowing - to turn the inner LED “ON”.
  • No current flowing - to turn the inner LED “OFF”
    When current is flowing, the voltage should be around 0.95 to 1.2V . When the current isn’t flowing, the voltage should be around 0.
    If you see a voltage that is lower than 0.95, then, consider that there might not be enough current to properly light up the internal LED. The best test would be to actually measure this current, but that requires a break in the circuit, and if this is on a PCB, then that might be difficult. If this is a prototype, with wires that can easily be lifted, then measure this current, and note it for later.
  • Set the meter to Diode test or Continuity [if your meter doesn’t have any of these settings, then set it to Resistance/200 and be sure to do this test twice, once with the probes one way, and again with the probes reversed – unless you happen to know the polarity of your probes when the meter is set to Resistance]. Then, with the output of the Opto disconnected, with the negative probe to the ‘E’ pin, and the positive probe to the ‘C’ pin, see what reading you get when you apply current to the inner LED [i.e. the “A” and “K” pins]. If it’s working, and if you’re using the Diode tester setting, you will see a voltage of around 0.4 (might be lower – 0.4 is the Max condition)
    – otherwise you will get a continuity reading. It might not cause the beeper to sound, but you will see numbers – when I tried this, I saw anything from around 200 to around 90, but your experience might be different – as long as it starts to show numbers].
  • With the output of the Opto disconnected from the Arduino, the voltage at the Arduino pin should be at or near 5V. If it isn’t, then the pin is either bad, or it isn’t configured properly [see #5, below].
  • If you were able to measure the current going through the inner LED, then, with the Opto output connected to the Arduino, measure the current coming out of the Collector [i.e. the “C” pin]. The current at the Collector should be at one half [or less] of the current at the Input of the Opto [this device has a minimum CTR of 50%]. If this current ratio is not Iout/Iin <= 0.5, then you will need to increase the current going into the Opto at it’s input. In fact, the current should be set for the worst case condition at the input of the Arduino. The worst case is a 20k pull-up resistance, which would cause around (5V-0.4V)/20k = 230µA at the Opto output [the 0.4V value is the Max VCE(sat) of the Opto’s output transistor]. Which means, the current at the input [the current driving the internal LED] should be at least 230uA/[50%/100] = 460µA
  • With the output of the Opto connected to the Arduino, the voltage at the Arduino pin should toggle between around 0 to ~5V, when the current is applied and removed from the input of the Opto. If it doesn’t, then something is wrong with the Opto, or the Arduino pin is either bad, or not configured properly [See code, below]
#define OPTO_READ_PIN 6  // Or whatever number it actually is.

const bool OPTO_OUT_HIGH = true;
const bool OPTO_OUT_LOW  = false;
 
bool optoState;

void setup() {
  pinMode(OPTO_READ_PIN, INPUT_PULLUP);
  delay(1);  // Give this transition time to "settle"
  // Get the initial state of the Opto-isolator output
  optoState = digitalRead(OPTO_READ_PIN);
}

void loop() {
  // Read the current state of the Opto-isolator output
  optoState = (bool)digitalRead(OPTO_READ_PIN);

  // Make productive use of this value. [This could be used as a nice little test!]
  if (OPTO_OUT_HIGH == optoState) {
    // Light the onboard LED if the Opto output is High
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else
  {
    // Turn the onboard LED OFF, if the Opto output is Low
    digitalWrite(LED_BUILTIN, LOW);
  }
}

ReverseEMF:
Yes:

Thank you so much for the detailed information. That helps immensely.

  • Voltage across A and K, about 1.1V. Seems good.
  • Diode Multimeter Test voltage across E and C, 0.12 seems low, but it is firing
  • Voltage at Arduino pin is 4.86, seems okay
  • Current inline between Emitter - GND is 137uA, seems like it should be okay
  • Measuring the voltage of the Arduino pin between GND, is measuring 74mV when optocoupler is active, 4.98V when inactive. built-in LED is continuously active, but when printing the state of optoState, it appears to change between 0 and 1 appropriately.

So it looks like it's now operating correctly. I'm using an Arduino Uno at the moment to perform these tests. Maybe I did something wrong before, or maybe it was my previous Arduino.
Not sure why the built in LED is not changing state, but so long as the logic is detected that's all that matters for now.

Thanks so much for your help.

Hi,
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

Not sure why the built in LED is not changing state, but so long as the logic is detected that's all that matters for now.

Can you post a copy of your code please?

Thanks.. Tom.. :slight_smile:

clam-:
Thank you so much for the detailed information. That helps immensely.

  • Voltage across A and K, about 1.1V. Seems good.
  • Diode Multimeter Test voltage across E and C, 0.12 seems low, but it is firing
  • Voltage at Arduino pin is 4.86, seems okay
  • Current inline between Emitter - GND is 137uA, seems like it should be okay
  • Measuring the voltage of the Arduino pin between GND, is measuring 74mV when optocoupler is active, 4.98V when inactive. built-in LED is continuously active, but when printing the state of optoState, it appears to change between 0 and 1 appropriately.

So it looks like it's now operating correctly. I'm using an Arduino Uno at the moment to perform these tests. Maybe I did something wrong before, or maybe it was my previous Arduino.
Not sure why the built in LED is not changing state, but so long as the logic is detected that's all that matters for now.

Thanks so much for your help.

Cool! Glad to hear it's working!!
A couple (or three) of notes:

  • 0.12V on the Collector-Emitter is not low, it's great! You want this voltage to be as low as possible :wink:
  • What makes you think the built in LED is not changing state? Clearly it is, if you're reading a state change at the output of the Opto-coupler.