Earth ground referenced comparator - Page 1
Forum section: electronics / projects

author: okw
author_rank: Frequent Contributor
timestamp: December 23, 2021, 08:27:27 pm
content: Hello!I have made a water level sensor circuit which senses contact with water between a probe and a earth grounded (3rd pin of 110/220V outlet) metal tank. This is my reference to the comparator. I connected the earth ground to the non-inverting input of the comparator, but made the mistake of not joining the earth ground and signal ground. Should I join these two with an inductor (or something) to create a common reference? Any insurances the comparator or other chips won't die if there is a earth ground problem (for example a heating element with leakage to earth ground - water between the heating element poles and ground could introduce microscopic currents to earth ground, without breaking the ELCB)? I included hysteresis, so the auto-fill pump won't engage on and off too much in the threshold area. Does this look correct?(I also made the error of connecting earth ground instead of signal ground to comparator GND (pin 4), but this will be corrected).In short:-Should both IC2 and T be grounded by signal ground (not earth ground)?-Should earth ground and signal ground be joined by an inductor, if yes, which value?-Any other modifications, to increase redundancy/stability/etc.?

author: Kim Christensen
author_rank: Super Contributor
timestamp: December 23, 2021, 08:54:28 pm
content: Redo your schematic... Maybe use a while background instead? What you posted is virtually unreadable.

author: Benta
author_rank: Super Contributor
timestamp: December 23, 2021, 09:08:34 pm
content: ^^^ This.The "Dark Theme" is not very good.Also, try to be specific about what you mean by "Earth", "Ground" and "Ground Earth".

author: okw
author_rank: Frequent Contributor
timestamp: December 23, 2021, 09:31:04 pm
content: I can't really see how it's unreadable, unless you're on a phone/tablet. Pressing the link opens the schematic in full size and it quite readable. However I included a white background.Dark theme is a blessing for the eyes after many hours.Earth ground is the 3rd pin of a 110/220V. Signal ground and ground would the GND pins of most chips I use (LM358, NE555, etc.) for this project.I modified the original post with more consistent use of earth/signal ground.

author: viperidae
author_rank: Frequent Contributor
timestamp: December 23, 2021, 09:39:31 pm
content: Unless I'm missing something, this doesn't do anything?The input signal is first rectified by the diode, then AC coupled with a capacitor. The input can only apply a positive voltage to one side of the capacitor and the other side is pulled high. Current is only going to flow for a brief period when the input goes higher than your supply rail.That would result in the opamp inverting input going from 5v to above 5v then back down to 5v.

author: Kim Christensen
author_rank: Super Contributor
timestamp: December 23, 2021, 09:58:38 pm
content: I would eliminate D2 and C3 as mentioned by viperidae.Next, you do not have to worry about "different grounds" if you power the entire circuit with an isolated power supply like a wallwart which is what you should be doing anyway.

author: okw
author_rank: Frequent Contributor
timestamp: December 23, 2021, 11:10:18 pm
content: Quote from: Kim Christensen on December 23, 2021, 09:58:38 pmI can't use a wall wart. Since it will be a drop in replacement of an exiting pcb, I have hard specs. Pins: 250V power (line + neutral + earth GND), sensor probe in, pump power out (L), heating element power out (L).Pump turns on and heating off when water level is too low. And vice versa.I'll remove D2 and C3.Any suggestions of how to make this circuit work with hysteresis? And which values to tweak to adjust the hysteresis?

author: Kim Christensen
author_rank: Super Contributor
timestamp: December 23, 2021, 11:41:59 pm
content: QuoteWell, then you should put a small transformer on the PCB that steps down the 250VAC and also provides galvanic isolation. The secondary voltage will depend on what type of relay (mechanical or solid state) you choose to switch the power for the pump and heater.

author: okw
author_rank: Frequent Contributor
timestamp: December 23, 2021, 11:53:13 pm
content: It's already in placeAlong with triacs and relay for pump and heating elements, a 555 timer for timeout unless the tank fills within a specified amount of time.I didn't post the full schematic, as some of it is proprietary. It has a transformer isolated 5V supply.

author: okw
author_rank: Frequent Contributor
timestamp: January 14, 2022, 05:48:58 pm
content: I've updated the schematics and included everything, except the pump and heater relay circuits (as they are quite easy).Any help to get this working?

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 14, 2022, 07:05:22 pm
content: How much hysteresis are you expecting from the LM358 circuit? You'll only have around 61mV of hysteresis because the output (pin 1) of the Lm358 is connected directly to the base of T2 limiting the voltage swing there to 0.7V. Plus, the LM358 will be in current limiting mode when pin 1 goes "high". You really should have a resistor in series with T2's base to limit the current and allow LM358 pin1 a wider swing:

author: okw
author_rank: Frequent Contributor
timestamp: January 14, 2022, 07:12:21 pm
content: I'm not sure how to calculate each resistor value, so it based it on a design I found online, but for a slightly different application.About the swing, I'm not sure how much is needed, I have to experiment with it. What would you say is good values for starting off? Then which values should I tweak?

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 14, 2022, 07:41:44 pm
content: You need to know how much "noise" (voltage instability) there will be on the LEVEL_SENSOR/5.3C input in a worst case scenario. Then you'd make sure that your hysteresis is greater than that by a reasonable margin. Also, you wouldn't want to make the hysteresis so high that it doesn't switch reliably. Once you know the hysteresis required and the output swing of the LM358 while driving T2 via the 8.2K, then you can choose R8's value to set the hysteresis.

author: okw
author_rank: Frequent Contributor
timestamp: January 14, 2022, 07:51:01 pm
content: Excellent. Thanks.And the schematic I supplied + 8.2k base resistor should work fine?About connecting earth_gnd and signal_gnd. What inductor should I use?

author: fourfathom
author_rank: Super Contributor
timestamp: January 14, 2022, 08:22:55 pm
content: Comments:the 555 output connected to "TIMEOUT" is a totem-pole design, and will force the LM358 "+" input either high or low. I assume the intent is to force the output ON or OFF, but instead it's going to prevent the comparator from working as you intend. Perhaps drive a transistor with the 555 output pin (through a base resistor) and connect the collector to the 358 (+) pin. You will have to deal with the logic inversion caused by the transistor.Once you fix this, your comparator will have hysteresis, provided by R8.The LM358 output is connected directly to the transistor base. I suppose this will work, but the output isn't exactly designed for this. It will drive perhaps 50 mA into the base. The 358 output capable of continuous short-circuit, but that's a lot of current into the transistor base (I can't find a spec for the absolute maximum base current for a 2N3904). You should add a resistor between the 358 and the transistor.The LM358 is an opamp, not a comparator. It will work as one, though, but with issues that probably won't matter in this design.I would really put some input protection on the LEVEL_SENSOR and EARTH_GND inputs. Diode clamps, series resistors, and noise-filtering capacitors are likely essential.Your original dark-mode schematic was virtually unreadable to me on my huge monitor. This may be because I have red/green color vision issues (for me it's extremely hard to see small red traces on a black background). A pretty large percentage of men have this type of color vision problem. Go for high-contrast colors.

author: okw
author_rank: Frequent Contributor
timestamp: January 14, 2022, 08:37:22 pm
content: Quote from: fourfathom on January 14, 2022, 08:22:55 pmThanks for the feedback.Oh yeah, I see it now. The timeout is there to ensure the pump wont be engaged forever (in the event of empty water reservoir tank, bent hose, seized pump, etc).However, even if it worked it would be counterproductive, as this would automatically turn off the pump after the timeout period, which would turn on the heating element. That would burn the heating element (if the water tank is empty).I need to work on the logic.I have a lot of opamps/comparators. Which standard one would you recommend for this kind of application?I originally had diodes and caps, but obviously wrong. How would I go about protecting the inputs?Dark mode: I didn't know. Then I don't have problems with my eyes. It's so delightful with the dark theme. The white background really tires my eyes.

author: fourfathom
author_rank: Super Contributor
timestamp: January 14, 2022, 09:21:35 pm
content: Quote from: okw on January 14, 2022, 08:37:22 pmThe LM393 is the "generic comparator" equivalent to the LM358 "generic opamp".But the more I consider it, I see some advantages to using the 358. The 393 has an open-collector output so you would need a pull-up resistor at the output (which would supply the transistor base current). The comparator output would then shut *off* the transistor, so you would have to rearrange your hysteresis and logic levels.But the 358 and the 393 have identical input stages, so that's not a problem. The 393 is faster as a comparator, but that's not going to matter in your case. The 358 class AB output (drives both high and low) might be an advantage in your design.One caveat: the 358/393 inputs aren't designed to work all the way up to the positive supply rail (look at the specs). You might want to have your sensor pull-up resistor connect to +3V (you can use a resistor divider on the +5 rail), or use a true "rail to rail" part.And it might be time to back up a bit and reconsider the entire circuit. Why is the transistor there in the first place? You can drive the LVC inverters directly from the 358 output (or from the 393 comparator, with a pull-up resistor). You can take the positive feedback (hysteresis) from the second inverter. Of course you could replace everything following the comparator with a $1 8-pin PIC-style ucontroller. Actually, you could even pull the comparator function into the PIC using the internal ADC. But I assume you don't want to go that routeI've got to run now, but if nobody has shown you a good input protection circuit I will draw one up tonight or tomorrow.

author: okw
author_rank: Frequent Contributor
timestamp: January 15, 2022, 02:25:07 pm
content: I backed up and reconsidered the circuit. I got rid of the transistor, as you pointed out. Added a voltage divider for 3V pull up for the level signal.I also made the 555 timer control the pump/heating, instead of the Schmitt trigger. I also swapped the two output signals from the Schmitt triggers (since I removed the NPN).I utilized the second opamp to control the timeout buzzer (active). Not sure if this will make the buzzer beep at random times in during the transitions low/ok water level?I'm I on the right track?

author: fourfathom
author_rank: Super Contributor
timestamp: January 15, 2022, 03:43:18 pm
content: I think you are making progress. Some more comments:As was mentioned, the LM358 inputs aren't specified to accept inputs near the positive supply. You are driving LM358 IC1B with AUTO_FILL_OFF which is a 0/5V logic level. The other IC1B input signal is PUMP_ENGAGED. If you are using a bipolar 555 this output may (or may not) be within acceptable range, but id you use a CMOS version of the 555 it will definitely be out of range. More important, even if there weren't input range issues, what will be the output of the 358 when both inputs are high or low? It's undefined and could be anything. You really need a logic gate for this function. Looking at the circuit, whenever AUTO_FILL_OFF is low the 555 output PUMP_ENGAGED will be held in reset. What is the logic you are trying to have here? Perhaps you could change that inverter package to a quad NAND or NOR, and use those gated for your inverters and logic?Your comparator bias resistors look good. You generally want to match the resistance into each input to compensate for input current, but on your case with wide voltage swings and big resistance changes on the sensor input this probably doesn't matter. What are the characteristics of your sensor? You are now feeding it from a much lower resistance (405K vs 1M previously).Is your circuit completely isolated from any other connections to other equipment grounds, mains ground, or neutral (if you have one)? It looks like it is, assuming your 240VAV/5V power module is fully isolated (and I supposed it has to be). This is an important requirement for your circuit, and if so I don't think you need those EARTH_GROUND inductors -- I'm don't see the circumstances where they make a difference. Perhaps someone else will want to comment on this? (please???)You still need protection on that LEVEL_SENSOR input. I am attaching a possible circuit.Sorry to harp about the schematic format, but the nets and text are still difficult to see or read. A light green-on-white just doesn't have enough contrast.

author: okw
author_rank: Frequent Contributor
timestamp: January 15, 2022, 04:43:03 pm
content: Quote from: fourfathom on January 15, 2022, 03:43:18 pmMy idea was to reset the 555 every time the level sensor sensed ok water level (even a brief second) to not issue a false alarm. But I suppose trigger pin going high (which happens when level is ok) will do the same thing.I added the schmitt trigger to get a clean square wave from the opamp. Is it even needed?Quote from: fourfathom on January 15, 2022, 03:43:18 pm0R. The sensor is a simple metal rod halfway into the tank (standard design for all these). Once the water level touches the rod, pump should stop.Quote from: fourfathom on January 15, 2022, 03:43:18 pmWe have both IT (isolated ground / Isolée Terre) and TN (Terra Neutral) power distribution systems, depending on the age of the residence. Neutreal+Line+GND. In IT we measure approx 115V between L or N to GND. On TN we measure the full 230V between L or N to GND. The circuit should also work other places in the world (I'm not so familiar with other systems).I'm using one of these cheap 5V 700mA modules from Aliexpress, I think it's a transformer isolated mains supply, possibly flyback topology:https://www.aliexpress.com/item/4000588876625.htmlWould "upgrading" to one of these be better?https://www.ebay.com/itm/122230400197Allthough the inside looks quite similar:https://lygte-info.dk/review/Power%20Mains%20to%205V%200.6A%20Hi-Link%20HLK-PM01%20UK.htmlI wanna keep cost down, but not at the expense of safety or compatibility with distribution systems.Quote from: fourfathom on January 15, 2022, 03:43:18 pmThanks, I've added this now.

author: Terry Bites
author_rank: Super Contributor
timestamp: January 15, 2022, 05:19:34 pm
content: The input common mode range for the comparator is Vcc-2. ie 3V max. Pin 2 pulled up to +5V. You'd be better to tie it to somwhere below 2.5V, 200mV under your upper threshold.

author: fourfathom
author_rank: Super Contributor
timestamp: January 15, 2022, 06:44:33 pm
content: Quote from: Terry Bites on January 15, 2022, 05:19:34 pmWe've addressed this since the original posted circuit. I haven't checked the divider voltages though but that's obviously trivial.[I just checked]The + input is at 2.5V +/- a small hysteresis (around 0.2V).The - input is at 3V or less.The first spec I saw for the LM358 showed that (Vcc - 2V) would be a safe upper limit on the inputs. Have you seen a different spec?

author: okw
author_rank: Frequent Contributor
timestamp: January 16, 2022, 03:07:15 am
content: I replaced the Schmitt with a quad NOR. I think that took care of both inverting and timeout alarm, with one gate to spare?

author: fourfathom
author_rank: Super Contributor
timestamp: January 16, 2022, 03:56:56 am
content: Your positive feedback (hysteresis) for the comparator should be taken from the comparator output, not the following inverter. Sorry, I should have caught that in your previous version. I had mentioned changing the feedback point when discussing other comparator options, but with the 358 now giving you a wide swing just take the feedback from the 358 output. As it is now you have negative feedback and probably unstable at that.You confused me with your 74AC02. As you note, these are NOR gates, but your symbols are NAND. Your logic diagram is also confusing (and probably wrong) since you show states with AUTO_FILL_ON and AUTO_FILL_OFF both being high or low. As you note these two signals are complementary and will never have the same state. And just looking at the two NOR inputs your state table is wrong. NOR output is high only when both inputs are low. All other input cases give a low output. The NOR has only four states.Re. transistor T1, when driving the gate from a regular CMOS logic gate you don't need R7. It doesn't hurt but it's not required. R6 is still needed, but with a 50mA load you want around 5mA into the base (the transistor spec sheet shows saturation curves for different base/collector current ratios). Perhaps use 820 Ohms for R6. The NOR gate can comfortably drive that.Please tell us about your moisture sensor. How much current can it "switch" and what is the leakage in the "dry" state? Is this something like a spike in the ground? Or is it some hard-on / hard-off sensor? And you mentioned a heater -- do we need to know about this and how it will be controlled by your circuit?I have by no means completely reviewed your design, so there may be more issues to come.

author: okw
author_rank: Frequent Contributor
timestamp: January 16, 2022, 04:19:33 am
content: Quote from: fourfathom on January 16, 2022, 03:56:56 amIn Eagle, the standard 74-library AND and OR almost look the same (only distinguished by the double lines going through the D). Very confusing.Both ON/OFF being in the same state is "don't care = x". It will never happen. So the only four outcomes is marked 0 or 1 in the TIMEOUT_ALARM column. And i'm only interested in the 1 (which is timeout). With the NOR gate, I achieve that, right? ​Quote from: fourfathom on January 16, 2022, 03:56:56 amThanks. R7 removed.Quote from: fourfathom on January 16, 2022, 03:56:56 amIt is simply a metal rod going from the top of the tank and down halfway into the tank (tank should never fill more than half), and the tank is grounded to mains earth.So I'm basically measuring the resistance between mains earth and the rod, with the water providing resistance when it hits the proper fill level.

author: fourfathom
author_rank: Super Contributor
timestamp: January 16, 2022, 04:36:00 am
content: Quote from: okw on January 16, 2022, 04:19:33 amOK, I see the four legal states in the middle of your table. Why do you show the four others that are impossible? Trust me, that only confuses things.Quote from: okw on January 16, 2022, 04:19:33 amOK that's pretty simple. Have you got resistance measurements at the proper fill level? Pure (distilled) fresh water is actually a good insulator. What do you know about the water you are working with?

author: fourfathom
author_rank: Super Contributor
timestamp: January 16, 2022, 04:39:45 am
content: Hey, would anyone else like to weigh in here? I don't want to steer okw wrong, or over-complicate things. Trust me, I can take a little necessary criticism!

author: okw
author_rank: Frequent Contributor
timestamp: January 16, 2022, 12:34:07 pm
content: Quote from: fourfathom on January 16, 2022, 04:36:00 amI measured the it at 3.5 - 4M. But that's with the same water sitting in the tank for a few weeks/months (stainless steel tank with a few copper pipes). It will probably be a bit higher when fresh water flows in. The intake is on the bottom, the outlet is on the top, so a lot of "old" water (with ions) will still be left and create a resistance. The fresh water will only slightly dilute the tank water. Newer tanks are stainless steel (negligible ion deposits), older models are copper (contributes with quite a lot of Cu2+ ions).I also measured fresh water in a 1 liter jar, 7-9M. So it will definitely detect something, if my opamp resistors are tweaked good enough.In Norway we have quite soft water (little ions) compared to other places in the world, so if I get the detector to work here, I'm sure it would work anywhere.

author: fourfathom
author_rank: Super Contributor
timestamp: January 16, 2022, 04:19:35 pm
content: It would be nice to get an upper limit on the "water detected" sensor resistance. If we assume it's 10M then with the bias resistors in your circuit the comparator (-) input shifts from 2.976V (dry) to 2.851V (wet). Call this 100mV. That's not a lot of swing and you are going to want 1% resistors to set the comparator voltages. You will also probably want to increase the value of the bias resistors at the (+) input tp more closely match the resistance at the two inputs. You also need to reduce the amount of hysteresis -- what you have is now about 0.2 Volts. Perhaps increase R8 to 5M or so?One way to increase the wet/dry voltage change is to increase the resistance of your sensor bias divider resistors, or add a third resistor as I had shown (scratched out) in my last circuit. But this comes at the expense of more sensitivity to the comparator input offset voltage and input offset current. I checked the existing circuit against the 358 specs and the effect of these factors was only about +/- 7mV, but when you increase the input resistances this effect also increases. There are comparators available with much lower offset specs should this be an issue.So this is in a water tank? When it is filling there will be ripples, so the detector will initially see an oscillating high-resistance wet/dry/wet/dry condition until the level has risen enough for more immersion. Wil this be a problem for your design? I have experience with water tanks (I have lived in rural areas with wells), and the level detectors used for pump control are usually two-wire mechanical switches with perhaps 1/2 foot of mechanical hysteresis. You really don't want to have high-frequency pump cycling.

author: okw
author_rank: Frequent Contributor
timestamp: January 16, 2022, 10:49:23 pm
content: It's quite difficult to measure, as the readings jump up and down as i move the dmm probes in the water. Perhaps concentration of ions isn't uniform?Yes, the high frequency pump cycling must be avoided at all costs. Wouldn't a wide hysteresis swing take care of that?It has to be the current level probe design. This is a closed heated tank (<1.7bar and 130'C).Besides tweaking the values. Would the latest circuit be sufficient and a good design for this? So I can go ahead and layout and produce a prototype. It's only a few bucks, but I don't wanna waste time and money, if something is wrong.

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 16, 2022, 11:05:00 pm
content: Quote from: okw on January 16, 2022, 10:49:23 pmYou need to measure it using the actual rod in the tank as it fills with water. DMM probes will be completely different.

author: fourfathom
author_rank: Super Contributor
timestamp: January 17, 2022, 03:12:40 am
content: Can you run two wires to a pair of probes held apart a small distance by insulators? One of the probes can be grounded. That way you won't have to work with the resistance from the probe to the tank wall, but just between the two parallel probes which should be more repeatable.As for hysteresis, you need a linear (or at least usefully monotonic) variation in sensor resistance as it becomes immersed. I suspect you do have that and it would be very useful to know how the resistance varies as a function of immersion depth. If halfway was (say) 10M and fully-immersed were 5M then we could work out an appropriate hysteresis range. Again, using a parallel sensor arrangement might make the values more repeatable.

author: okw
author_rank: Frequent Contributor
timestamp: January 17, 2022, 05:13:05 pm
content: Quote from: fourfathom on January 17, 2022, 03:12:40 amI need to keep it exactly as is (tank is completely closed (except a few inlets and outlets). Earth grounded copper tank and a probe (insulated from the the mounting point of course).I could of course hook up a data logger with a voltage divider and see how resistance varies during the water low/normal area.

author: fourfathom
author_rank: Super Contributor
timestamp: January 17, 2022, 06:08:47 pm
content: Quote from: okw on January 17, 2022, 05:13:05 pmIt would be extremely helpful to get this resistance vs level data. With that we can optimize the sensor interface and the amount of hysteresis.You have mentioned using this design in more than one place. Will the tank dimensions be the same? This will most likely affect the probe-to-tank resistance.

author: okw
author_rank: Frequent Contributor
timestamp: January 17, 2022, 06:24:10 pm
content: Quote from: fourfathom on January 17, 2022, 06:08:47 pmI'll try to see how fast I can get to this.Quote from: fourfathom on January 17, 2022, 06:08:47 pmYes, same dimensions and geometry.

author: fourfathom
author_rank: Super Contributor
timestamp: January 17, 2022, 06:34:31 pm
content: Quote from: okw on January 17, 2022, 06:24:10 pmGreat news! This helps a lot.The only other variable will be the water conductivity which will determine the full-immersion resistance, and the effective hysteresis vs level change. Perhaps the variation will be minor...

author: okw
author_rank: Frequent Contributor
timestamp: January 17, 2022, 07:32:07 pm
content: Is there an easy way to add a delay on both ON and OFF? I've seen this same principle (one with LM324 and another with both LM324 + LM358), but they didn't engage the pump until 2-3 seconds after plugging in. Maybe there is possible to add some rise/fall delay on the output? In addition to the hysteresis?By the way, will the lm358 (and the rest) with the current protection survive if the heating element cracks and starts leaking AC current via water to ground? This happens very often (reason no1 for heating elements die, reason no2 is of course burnt heating wire). The GFCI should trip, but many older setups don't have it, or not tripping at low enough currents.

author: fourfathom
author_rank: Super Contributor
timestamp: January 17, 2022, 07:53:58 pm
content: Quote from: okw on January 17, 2022, 07:32:07 pmAs long as you don't need much timing precision a delay could be as simple as putting a series resistor then a capacitor to ground at the comparator output. You are using cmos NOR gates so the RC values should be reasonable. I think you will want to use schmitt-trigger-input NOR gates in that case, but these are available. You will probably need to add a diode and maybe a resistor to ensure proper power-up and power-down behavior. (Are you sure you don't want to use an 8-pin PIC for all this? It would get rid of most of your components and cost less.)240VAC leaking into the water? That's nasty. If the tank is your ground reference then the only real problem is on the sensor input. The protection circuit I showed you can handle moderate transients, but with high-voltage and current more than (say) 10 mA then first the diodes will blow, followed by the 358. Or more likely, the input protection diodes will pump up the +5V voltage to a couple hundred volts and zap every active device on the board. Once we get a better handle on the sensor resistance range we can probably modify the input circuit slightly to make it fairly bulletproof in the broken-heater scenario -- probably by putting a series resistor in line before the diodes and perhaps using higher-current diodes and some sort of clamp (Zener or equivalent).So how are you switching power to the pump and heater? This is important when we are so concerned about grounding and isolation and power-faults. All you've shown us is what looks like an alarm-type beeper.

author: okw
author_rank: Frequent Contributor
timestamp: January 17, 2022, 08:34:56 pm
content: A PIC would be easier and cheaper, but I'm treating this as a project for learning - and I've learned a lot so far. I do software dev all day, so it's fun doing this all old-school.This is my relay and triac circuit. Not everything is calculated yet.

author: fourfathom
author_rank: Super Contributor
timestamp: January 17, 2022, 09:08:22 pm
content: OK, we can look at the protection circuitry once we have better sensor resistance data.About your relay and triac, I'm glad to see the optoisolators! But take a look at OK2 pin 6. You need to connect the opto collector instead. You might want to put a bypass cap on pin 6 but check the device specs -- I believe the base is usually left floating. For that matter, the entire OK2 driver circuit looks "interesting". Why so complex? Why the reverse-diode across the opto input? You are only going to get less than 0.4 mA of opto drive current through Q1, and that's probably not enough. Why not just drive the opto via a resistor from your logic?And Q2 needs some protection from the relay-off flyback spike. There are various ways to do this, all pretty simple.I haven't reviewed the design in total, these items just jumped out at me.

author: okw
author_rank: Frequent Contributor
timestamp: January 17, 2022, 09:56:09 pm
content: Of course, my bad. Pin 5, not pin 6. And I added a 100nF between pin 4 and 6. Seems it would add some noise immunity.The protection diode should be on the relay, not triac optocoupler. A hasty mistake.But yeah, the complex input was probably too much. I removed everything and driving it through a resistor now.

author: Kim Christensen
author_rank: Super Contributor
timestamp: January 18, 2022, 12:18:59 am
content: I don't see the point of OK1 since the relay coil is also connected to the +5V line. Just drive Q2 directly via R13. Yea, and a diode across K1's coil (Cathode to +5V) is a good idea.R12 makes no sense to me. Connect the emitter of Q1 to ground, or just drive the OK2 directly like you did with OK1.

author: fourfathom
author_rank: Super Contributor
timestamp: January 18, 2022, 12:35:09 am
content: Quote from: Kim Christensen on January 18, 2022, 12:18:59 amYes. I agree with all of this. I think okw is now driving opto OK2 directly as you suggest.And yes, the opto for the K1 circuit seems redundant -- the relay will provide the necessary isolation. Since you need the transistor Q2 to handle the 71 mA relay current, just drive the transistor from the logic. The 1K base resistor should probably be dropped down to perhaps 560 Ohms though. I think the cmos logic can source that 7 mA base current.

author: okw
author_rank: Frequent Contributor
timestamp: January 18, 2022, 12:55:35 am
content: The relay optocoupler was there to provide AC noise protection, especially since it's switching high loads (1400w heating element). This is resistive so it probably won't introduce so much noise(?). But the relay will switch only at the transition pump off - heating on. When heating is on, an external thermostat (in series with the relay) will switch on/off separately.

author: okw
author_rank: Frequent Contributor
timestamp: January 20, 2022, 12:37:11 am
content: Any input on this?

author: fourfathom
author_rank: Super Contributor
timestamp: January 20, 2022, 01:42:12 am
content: Quote from: okw on January 20, 2022, 12:37:11 amNot really.I just don't know how much noise is transferred into the relay coil when the contacts are switching high voltage / power, so the following is all guesswork: If it's just a current spike I would think that the flyback protection would suffice (and perhaps a second diode to ground if the spike went negative). If it's a common-mode surge that somehow forces ground-current than you're going to need more than an opto since the relay and drive transistor are still connected to +5 and ground -- but your power supply isolation should prevent that.

author: okw
author_rank: Frequent Contributor
timestamp: June 05, 2023, 11:52:58 am
content: Finally I had time to realize this into a PCB.Sadly the 555 timer doesn't start countdown unless the 555 trigger (signal !AUTO_FILL_ON) goes high again.But !AUTO_FILL_ON is dependent on water level sensor and will stay low until water level is satisfactory.I see some designs adding a pull up and a capacitor to make it an edge-trigger, but I can't manipulate the !AUTO_FILL_ON as this is part of the NOR gate to compare !AUTO_FILL_ON and PUMP_ENGAGE.When both are low (pump is running but water level is still low after ~60 sec), it gives a buzzer alarm + pump stops.Any idea how to fix the 555 circuit?

author: Kim Christensen
author_rank: Super Contributor
timestamp: June 05, 2023, 03:33:51 pm
content: Since this is an old thread, was this the circuit you built? Or were there additional changes?

author: okw
author_rank: Frequent Contributor
timestamp: June 05, 2023, 05:06:30 pm
content: Somewhat modified, but yes more or less.Except R8 is connected to the IC1A output (instead of between the NOR gates).Also, I put a resistor R10 between IC1A output and IC4D input, and a capacitor (not assembled) between this resistor / IC4D input and ground.R10 is now 0R, but was advised 8.2k for wider hysteresis band, have to experiment how much I need.All opamp/NOR gate inputs has been properly grounded / etc. for more stable operation.I didn't modify the 555 timer in the attachment, this is the PCB i received.

author: Kim Christensen
author_rank: Super Contributor
timestamp: June 05, 2023, 10:19:55 pm
content: Quote from: okw on June 05, 2023, 11:52:58 amI've edited your diagram because the Net-Names were not helping me follow the circuit. I'll have to look at this again a bit later, but my edits may help others:

author: okw
author_rank: Frequent Contributor
timestamp: June 05, 2023, 10:39:05 pm
content: It's easier to follow in Eagle, than on a separate imageR24 is not mounted, just a backup solution if timeout and alarm isn't needed (and 555 timer isn't mounted).

author: okw
author_rank: Frequent Contributor
timestamp: June 12, 2023, 12:57:34 pm
content: Quote from: Kim Christensen on June 05, 2023, 10:19:55 pmDid you have a chance to check it out?

author: Kim Christensen
author_rank: Super Contributor
timestamp: June 12, 2023, 10:47:30 pm
content: Quote from: okw on June 05, 2023, 11:52:58 amI think this would be the easiest way to fix the problem. Does the PCB layout prevent you from inserting at small capacitor between the "!AUTO_FILL_ON" wiring and pin 2 of the 555 by cutting the trace, and also adding a pullup between pins 2 & 4 of the 555? Or you could bend pin 2 of the 555 up before soldering it to the PCB... It wouldn't be very pretty though.It's too bad that the power pins on a 555 are opposite that of a PIC12F675 (Or similar 8 pin MCU) because it would be trivial to program one to replace the 555. Hmmmm... Is the PCB set up for a through-hole 555? If so, you could mount a PIC12F675 from the solder side and then the power pins would be the correct polarity. But this would require MCU programming, which might be an issue if you don't have the tools/skills for that.

author: okw
author_rank: Frequent Contributor
timestamp: June 12, 2023, 11:28:56 pm
content: Quote from: Kim Christensen on June 12, 2023, 10:47:30 pmYes, I can do both the cap and pullup. So I'll try that tomorrow and see how it goes.Actually, I'm avoiding MCUs this time as I've programmed my fair share. I flet it was time to go old-school and learn a bit new (old) stuff.

author: okw
author_rank: Frequent Contributor
timestamp: May 03, 2024, 11:12:49 am
content: A follow up on this. I finally managed to redesign and test the circuit. I decided to temporarily remove the 555 time-out alarm as the trigger needs to be toggled to start counting, not just stay low. And it's not a critical feature now. I could have removed the 7402 inverter and pulled the optocoupler (PUMP_ENGAGE) and relay signal (!AUTO_FILL_ON) directly after R9, but I left the inverter in place, as I hope to get the timer working later.However, I see 426mV on the optocoupler when it should be 0V. On high, I see 1.15V which is the forward voltage of the LED, so all good. I'm not sure if this will cause any issues with the optocoupler.I removed R19, and the optocoupler input is 0mV. What's the trick here? If there is a simple mod for the existing PCB it would be good.And a more fundamental redesign for my next revision?Also does the relay transistor need a pull-down?

author: Kim Christensen
author_rank: Super Contributor
timestamp: May 03, 2024, 03:39:46 pm
content: Quote from: okw on May 03, 2024, 11:12:49 amI assume you mean 426mV across pins 1&2 of the optocoupler. If so, this shouldn't be a problem since 426mV is not enough to light the LED in the opto and turn its TRIAC on.QuoteThe reason for the 426mV across pins 1&2 of the optocoupler is because R19/Q1 is loading the output of IC2B (pin4) when it goes high.This means pin-4 only goes up to 4.574V (5V - 426mV assuming a 5v supply)Like I said, it's not really a problem, but if you changed Q1 to a MOSFET and eliminated R20 this "problem" would go away.Another option would be to increase R19 to 1.2k (assuming a worst case beta for Q1 of 20) which would reduce the current draw from IC2B. (pin4). This would reduce the voltage to something lower than 426mV.QuoteIf the output of IC2B (pin4) doesn't go lower than apx 700mV when it's low, then Q1 will not turn off. R19 & R20 can form a divider so that the voltage on Q1's base is less than 350mV when pin-4 goes low.

author: okw
author_rank: Frequent Contributor
timestamp: May 03, 2024, 04:26:34 pm
content: ThanksQuote from: Kim Christensen on May 03, 2024, 03:39:46 pmIf I replace Q1 with either 2N7002LT or BSS138LT1G, what should I be considering? I guess 1k base resistor is OK? And drop R20 (or 100k)?Is MOC3083 (zero-cross) and Z0103MN a suitable choice for a 240V 48W vibration pump (on max 1-2 min worst case, usually 3-10 sec every 30 min)?Regarding the values for snubber (R25/C2), gate bleeder (R21) and backlash (R23), I just used what was in the datasheet, but that was for resistive loads. Any enhancements here?The datasheet says R25 (39R) should be increased to 360R with highly inductive loads. I don't know if mine is highly or slightly.

author: Kim Christensen
author_rank: Super Contributor
timestamp: May 03, 2024, 07:45:29 pm
content: Quote from: okw on May 03, 2024, 04:26:34 pmThe BSS138LT1G is a better choice due to it's lower gate voltage turn-on requirements. You can safely leave R19 at 560and eliminate R20.I'll leave the TRIAC questions for others to answer...

author: okw
author_rank: Frequent Contributor
timestamp: May 06, 2024, 01:16:52 pm
content: Quote from: fourfathom on January 15, 2022, 03:43:18 pmI have a question. I've played around with the circuit you attached. I put a potentiometer in place of the inverting input pull-up and removed the feedback resistor. Found out at 17.1k pull-up on the inverting input it switched when water level was perfect. So I'll put in a 18k resistor (no need for perfection). Then a potentiometer in place of the feedback resistor and 1M seems to give an OK hysteresis. I also added a 100k/10uF RC delay on the output (after the feedback resistor).Anything to consider when having such a gap (18k/1M) on the divider?I also put a 1206 0R resistor in series before the 1k you drew up, and a 32V zener to ground. And a 1206 0R resistor between earth ground and logic ground. Are those reasonable for added input protection?Given the worst case scenario (rupturing heating element, momentarily 240V into the water (earth ground) before the 20-25mA ground fault circuit breaker kicks in.

author: okw
author_rank: Frequent Contributor
timestamp: May 29, 2025, 03:59:16 pm
content: Quote from: fourfathom on January 20, 2022, 01:42:12 amI'm reviving this old thread. 5 boards has been in use in different locations for a year now, with just a minor hick-up, once every 2-3 months or even less frequent. The LM358 doesn't detect the correct LEVEL_SENSOR and kicks in the pump to restore the water level, and leaves it engaged "forever", until the user turns it off and back on. That usually resets it. And it seems this faulty detection only happens at power on, not randomly after some uptime. Some users leave it on permanently from e.g. 8am-5pm, while others turn it on for 30 min, then off again after use (2-3 times daily).I was thinking maybe the voltage divider (820k/1M) on the level sensor is too high, that it sometimes doesn't supply enough current to the LM358 input (especially at power on, with the 5V supply module dipping - but that should affect both dividers)? Or will the 100k/100k be stronger at fluctuations/dips?