# Simple op-amp comparator circuit not behaving as expected

I've been attempting to design a circuit that will observe a connector and light an LED when there is a sensor connected to the connector. The LED will be off when the connector is left open.

The sensors that plug into the connector are 4-20 mA loop (aka process) sensors such as this one.. On the PCB, the connector for the sensor is in series with a 130 Ω resistor, which allows an ADC to measure the voltage and calculate the current.

I did not want the LED circuit to interfere with the current output of the sensor, as this would of course interfere with the readings, so I opted to use an op-amp that had a very high input impedance. I came up with this circuit (the current source is in place of the sensor):

I expected the voltage across the 130 Ω resistor (V+) to be approximately 0.52 V when the sensor is connected and outputting 4 mA, and the voltage at V- to be 0.45 V, therefore lighting the LED when the sensor is connected.

When I built this circuit, I used a TL071 as it's what I had handy. The LED was permanently lit, whether I disconnected the sensor or not. I can't figure out why, but I sense (forgive the pun) that I'm overlooking something very simple.

Does anyone have any suggestions? Perhaps the op-amp is unsuitable, or maybe there's an altogether simpler way of detecting the connection.

EDIT: I powered the op-amp at VCC- -> 0 V and just now figured that might be the problem, as Vout won't have reached 0 V. Can anybody confirm that this is the problem?

• Yes, that's the problem, but not at the output. The input voltages must be above Vcc- by at least 2.0 V. See section 6.5 of the datasheet. Nov 23, 2022 at 15:52
• Ah, brilliant point, thanks! Now to figure out how to adapt this design to work when I don't have access to a negative supply. I might have to source a single-source op-amp in this case. Nov 23, 2022 at 16:00
• There are plenty of comparators that do include the negative rail in their common-mode input range. I would recommend staying away from opamps in comparator applications. They tend to be slow, and in some cases, ill-behaved when the inputs are over-driven. See What is the difference between "opamp" and "comparator"? Nov 23, 2022 at 16:03
• We're not really allowed to make product recommendations here. Try going to your favorite parts distributor (Digi-Key, Mouser, etc.) and using their parametric search. The LM311 does not have rail-to-rail inputs either. LM339 is an old standby that might work for you. Nov 23, 2022 at 16:10
• Try using an LM358, LM324 or any other opamp or comparator which is advertised as being "single supply" capable. Nov 23, 2022 at 16:27

## 2 Answers

Jonk +1 answered in detail why this is not working, and you should read and understand it.

If you just want a quick solution, substitute half of an LM358 for the TL071. The LM358 is not a rail-to-rail input or output op-amp but the input common-mode voltage includes the negative rail and it will get down to within mV of the negative rail at the output when not sinking current.

As a subtle, but not unimportant, additional consideration, the output when railed is guaranteed to be of the correct 'state' so long as both are higher than the negative rail and one of them is within the common-mode input range. Since the inverting input will always be within the common-mode input range (about 0 to 3V) we don't need to worry about the other. There's another important point.

Unlike most more modern RRIO op-amps, the inputs are allowed to exceed the supply voltage, up to more than 30V depending on the exact variant.

That may not seem like a big deal since 20mA * 130Ω is 2.6V, which is way under 5V, but if you attach a two-wire transmitter using an active 24V loop power supply to the circuit any output capacitance in the transmitter will cause a transient that will approach 24V. That will likely cause latchup in a RRIO CMOS op-amp and it will be destroyed almost immediately (and also will interfere with the signal while it is frying). I would add a series 10K resistor to the non-inverting input in either case, which will mitigate any transients and will prevent any fault in the LED circuit from having much effect on the signal.

simulate this circuit – Schematic created using CircuitLab

Now, if you want a real simple solution, you could just put the LED in series with the current loop, something like this:

simulate this circuit

Much sloppier transition, LED intensity varies with current up to a point and it robs up to 5V and change out of your compliance, but easy.

• Thanks to you and @jonk - I understand the problems with my approach much more now. I think, for sake of simplicity, I may try the second circuit. Can I ask what the purpose of the zener diode is? Is it just a form of over-voltage protection? Nov 24, 2022 at 11:10
• The zener limits the current through the LED and limits the maximum voltage drop of the circuit to less than 6V. You could just connect an LED in series with the 4-20mA and get even less voltage drop but some transmitters output close to 30mA for over range, which is a bit much for a normal LED. Nov 24, 2022 at 11:16

First off, a TL071 is kind of limited. It's certainly not a rail-to-rail I/O opamp. From the datasheet:

This really is not encouraging, given a $$\5\:\text{V}\$$ rail and ground. It's basically saying that the output will typically be about $$\1.5\:\text{V}\$$ away from the rails, which after you subtract away those margins means you only get about $$\2.5\:\text{V}\pm 1\:\text{V}\$$ at the output as your range. That's if the temperature is stable at room temperature. Worst-case, though, over the entire allowable operating temperature range? You've got nothing at all.

So, let's just assume you don't care and that the temperature will be stably at room temps and that you plan to accept the "typical" instead of worst case scenarios and just plain "go with it."

Okay. So now let's look at the input common mode range:

That pretty much tells you that typically the input can't go below about $$\+3\:\text{V}\$$ in your case (note the $$\-12\$$ in the typical column?) though it seems that they can get close to your $$\+5\:\text{V}\$$ rail.

So you have input range limitations and output range limitations and your $$\+5\:\text{V}\$$ rail really isn't giving this opamp any elbow room to work with. Using it will be 'pretty painful'.

One way it will be painful is that while the input current load on your source will be 'nil' when the input is within the common mode range, when it is below that range the input current load on your source might be hundreds of thousands of times higher. You don't know when, where, or if that will happen. But it almost certainly won't be low, at some point. Yet another potential source of an unanticipated error in the circuit.

For the LED itself as a detector, you really want a different circuit that includes hysteresis. I get it that you also want an analog output so that you can 'read' the value being provided by the sensor. But just hooking up the LED like that really isn't the answer.

In short, there are a lot of problems to solve if you are stuck with a TL071 and are willing to use 'typical' values and abandon conservative design. (If you are being conservative, you simply cannot use it at all and need to find something else.) One of the problems is how to design for an unknown sourcing current from the input through your $$\130\:\Omega\$$ resistor when there's no sensor connected and how you will handle it. Another is to get a different result where the input is at least $$\3\:\text{V}\$$ from the minimum of $$\4\:\text{mA}\$$ when the sensor is connected up. And another is to get, say, $$\4.5\:\text{V}\$$ at the input when the sensor is delivering the full $$\20\:\text{mA}\$$. And that's just the analog part. The LED circuit needs to be separated, I think.

I'd just suggest that you abandon the TL071 and then think a lot more closely about your situation before grabbing up an opamp or two and slapping things together.