Liquid Level Circuit Design - Page 1
Forum section: electronics / projects

author: sirklezero
author_rank: Newbie
timestamp: December 09, 2018, 06:07:00 pm
content: Hello!I'm pretty new to designing circuits, and am working on a project to keep a tank of water filled between the level of two sensors; a min and max level scenario. I have an extensive software engineering background and put together a pretty simple arduino project to do this, but then decided I wanted something a bit simpler, a bit less overkill, and something also where I could learn a few new things. So, I decided to ditch the arduino and design something a bit lower level. I'm hoping someone here could give this a once over and provide a friendly critique of what I'm working on. I've attached the KiCad schema as an attachment.With that said, here's what I've been thinking:The system is based on two optical liquid level sensors, one installed near the bottom of my tank, and one near the top. Both output 0V when exposed to liquid and in my case 5V when exposed to air. I'm looking to keep the water level in between those two sensors, without dropping below the lower, or filling higher than the top by using a solenoid controlled brass liquid valve. Since this is water, and it's in my basement, I'm also concerned about overfilling and flooding my basement, so I've installed a mechanical float valve on the inside of the tank that can mechanically shut the water supply off if it reaches the actual top of the tank (near enough). My experience with these floats is that they are far from perfect and at least the two that I've tried have had leaks that caused them to fill faster than the water is used, causing a small water disaster. All of this is then connected to the utility water connection in the basement for its water supply.On the circuit side of things I'm powering this with 12V. I've then got an LM7805C regulator stepping down to 5V for the logic level portion of things. From there I went for a simple NOR gate SR latch based on the SN74LS02 to handle the logic processing of the sensor output. The LOW sensor is attached to the SET of the latch and the HIGH sensor is attached to the RESET of the latch. From there I've got two LED's connected to the outputs of the latch as indicators. Pretty simple so far, and testing in a cup of water on my bench seems to work great. However, this is where I start having a few questions...My hope is to use the 12V power supply to power the solenoid for the brass valve. At 12V it's sheet says it will draw 3A. So, based on some other recommendations I've gotten I built a MOSFET into my circuit. I've got the output of my latch going to the GATE of my MOSFET, a 10k pull-down resistor between GATE and SOURCE and I've got a 1N4001 kickback diode in parallel with the solenoid to protect the MOSFET.With my, hopefully decent explanation, I'm hoping to get some feedback on a couple things:Is the way I have the MOSFET included in this circuit the right way to do it? I was unsure if the diode would go in parallel or series with the load of the solenoid.I'm not entirely sure how to calculate the heat dissipation for this circuit and this MOSFET to determine if I'll need a heatsink.I'd like to add some headers to this that could be wired up to a microcontroller for monitoring. I have another microcontroller in the basement that does some climate monitoring (it's a woodworking shop), and I think it would be interesting to catch a notification when the tank is filling. I'm just not sure of the best way to do this, would I just connect a header at the output of the latch and monitor it with the microcontroller?Generally speaking, I'd love a critique of the design. I'm SUUUUUPER new to designing circuits, and this is my first project using KiCad, so I'm not sure what I could be doing better both in the design of the schematic and the circuit itself.Ultimately I'd like to make a PCB for this. For this type of circuit, any tips or pointers you might have?This has been a really fun project for me to learn on, and I get something useful for my workshop, so it's a double win. I know I have a lot of questions, and I'm grateful for your time reading all this.

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 09, 2018, 07:39:48 pm
content: "VALVE" (gate of the mosfet) should be tied directly to the NOR gate output.You do not need the 10K resistor tied to the gate.Place a 0.1uf ceramic bypass capacitor directly at the supply pins of the NOR gate.Shield the long run of wire between the two sensors and the inputs to the NOR gates.

author: IanB
author_rank: Super Contributor
timestamp: December 09, 2018, 07:45:17 pm
content: Quote from: Wimberleytech on December 09, 2018, 07:39:48 pmThe 10 k resistor R2 appears to be a pull down resistor to ensure the gate does not float. Seems sensible to me?

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 09, 2018, 07:47:31 pm
content: Quote from: IanB on December 09, 2018, 07:45:17 pmOutput of NOR should not float, but the 10k will not hurt anything for sure...so it is fine.

author: tautech
author_rank: Super Contributor
timestamp: December 09, 2018, 07:49:19 pm
content: Why optical ?Is the liquid non-conductive ?Old thread:https://www.eevblog.com/forum/beginners/which-sensor-to-use-for-salt-water-level/

author: sirklezero
author_rank: Newbie
timestamp: December 10, 2018, 03:55:48 am
content: Quote from: Wimberleytech on December 09, 2018, 07:47:31 pmYeah, I was reading another thing that mentioned that the gate can maintain a charge, and that the pull-down would keep it from latching open once signal stops. Is this true, or am I maybe misunderstanding something.

author: sirklezero
author_rank: Newbie
timestamp: December 10, 2018, 03:59:16 am
content: Quote from: tautech on December 09, 2018, 07:49:19 pmnah, it's just water. I went with the optical ones because, honestly I didn't know any better when I bought them and they looked pretty fancyAt least they work really well.

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 10, 2018, 04:03:31 am
content: Quote from: sirklezero on December 10, 2018, 03:55:48 amThat is a possibility. There is feedback from drain to gate. When the gate is driven low, the drain goes high and if there is enough charge to overcome the output of the NOR, then, yes it is possible to flip the latch.

author: sirklezero
author_rank: Newbie
timestamp: December 10, 2018, 04:06:57 am
content: Quote from: Wimberleytech on December 09, 2018, 07:39:48 pmI tried to do this with a Label in KiCad, and I "think" it routes everything fine, but now I'm wanting to sanity check that! I was shooting for displaying the logical parts of the circuit individually, even though it's not a terribly complicated design.Quote from: Wimberleytech on December 09, 2018, 07:39:48 pmSo, this is something that has always kinda threw me for a loop; when do you need capacitors and when don't you. In this case, how would these capacitors affect the input to the NOR gates? Would I put a capacitor at the junction between the sensor inputs (two of them, one for each) or would I put a capacitor at every input (six of them, one for each input of the three NOR gates)?Quote from: Wimberleytech on December 09, 2018, 07:39:48 pmHow would I do this, just a shielded cable?

author: t1d
author_rank: Super Contributor
timestamp: December 10, 2018, 10:39:55 am
content: I have always thought "capacitive water level sensors" to be interesting and doable. I think that they can be as simple as one piece of metal pipe inserted into another?https://www.google.com/search?q=capacitive+water+level+sensor+circuit&client=firefox-b-1&tbm=isch&tbo=u&source=univ&sa=X&ved=2ahUKEwiMie64h5XfAhUNXa0KHX1xA74QsAR6BAgEEAE&biw=1280&bih=667https://www.instructables.com/id/Capacitive-Fluid-Level-Sensor/

author: tautech
author_rank: Super Contributor
timestamp: December 10, 2018, 10:51:51 am
content: Quote from: sirklezero on December 10, 2018, 03:59:16 amFYI I attach the file from that thread just in case you missed it:A single XNOR IC, 4 resistors and 2 caps.Toggles between 2 states.

author: rhodges
author_rank: Frequent Contributor
timestamp: December 10, 2018, 02:27:36 pm
content: I am doing a similar project. I have a 1000 liter "tote" (International Bulk Container) that I will use as a secondary water tank.I thought about mechanical floats and finally decided to use an ultrasonic distance sensor. The HC-SR04 cost $1.25 on ebay. I will drill two holes on the top of the plastic tank for the transmit and receive transducers. Its board will be on top of the tank, held in place by friction.I did not think about an optical sensor, but I would be concerned that water drops might stay on the optical surface and give a faulty signal.Will the Mosfet saturate with TTL input? A CMOS buffer might be a good idea, or use a P Mosfet and a 2N3904 or 2N4401 to pull down the gate.Off topic: If anyone is interested in using the HC-SR04 with an STM8S103, I have put my library and example code on github. Here is the wiki summary:https://github.com/unfrozen/stm8_libs/wiki/lib_ping:-Control-one-to-three-HC-SR04-ultrasonic-rangefinder-devices.

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 10, 2018, 02:35:27 pm
content: Quote from: rhodges on December 10, 2018, 02:27:36 pmBe sure to post when this project is done!!

author: David Hess
author_rank: Super Contributor
timestamp: December 10, 2018, 08:04:01 pm
content: When I was reading your description, I immediately thought "set-reset flip-flop" but I might have made it with discrete transistors or high voltage CMOS logic so no regulator is required.Where to place the reverse EMF suppression diode depends on the application. In this case with a slow acting solenoid, across the solenoid is the best place. The low voltage drop across the diode makes for a low decay time but that is irrelevant here. A zener diode or resistor in series with the diode could be used to raise the reverse voltage and decrease the decay time. A diode across the transistor would direct the decay current into the positive supply which may or may not be acceptable.Unless you use a really small power MOSFET, heat sinking should not be required. The only real question is power dissipation while turned on which depends on channel resistance which can be absurdly low such that no heat sinking is required.

author: sirklezero
author_rank: Newbie
timestamp: December 11, 2018, 04:02:36 am
content: yeah, my project is for a humidifier to help maintain a consistent'ish relative humidity in my workshop where I build classical guitars. I've got a dehumidifier element to it as well; it gets super dry during the winter here, and super humid in the summer, so the climate management is always a tug of war.

author: sirklezero
author_rank: Newbie
timestamp: December 11, 2018, 04:10:22 am
content: I really appreciate the feedback of this group so far, thanks everyone!It seems like, other than adding some caps at the inputs of the NOR gates (which I'm still a little fuzzy on), it seems that for the most part this should work out really well for me. I think I might poke around with some of the other ideas for water level detection, this is a learning project after-all, so the experience will be well worth it regardless of the end outcome.Can someone help me understand how the caps benefit the circuit in this case? Is it a protection for the inputs of the NOR gates from something going wrong on the sensor side of things?

author: IanB
author_rank: Super Contributor
timestamp: December 11, 2018, 04:16:15 am
content: Quote from: sirklezero on December 11, 2018, 04:10:22 amThe caps don't go on the inputs, they go on the power supply pins. Essentially place the capacitor between the power (+) and power (-) pins of the IC, as close to the IC as possible. These are "bypass" capacitors, they help to prevent high frequency glitches in the supply messing up the operation of the chip. Such glitches can be caused when the logic gates switch state (they draw a pulse of current when they switch).

author: raptor1956
author_rank: Frequent Contributor
timestamp: December 11, 2018, 06:45:13 am
content: Quote from: t1d on December 10, 2018, 10:39:55 amFuel quantity sensors on aircraft use capacitance sensors to measure fuel level. The probe has contoured plates so that variation in tank geometry is figured in. In addition, a compensator capacitor is used to compensate for fuel density as the temperature changes. Ultimately this arrangement provides a fuel reading by mass that is more accurate than by level alone.Brian