Comparator (LM339) Question

Thread Starter

Roxi

Joined May 27, 2019
9
I have a question to help me understand better.
I am using the following circuit on a breadboard:

comparator.jpg
I want to connect a second led, LED2, from the comparator output (2) to ground,
that would light when LED1 doesn't. It doesn't work. Here is what I tried:

Since LED1 is connected to +V, it works when the comparator outputs -V, right? So that is 10V in this case
If LED1 has a voltage drop of 2V then the 330ohm resistor has a voltage drop of 8V. If LED1 draws 20mA then the resistor is 8V/20mA which is 400 ohms, which is about 330 so I think this is correct.
I tried calculating the second resistor (not in picture) in the same way. The output voltage now has to be +V, the voltage drop is now 5V. The resistor would be 3V/20mA which is 150ohms.
I measured LED2 with a multimeter and I have a voltage that is higher than 2 V, but LED2
does not light,
I tried for all values of the potentiometer, it doesn't. I checked the LED, it works well, just not in this case. I could use a transistor as an inverter but why doesn't this work? Thank you.
 

DickCappels

Joined Aug 21, 2008
10,152
Note: Your schematic says it is a 5V power supply. That might confuse some of us.

I can imagine a few different ways you might have LED2 connected, but I don't have any idea of how you have it connected. Would you please add it to your schematic or carefully describe with words how LED2 is connected and whether it is supposed to be on when LED1 is or when LED1 is off?
 

bertus

Joined Apr 5, 2008
22,270
Hello,

Where did you get the +10 Volts?
In your schematic you show a supply voltage of +5 Volts.
When you connect a second led from pin 2 to ground it will not work.
The comparator has an open collector output.

LM339_internal schematic.png

When the output is "high" , the output transistor is not conducting and both leds will be in series between the powersupply and ground.
Both leds will be lit dimly.

Bertus
 
Last edited:

bertus

Joined Apr 5, 2008
22,270
Hello,

As I said before, that circuit will not work.
When the output is low, the putput transistor will short led 2 and only led 1 will be lit.
When the output is high, the output transistor will not conduct and both leds will light dimly.
You will need an extra transistor for the way you want to change the leds.

bertus
 

jbeng

Joined Sep 10, 2006
84
The LM339 has four comparators in one package. If only one section is being used, one of the 3 unused sections could be connected to drive the second LED, indicating when the output of the first section is not active.
 

dl324

Joined Mar 30, 2015
16,845
Here is the complete image. I want LED2 to be on when LED1 is off and vice versa.
Most comparators have open collector outputs. If you use one that doesn't have open collector outputs, your circuit could work.

The devil is in the details. What is the forward voltage of the LEDs?
 

danadak

Joined Mar 10, 2018
4,057
If you ever get into processors there are some advantages, like no false LED
turn on on power up, more accurate V detection, ease of implementing hysteresis....


Here you write no C code, drag and drop blocks onto canvas (right window), then tool generates
Arduino C code for you. For future reference. Lots of videos on web to learn. There are also other
block languages with specific capabilities. Learn one they all are easy to use.

Note would be easy to add another input in block code that turns off both LEDs for low power control,
for example. Also to add a delayed (or not) pulse output when the compare voltage changes state. or
add more V inputs to look at other voltages....

1582478117669.png


Board would look like -

1582478214965.png

Chip, micro, is ATTINY85, basically Arduino like family part.

Regards, Dana.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
18,176
I have a question to help me understand better.
I am using the following circuit on a breadboard:

View attachment 199747
I want to connect a second led, LED2, from the comparator output (2) to ground,
that would light when LED1 doesn't. It doesn't work. Here is what I tried:

Since LED1 is connected to +V, it works when the comparator outputs -V, right? So that is 10V in this case
If LED1 has a voltage drop of 2V then the 330ohm resistor has a voltage drop of 8V. If LED1 draws 20mA then the resistor is 8V/20mA which is 400 ohms, which is about 330 so I think this is correct.
I tried calculating the second resistor (not in picture) in the same way. The output voltage now has to be +V, the voltage drop is now 5V. The resistor would be 3V/20mA which is 150ohms.
I measured LED2 with a multimeter and I have a voltage that is higher than 2 V, but LED2
does not light,
I tried for all values of the potentiometer, it doesn't. I checked the LED, it works well, just not in this case. I could use a transistor as an inverter but why doesn't this work? Thank you.
It will NEVER work because the LM338 is an open collector output comparator . The easy solution is to replace it with an op-amp. It will not be as fast but it will be able to pull up and pull down. But you will need to use "high brighness" LEDs because the current will be less.
 
Last edited:

AnalogKid

Joined Aug 1, 2013
10,987
My guess from your first question is that you do not understand the output stage of an LM339. The 339 is not a normal opamp. The output can sink current as in your first schematic, but it cannot source current as would be needed in the second schematic. In short, your approach (which would work with a true opamp) will not work with a comparator that has an open collector output.

But it can be done with one comparator using a trick. In this schematic (a fragment from the past), the LM393 is a dual version of the LM339. When pin 1 is high, current goes through the resistor, red LED, and the signal diode. When pin 1 is low, the green LED "shorts out" the red LED + diode combination because it has a lower forward voltage (2.1 V) than the combination (1.8 V + 0.6 V = 2.4 V). The green LED runs with higher current, so choose the resistor accordingly.

Apologies for the schematic quality (no reference designators, decoupling, unused pin treatments, etc.). I'll clean it up soon.

ak
1582524659535.png
 

Attachments

dendad

Joined Feb 20, 2016
4,451
You can do this...
2LEDs.jpg

With the 399 of (o/p high) LED 2 will light.
Then, 399 o/p to 0V, LED1 will light. The voltage drop across LED1 is less that that needed for LED2 and series 1N914 (or 1N4148) so LED LED2 is out.
EDIT: POOH! @AnalogKid beat me by a min!
 

atferrari

Joined Jan 6, 2004
4,764
Ha!
Mine really was scribbled on the back of an envelope!
You can see the line of the flap :)
Our local recent history tends to favor paper napkins over envelopes, where the names of judges, politicians and union leaders were mentioned.
Envelopes seem to be more for technical matters.
 

danadak

Joined Mar 10, 2018
4,057
My guess from your first question is that you do not understand the output stage of an LM339. The 339 is not a normal opamp. The output can sink current as in your first schematic, but it cannot source current as would be needed in the second schematic. In short, your approach (which would work with a true opamp) will not work with a comparator that has an open collector output.

But it can be done with one comparator using a trick. In this schematic (a fragment from the past), the LM393 is a dual version of the LM339. When pin 1 is high, current goes through the resistor, red LED, and the signal diode. When pin 1 is low, the green LED "shorts out" the red LED + diode combination because it has a lower forward voltage (2.1 V) than the combination (1.8 V + 0.6 V = 2.4 V). The green LED runs with higher current, so choose the resistor accordingly.

Apologies for the schematic quality (no reference designators, decoupling, unused pin treatments, etc.). I'll clean it up soon.

ak
View attachment 199841
Observation, when output low there is a small current thru RED LED, eg. its log curve at low V,
and if modern high bright LED used it possibly can glow at a low level ? I have seen this
issues discussed on other threads where uA levels of current cause the LED to glow, pro-
ducing low light level.


Regards, Dana.
 

MisterBill2

Joined Jan 23, 2018
18,176
Observation, when output low there is a small current thru RED LED, eg. its log curve at low V,
and if modern high bright LED used it possibly can glow at a low level ? I have seen this
issues discussed on other threads where uA levels of current cause the LED to glow, pro-
ducing low light level.


Regards, Dana.
I have done exactly that in years past. The LEDs were labeled by Digikey as "Super bright", and at 20 mA they were vey bright by those standards. And at about 3mA they were plenty bright enough to be easily seen. So they could be used with CMOS logic running at 5 volts and they were perfect for my applications. For the application in this thread one of those LEDs connected between the comparator output and negative supply might be adequate.
But I suggest instead using the second LED as simply a "power present" indicator that would be on with the power. A comparator output is either on or off, high or low, no other conditions.
Of course it can be oscillating rapidly. THat can happen.
 
Top