Opamp "sticking" randomly - Page 1
Forum section: electronics / projects

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 10:40:54 am
content: I have a problem where this water level detector sometimes doesn't cut off the pump+solenoid valve when water level is sufficient. The LEVEL_SENSOR is a metal rod from the top in a grounded metal tank. Once the water reaches the rod, it should shut off. If the problem occurs, it seems to always be when switching on power (which powers the 5V SMPS + circuit below).Do you see any obvious problems in this circuit?Could it be the SMPS voltage rise time, that confuses the LM358?

author: Zero999
author_rank: Super Contributor
timestamp: July 08, 2025, 10:51:33 am
content: Is the circuit ground connected to the metal tank?The common mode range of the LM358 is being exceeded, although it should still work as a comparator, when of its inputs are still in the common mode range. I suspect IC1B is the problem. Try driving the relay and opto-coupler directly from pin 1 and connect pin 5 to 0V./

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 11:04:04 am
content: Yes, tank and circuit are on the same ground.I can try, but if I remember correctly, it was like that before. The original design had tied IC1B pin5 to a 820k/10M divider (as per the datasheet for unused gates), instead between IC1A pin1 and the relay/opto there was a 74AC02 and a 555 timer to stop the filling if it took too long. But the reset signal for the 555 needs to be pulsed for it to start, not held, so the circuit didn't work. So I removed that and used IC1B as a buffer, as I remember it didn't work correctly directly from IC1A pin 1. The opto LED would feedback into pin1 and mess up the hysteresis(?)I could be wrong and can try it again?

author: iMo
author_rank: Super Contributor
timestamp: July 08, 2025, 11:10:16 am
content: When you do with batteries?PS: also you may try to use say 1uF capacitor there - that makes aprox 40ms delay, otherwise it is 4ms after power-on with 100n (off the sim and 100k water resistance).

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 12:55:44 pm
content: Quote from: iMo on July 08, 2025, 11:10:16 amYou mean C2?

author: mtwieg
author_rank: Frequent Contributor
timestamp: July 08, 2025, 01:15:35 pm
content: Quote from: Zero999 on July 08, 2025, 10:51:33 amEh, I wouldn't count on it. The datasheet from TI says the following:QuoteReducing the voltage from the R1/R2 divider to <3V might solve the problem. Or just use a different opamp which doesn't suffer from phase reversal.

author: Circlotron
author_rank: Super Contributor
timestamp: July 08, 2025, 01:22:35 pm
content: Some opamps don't like a big difference in voltage between the two inputs. This will be happening with IC1A.

author: iMo
author_rank: Super Contributor
timestamp: July 08, 2025, 01:29:57 pm
content: Quote from: okw on July 08, 2025, 12:55:44 pmYep. Also doublecheck your 100uF C3 in parallel with the protection diode. I would put there something like 10-100n. Plus see my small changes. Hopefully you are not using 2N7002 there..

author: RoGeorge
author_rank: Super Contributor
timestamp: July 08, 2025, 01:30:57 pm
content: Quote from: okw on July 08, 2025, 10:40:54 amRemove C3 (100uF).

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 01:31:31 pm
content: Quote from: mtwieg on July 08, 2025, 01:15:35 pm

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 01:33:05 pm
content: Quote from: RoGeorge on July 08, 2025, 01:30:57 pmSorry, C3 is already off the board (was just a test, the relay was clicking like crazy, but it turned out to be a 230V load dump from the solenoid on the other end).

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 01:34:15 pm
content: Quote from: Circlotron on July 08, 2025, 01:22:35 pmWhat do you suggest here? That I lower both the reference and the level divider?

author: Circlotron
author_rank: Super Contributor
timestamp: July 08, 2025, 01:40:14 pm
content: Quote from: okw on July 08, 2025, 01:34:15 pmReplace the LM358 with a LM393 comparator. They have the same pinout. The outputs are open collector though, so you will need pullup resistors.The (-) input of the second comparator should be connected to half Vcc. It will not function as a voltage follower, but will probably oscillate.

author: iMo
author_rank: Super Contributor
timestamp: July 08, 2025, 01:56:23 pm
content: See above in my post the other small changes I would do..

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 02:00:24 pm
content: Quote from: iMo on July 08, 2025, 11:10:16 am2N7002? Guilty. Why not? (I have 3904 in my bag.)

author: Zero999
author_rank: Super Contributor
timestamp: July 08, 2025, 02:01:02 pm
content: Quote from: Circlotron on July 08, 2025, 01:40:14 pmThe LM393 should work. In this case I would put a 150R resistor across the input of the opto-coupler, rather than a pull-up, to stop it turning on, when the output goes high.

author: iMo
author_rank: Super Contributor
timestamp: July 08, 2025, 02:05:02 pm
content: Quote from: okw on July 08, 2025, 02:00:24 pmIt is a mosfet which "switches on" at much higher Vgs voltage than the 3904. I would definitely use the 3904 there.Also doublecheck the logic of the sensing water level and switching the relay - in my above sim you may see the two situations - if the water is 30k ("the rod in the water") and when it is 100k ("the rod off the water"). The waveforms show the situation after power-on.

author: Andy Watson
author_rank: Super Contributor
timestamp: July 08, 2025, 02:27:03 pm
content: QuoteBe aware that the output of a LM358 will have difficulty in sinking current below 0.8V. This may not be low-enough to turn-off a bjt without further attention to the biasing network.I would definitely consider using a comparator instead of the LM358.

author: iMo
author_rank: Super Contributor
timestamp: July 08, 2025, 02:28:22 pm
content: Therefore my changes - see above the improved schematics..

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 03:29:53 pm
content: Did I remember everything?

author: David Hess
author_rank: Super Contributor
timestamp: July 08, 2025, 03:31:26 pm
content: The symptoms suggest a classic phase-reversal problem, which the 324/358 suffer from.The LT1013 is an improved direct replacement for the LM358 without phase-reversal, but has the wrong pinout in the SO8 package because they had to rotate the large die. It is also a premium part so relatively expensive.Let's see ... dual in SO8 package with no phase-reversal ...I used to use the CMOS LMC6482 for that sort of thing. The OPA2990 should be a good choice. Other parts I would consider are the TLV9102, TLV9142, and TLV2186.Quote from: Circlotron on July 08, 2025, 01:22:35 pmThe 324/358 do not have that problem and support large differential input voltages. High input impedance at one of the inputs will allow the use of parts which have a small differential input range anyway.

author: David Hess
author_rank: Super Contributor
timestamp: July 08, 2025, 03:32:31 pm
content: Quote from: okw on July 08, 2025, 03:29:53 pmPin 1 should have a pull-up resistor to the +5 volt supply also. I would not rely on those high value resistors for this.

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 03:43:03 pm
content: Quote from: David Hess on July 08, 2025, 03:32:31 pmHow will that affect the hysteresis? And which value should I choose?

author: David Hess
author_rank: Super Contributor
timestamp: July 08, 2025, 03:49:05 pm
content: Quote from: okw on July 08, 2025, 03:43:03 pmIt will increase the hysteresis because you will be pulling the output up to a full +5 volts, however it will also make it predictable.I would choose somewhere between 1/10th the value of R6 (39 kilohms), and the same resistance you are using at pin 7 (710 ohms). A 1 kilohm resistor would be fine.

author: Ian.M
author_rank: Super Contributor
timestamp: July 08, 2025, 04:03:27 pm
content: I wonder what the electrode potential is doing during powerup!See:https://en.wikipedia.org/wiki/Galvanic_seriesIf the electrode and tank are dissimilar metals e.g. a stainless steel electrode and a galvanized or aluminum tank, the resulting electrochemical cell could deliver up to around 1V, electrode positive. This will be clamped by the 1N4148 input protection diodes, so I doubt there will be over 0.6V at the OPAMP (or comparator) input, which *shouldn't* be enough to cause trouble provided the circuit is locally grounded to the tank near the sensor mount (to minimise noise and ground offset voltages).

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 04:13:37 pm
content: Quote from: David Hess on July 08, 2025, 03:49:05 pmLike this?

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 04:16:42 pm
content: Quote from: Ian.M on July 08, 2025, 04:03:27 pmThe thought have crossed my mind. Would I be able to measure it with a DMM (Fluke 189)? Or would the internal DMM resistance (though high) kill off any potential?

author: temperance
author_rank: Super Contributor
timestamp: July 08, 2025, 04:23:22 pm
content: In the long run this will fail anyhow because of electrolysis induced corrosion. To avoid this, AC should be used instead DC excitation for the rod.Edit: I didn't read what Ian.M wrote.With AC excitation, you can amplify an AC coupled and band pass filtered version of the received signal as much as you want without getting into trouble.

author: xvr
author_rank: Frequent Contributor
timestamp: July 08, 2025, 04:23:58 pm
content: MOC3083 will be permanentrly  turned on. When IC1B output in zero - via it and R10, when IC1B output is in off state - via R10, R9 and BE junction of Q1

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 04:54:17 pm
content: In the original design (first post) the MOC have reliably turned on and off, except when the opamp has been acting up (at least that's what I think)

author: floobydust
author_rank: Super Contributor
timestamp: July 08, 2025, 04:55:55 pm
content: okw, I would abandon the approach to use conductivity. That is Arduino-grade and they'll use a BJT or mosfet lol.The electrode gets nice galvanic corrosion due to the 5V/39k while it's wet. It has no AC mains hum rejection, and as Ian.M points out some metals in the tank can present a DC potential that fools the circuit.I would advise to change to AC excitation and it's not much different for the amount of hardware required.

author: Zero999
author_rank: Super Contributor
timestamp: July 08, 2025, 05:20:45 pm
content: Quote from: temperance on July 08, 2025, 04:23:22 pmAC is better and more reliable, long term, but it does require a more complicated circuit.Here's an ideal using the 74HC14. R2 determines the sensitivity. You'll probably have to adjust the resistor values if you build this, since I've only simulated it.Water detector AC comparator.ascQuote from: okw on July 08, 2025, 04:13:37 pmYes. That will work.

author: floobydust
author_rank: Super Contributor
timestamp: July 08, 2025, 06:08:41 pm
content: My view, you don't need A2, lower R2 to say 15-20k and increase C2 to 10nF (although I do not know your chosen frequency). I use 5-7kHz. Like sch snippet works and can use Tinylogic. It's 9V though and should be OK at 5V.You can actually use the LM358 for AC but biasing it up takes I think a third op-amp section. There are some very simple cheap boards on eBay. I have this fuzzy schematic of a pump controller but it gives the idea. One op-amp for the oscillator and another for the detector.Attaching some schematics for ideas.

author: temperance
author_rank: Super Contributor
timestamp: July 08, 2025, 06:30:06 pm
content: For the circuit presented by Zero999 you can also use 4000 series logic.

author: David Hess
author_rank: Super Contributor
timestamp: July 08, 2025, 07:20:27 pm
content: Quote from: okw on July 08, 2025, 04:13:37 pmExactly.

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 07:31:08 pm
content: Quote from: David Hess on July 08, 2025, 07:20:27 pmThanks!

author: okw
author_rank: Frequent Contributor
timestamp: July 08, 2025, 07:55:24 pm
content: Quote from: floobydust on July 08, 2025, 06:08:41 pmAt the moment I'm just trying to correct the already produced PCB, and the amount of changes are quite limited.The whole project was to learn how to realize the control with old-school gates. But I still need to correct is, as I'm dependent on it until next version.Next version is to rewamp the whole circuit and use an ESP/Arduino and I would love to use AC instead, but here I'm quite blank.

author: Zero999
author_rank: Super Contributor
timestamp: July 08, 2025, 09:26:44 pm
content: Quote from: okw on July 08, 2025, 07:55:24 pmI had a feeling you wanted to modify the existing PCB, so wanted to change as little as possible. Please be clear about this in future. It will make it easier to help, as we know what you want.It should be easy to implement using a microcontroller. Look at my schematic. A1, R1 and C1 can be replaced with a square wave driven from an output pin. A2 can just be an input, preferably a Schmitt trigger, but you can probably get away with just a normal pin. The input will simply see the same signal as the square wave output, until water is between C2 and 0V, which will short out the AC waveform, so the input will see some phase shift and a lower amplitude signal, until it no longer triggers.

author: Circlotron
author_rank: Super Contributor
timestamp: July 08, 2025, 11:39:53 pm
content: Quote from: okw on July 08, 2025, 04:54:17 pmThat's because the opamp output can pull high but the comparator can't because it's output is open collector. The node ends up floating. A decent pullup resistor on the comparator output will fix this.

author: Zero999
author_rank: Super Contributor
timestamp: July 09, 2025, 07:21:41 am
content: Quote from: okw on July 08, 2025, 04:13:37 pmI've just realised. No that won't work and it's my fault. I suggested far too lower value for R7! The idea is to prevent the opto-coupler from turning on, when the comparator's output is high. I chose too lower value, so the opto-coupler will never turn on.How much current does that relay coil use? I bet you could choose a higher value for R9, then R7 can also be higher and won't rob the opto-coupler of so much current.

author: okw
author_rank: Frequent Contributor
timestamp: July 09, 2025, 09:46:12 am
content: Quote from: Zero999 on July 09, 2025, 07:21:41 amThe relay uses 71.4mA (pluss the inrush).

author: Zero999
author_rank: Super Contributor
timestamp: July 09, 2025, 11:23:15 am
content: Quote from: okw on July 09, 2025, 09:46:12 amThere won't be any inrush, since the coil is just run off DC, the current will ramp up slowly.In that case then I recommend a MOSFET for Q1. Contrary to what's been suggested previously, the 2N7002 is suitable for just 70mA, with a logic voltage of 5V. It's specified as a RON= 5.3R when VGS= 4.5V and will deliver 4.6V to the relay coil, which should be enough. It also simplifies the circuit by getting rid of a few resistors.https://assets.nexperia.com/documents/data-sheet/2N7002.pdf

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 09, 2025, 08:28:10 pm
content: Quote from: Zero999 on July 09, 2025, 11:23:15 amA MOSFET is a good choice, but as drawn above, the OPTO LED drop means the gate drive is ~ 4V.Pick a logic level, low RDS fet and it will be fine.The'2301''2302' is popular and cheap.

author: Zero999
author_rank: Super Contributor
timestamp: July 09, 2025, 08:38:37 pm
content: Quote from: PCB.Wiz on July 09, 2025, 08:28:10 pmMore like 4.5V with the sub-pA current through the gate, although you're right, it could be better. Put 1M between pins 1 & 2 of the opto-coupler and that will ensure it reaches 5V.

author: okw
author_rank: Frequent Contributor
timestamp: July 09, 2025, 09:01:21 pm
content: 2301 is P-ch, but I need N right?I have these N-ch in my bag: 2N7002-7-F, 2N7002LT, AO3400, BSS138LT1G, BSS138PW, HL2312, IRLML2502TRPBF, IRLML6344GT, IRLML6344TRPBF.HL2312 might have the lowest RDS.Which would you guys recommend? And I still put the 1M across the opto LED?

author: Zero999
author_rank: Super Contributor
timestamp: July 09, 2025, 09:12:19 pm
content: Quote from: okw on July 09, 2025, 09:01:21 pmYou don't need super low RON. Your relay only draws 70mA and should still work down to 4.5V. Any of those will probably do.Yes, the 1M across the LED is a good idea.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 09, 2025, 10:35:06 pm
content: Quote from: okw on July 09, 2025, 09:01:21 pmoops, yes, I sorted by price and forgot to sort n N-Ch.Quote from: okw on July 09, 2025, 09:01:21 pm2312 is fine, note that FET part codes are somewhat nominal in Asia, so you can get quite wide variations on the die they label.I like to pick parts with ESD gate protection, as that has close to zero premium.5V relays have little margin, so RDS should be well under 10% of the relay resistance, it is easy to get < 1% and still be very cheap.

author: okw
author_rank: Frequent Contributor
timestamp: July 10, 2025, 11:11:59 am
content: Something isn't completely right. The output from IC1A switches correctly on high/low on the inverting input. However, IC1B output stays permanently low. The LM393 open-collector output probably needs a pull-up (which I might not be enough with the 560R+1M combo?

author: Zero999
author_rank: Super Contributor
timestamp: July 10, 2025, 11:23:42 am
content: Quote from: okw on July 10, 2025, 11:11:59 amHow did you measure it?Move R7 from pin 7 on the LM393 to 5V and change the value to 10k.

author: okw
author_rank: Frequent Contributor
timestamp: July 10, 2025, 12:45:04 pm
content: Quote from: Zero999 on July 10, 2025, 11:23:42 amWith a Fluke 189 between ground and pin 7.Quote from: Zero999 on July 10, 2025, 11:23:42 amI'll try.

author: okw
author_rank: Frequent Contributor
timestamp: July 10, 2025, 02:00:12 pm
content: Quote from: Zero999 on July 10, 2025, 11:23:42 amHad a short under IC1 from cutting the trace between pin6-7.So both 1M across LED and 10k pull-up on output actually worked. But 1M didn't always keep the relay stable (clicking, yet when relay was stable voltage was about 4.98V). But not all the time, seemed to happen randomly between power ups.10k seemed fine.What are the pros/cons between the two? Increasing the 10k, lowering the 1M?