# Comparator Question (and more general question)

I have been fascinated with electronics my whole life and read many books on it, but only recently have I began to really tinker, and I have often been befuddled by many salient details that are involved, that don't seem to be written down anywhere.

simulate this circuit – Schematic created using CircuitLab

The current circuit I am working on is a comparator (LM339N). It is on a 9v source. I have two voltage dividers feeding the +/- inputs. One is a simple 50% voltage divider, and the other has a photoresistor attached. The goal is that when the photoresistor detects no light, an LED attached to the output should light up.

So, the LED is attached to the outlet so it sinks to the comparator when it goes low (the fact that comparators only sink current and do not source it took me forever to discover - again it seems that there are many salient details that are hidden to newbs like myself).

The circuit works great if it does the opposite - if the light on the photoresistor turns the light off. Now, to me, it seems that if light on the photoresistor turns the light off, then I should be able to get my desired result simply by switching the inputs of the comparator. However, when I do this, the light never turns on.

The only thing I can think of (which I couldn't think of last night when I was working on it until midnight, but now that I'm in my office I'm wondering about), is that maybe the fact that the photoresistor is giving a variable voltage rather than a constant reference voltage is preventing the comparator from working.

Another possibility is that I don't know if the comparator is sinking current from my voltage dividers or not, and/or messing with their operation by providing a low-load path for electricity. Does it matter how stiff I make my divider? 200-ohm or 10k ohm dividers?

So, in short, if anyone knows much about comparators and can help me in the right path that would be great. But even more, if someone knows a good book that helps with the nitty gritty sorcery involved in electronics (like going through each major part and telling where the doozies are - like that comparators don't source currents), that would be even better.

• On this site we always say: No schematic means no answer. We're too lazy to get the crystal ball out to see what you build. Commented Jul 7, 2016 at 14:22
• Moreover, seeing a title saying "comparator" I would assume a very simple question. But seeing a wall of text under it I would say "nah, not going to read all of this for a simple question". Commented Jul 7, 2016 at 14:46
• Did you read the datasheet of the LM339N? At least one of your questions is answered there. Commented Jul 7, 2016 at 14:50
• There is a schematic button on the editor toolbar. Click it! Double-click components to edit their properties. Commented Jul 7, 2016 at 14:53
• Buy a copy of "The Art of Electronics" (TAOE), and read every relevant section carefully several times. Try reading datasheets, and reference TAOE or use a web search when you don't understand something. The second edition is fine, and might be picked up cheap at a charity store, 'garage sale', etc. IMHO TAOE answers your basic questions, and gives enough understanding to read a comparator datasheet. Commented Jul 7, 2016 at 15:16

This is not a complete answer - yet.

simulate this circuit – Schematic created using CircuitLab

Figure 1. OP's schematic with + and - inputs swapped.

Everything you have reported indicates correct understanding of the circuit operation. Switching the + and - inputs should have worked.

Another possibility is that I don't know if the comparator is sinking current from my voltage dividers or not, and/or messing with their operation by providing a low-load path for electricity. Does it matter how stiff I make my divider? 200-ohm or 10k ohm dividers?

If the LDR goes < 5k when lit then you have set this up correctly. The input impedance of the LM339 will be very high in comparison with your 5k resistors so that shouldn't be the problem.

Next steps:

Using the battery negative as reference, measure the voltage at A; measure the voltage at B and report readings for dark and light. We're expecting:

| Dark | Light |
==================
A |  4.5 |  4.5  |
B | <4.5 | >4.5  |

Report back.

Tip: The problem with your connection between 'A' and the comparitor (on the CircuitLabs schematic) was that you were trying to cross the node of R2. That will cause it to connect. I pulled R3 and R2 down one square and the lines then cross without connecting.

• Reporting back - it turns out that I had blown something in my comparator, but not enough for it to completely cease functioning. I checked the voltages and got really strange results. I checked the resistors in the reference voltage divider three times and even though they were equal the voltages across them were NOT, telling me that something in the comparator had shorted out. Anyway, I swapped it with another comparator and everything was peachy. Thanks for the help! Commented Jul 8, 2016 at 1:52