Open Collector output from sensor : connect to MCU and LED indicator

Thread Starter

kiweered

Joined Dec 13, 2021
28
Hi,

I use a photo sensor as an object detector and the output of this sensor is an open-collector :
1684834416190.png

I need to connect this output to a STM32 GPIO input. I also want it connected to a LED directly on the PCB for debugging and test purposes.
I did this on a breadboard and it works :
1684834884533.png
But basicly I don't understand why, when the open collecter acts as an open switch, you don't have a curent flowing from 3V3 to the MCU and so the LED is lit. What is the current path when the output is off ?
Plus if the the voltage drop of the LED is too high, you migth not be able to detect the High level logic whith GPIO ? I guess the pullup resistor is useless here, maybe internally ?

I also drew this design to invert the output and so the LED is lit when the GPIO reads High level (before it was the opposite) :
1684835211685.png
(The NPN transistor acts as the output of the sensor and is not in the design)
Is it a good design ? Do you have better/easier solutions (with inverted or not output) ?
 

StefanZe

Joined Nov 6, 2019
191
When Q2 is conducting the current for the LED can flow through the Q2 in the LED is lit (MCU GPIO Input is LOW)
When Q2 is off the LED is off and the MCU GPIO Input is HIGH.

Your design to invert the LED signal is ok. The choosen mosfet is a bit of an overkill
 

DickCappels

Joined Aug 21, 2008
10,169
Stefanze wrote:
"What is the current path when the output is off ?"

There is no significant path if the pin on the controller is configured as an input.
 

MisterBill2

Joined Jan 23, 2018
18,461
Hi,

I use a photo sensor as an object detector and the output of this sensor is an open-collector :
View attachment 294775

I need to connect this output to a STM32 GPIO input. I also want it connected to a LED directly on the PCB for debugging and test purposes.
I did this on a breadboard and it works :
View attachment 294777
But basicly I don't understand why, when the open collecter acts as an open switch, you don't have a curent flowing from 3V3 to the MCU and so the LED is lit. What is the current path when the output is off ?
Plus if the the voltage drop of the LED is too high, you migth not be able to detect the High level logic whith GPIO ? I guess the pullup resistor is useless here, maybe internally ?

I also drew this design to invert the output and so the LED is lit when the GPIO reads High level (before it was the opposite) :
View attachment 294781
(The NPN transistor acts as the output of the sensor and is not in the design)
Is it a good design ? Do you have better/easier solutions (with inverted or not output) ?
If the LED is illuminating then there is current flow. Just because it does not show on some documentation does not mean there are no other components involved.
 

AnalogKid

Joined Aug 1, 2013
11,036
The GPIO pin input impedance is very high, like over 100K. When the sensor is off, this impedance forms a 2-resistor voltage divider with R5 in your first schematic. R5 is 1K, so the voltage at the input pin is 3.27 V or more. There is only 0.03 V across the LED, not enough for it to conduct current and emit light.

ak
 

BobaMosfet

Joined Jul 1, 2009
2,113
Understand the concept behind 'open collector'. What that means is that you use a pull-up between V+ and the collector to pull the signal high when transistor open/OFF. The idea being that the transistor is used to GROUND the collector, thus over-riding the pull-up and taking the collector low when the transistor is closed/ON. The amount of current on the collector, then, is determined by the pull-up resistor.
 

ElectricSpidey

Joined Dec 2, 2017
2,774
" I guess the pullup resistor is useless here"

No, because the impedance of an LED is extremely high when not conducting therefore when the transistor is "off" the LED is in a high impendence state and may not pull the input high enough to provide a proper "high".

Of course, if there is an internal pull-up then the external pull-up in not needed.
 

Thread Starter

kiweered

Joined Dec 13, 2021
28
The GPIO pin input impedance is very high, like over 100K. When the sensor is off, this impedance forms a 2-resistor voltage divider with R5 in your first schematic. R5 is 1K, so the voltage at the input pin is 3.27 V or more. There is only 0.03 V across the LED, not enough for it to conduct current and emit light.

ak
Ok thanks I think this is what I was missing.

" I guess the pullup resistor is useless here"

No, because the impedance of an LED is extremely high when not conducting therefore when the transistor is "off" the LED is in a high impendence state and may not pull the input high enough to provide a proper "high".

Of course, if there is an internal pull-up then the external pull-up in not needed.
Yep, understood !

Thanks all for your aswers !
 
Top