[Solved] LM339 Comparator Confusion

I'd like to use this circuit to detect low levels of light with a phototransistor and turn on an LED with a comparator (LM339). When the input voltage is higher than the reference voltage, it's supposed to connect the output pin to ground. Otherwise output should be an open connection.

But that's not how it's working in the actual circuit.

Input connected directly to ground, output open
Input connected pretty much anywhere in the circuit or even disconnected, output closed
vref disconnected, output closed
vref connected directly to ground or +5v, output closed

So the output is closed as long as the input isn't connected directly to ground...

I'm pretty sure the comparator isn't broken, because I tried 2 and have the same results. I think I'm just confused about how this comparator is supposed to be wired up.

Circuit in attachment.

y (2).png

820 ohms and 470k ohms?
What voltage is that resistor divider putting on the non-inverting input?

Is that what you want to be comparing with?

Is that even in the common mode voltage range for the 339!?

The voltage divider produces 0.4-0.5mV, the phototransistor part produces around 0.7mV in my room. Around 25mV when I shine the flashlight on it.

The circuit was updated to remove the transistor I was using to amplify the output of the phototransistor, and the vref divider was updated accordingly (it's what the original image shows now).

But after updating it I have a different problem.

0 - connected directly to ground
1 - connected directly to vcc

VREF IN OUT
  1   1  0
  0   1  0
  1   0  0
  0   0  0

y (2).png

If that is a regular led, it requires a series limiting resistor ~220 ohms.

.

Might do better with a LDR...

Allan.

0.7 mV over 1M resistor? Looks like something is wrong with the phototransistor.

Smajdalf:
0.7 mV over 1M resistor? Looks like something is wrong with the phototransistor.

I've got a bag of them, and they all produce around 1mV for the same light level.
Maybe the batch it defective? They give the same voltage regardless of resistance.

That's kind of irrelevant for the comparator though.

I was rewiring the circuit to remove jumper cables and move certain things closer together. When I noticed something. Without the vref connected, and with the phototransistor connected to the other input, it seems to work like I wanted it to. With vref connected again, it's always closed no matter what light levels are present.

After rearranging the divider circuit on the breadboard, it works fine. Looks like I just had it backwards.

You may want to experiment with feedback from the output to input+ ~10meg.

.

Hi,
What are your photo transistors, spec/data sheet.
Have you connect them the correct way round, what are the pinouts?

1M sounds way to low, you will never have any decent amount of current for transistor to work with.
Try 100K, 10K and 1K

Thanks.. Tom... :slight_smile: