# Window comparator using LM339 - invert output

I'm using the LM339 for an application with different voltage ranges. I am using the window comparator circuit since I want to test a specific range (4 - 8V). The circuit shown below actually identifies this "window" but not as I am expecting. When the input value is in this window I want to light the led, instead the led is off. Is there a way I could invert this output to light it in the window and turn it off when it's out of range?

Sorry if it's too dumb, but I'm stuck with this.

Put the LED between the combined output and ground and put the resistor directly to 12V.

When either of the comparators turns on it will short the output to ground and turn off the LED.

The function needed is a logical AND. The input level should be less than the upper limit AND above the lower limit.

The original connection of the LED performed a logical OR - it would light if the input was above the upper limit OR below the lower limit.

The open-collector outputs of the LM339 cannot be configured to do a logical AND but by inverting the logic we can do a DeMorgan conversion and now cause the LED to be OFF if the input is above the upper limit or below the lower limit which means it is ON while the input is within the window.

• Why should you do that with diode? In that case circuit will always have current through resistor regardless if LED is on or not. It's a waste of energy, especially if this circuit runs on batteries. Instead there's an easier solution, just reverse polarities on comparators. Connect to "-" wires which are connected to "+" and connect to "+" wires which are connected to "-" on both comparators. Aug 10, 2016 at 19:29
• BJovke, Your solution will not work correctly - the LED will always be on. Your logic will light the LED if the voltage is below the higher limit OR above the lower limit. This will always be true. I agree that it is a disadvantage to have the current always flowing in R17. If you wish to reduce the current add a logic AND gate to drive the LED. kevin Aug 12, 2016 at 1:34

The LM339 can only sink current, as it has open collector outputs. When the voltage is within the window both comparators are off and hence no current flows, and LED is therefore off. If either comparator is outside the window then its output would be low, and hence the LED lit.

Place Led resistor to first Comparator output. Then connect that to second Comaparator output. Finally connect LED between bottom Comparator and ground 0ve. That should work

1. Swap pins 8 and 9. Now D2 will light when the input rises above 4 V.

2. Disconnect pin 2 from the LED cathode.

3. Connect pin 2 to the R17-D2 node. Now when the input rises above 8 V, pin 2 will cause the R17 current to bypass the LED, turning it off.