Design help with basic logic gates for a simple aquarium pump controller. - Page 1
Forum section: electronics / beginners

author: Enlargee79
author_rank: Contributor
timestamp: April 07, 2018, 02:07:17 pm
content: Hello all,I've gotten a bit stuck trying to design this, as I am beyond noob grade when it comes to circuit design but at the same time I'm massively curious and have plenty of simple electronics (emphasis: simple) experience.I have built an aquarium pump controller that is as basic as it gets, with 2 float switches in series that will interrupt a low voltage supply for a relay that switches AC240V. If either the tank runs high or the sump (a lower filtration tank, for those non-aquarist) runs low, either will break the relay control circuit and therefore inhibit the pump. There is a status LED that only lights if the entire circuit is closed, so it's a little pointless but I couldn't figure out how to have an LED work for either switch 10 years ago, and just went with a single in-line LED.Anyway, the circuit's simplicity makes it fantastically robust, and it's still working well nearly 10 years on.This is the schematic: (screw terminal refers to the pump)I've designed a better version that now will have an LED that works in lineHowever I've decided I'd like to make a fancier version. One of the problems with this design is lack of hysteresis: when either switch triggers, the pump is stopped however the water continues to flow. So, if there is a partial blockage of the drain, at some point the water can still flow down to the sump, which will then restore the normal circuit and start the pump again. This results in the pump stopping and starting every minute or so, until the problem is corrected. I would prefer to have the switches latch in the off state, and light up a fault LED (+/- piezo alarm) corresponding to whichever switch was tripped; I would also need a reset switch so as to restart everything once the fault is fixed.With some homework and reading, I've enhanced the original design with more status LEDs and a rudimentary AND gate. There is also some more feedback lighting with a 3 position switch that can either force the pump on or off.So I'm thinking that a simple latch eg. S-R will do the trick. If either switch outputs a 0, then the output should switch from the normal running state (Q -> power to relay) to alarm state (not Q -> power to something else) , with a momentary reset button on the front to return to Q state with manual intervention.EditI've noticed my mistake with the override, currently working on fixing that.

author: picandmix
author_rank: Frequent Contributor
timestamp: April 07, 2018, 02:47:46 pm
content: Hi,Can see the idea behind your switches, though cannot say I have seen anyone making such a device before.Your problem of the repeated off/on slow draining needs a small delay which could be built in with caps etc, but looking at the extra parts already used then I would just use a little $5 Arduino Nano or Uno which allows you total timing control.Obviously you could do so much more with the Arduino at the same time, temp control, lighting , if you haven't got that already.Its very easy to use and could give you some float switch code to work with if it seems too daunting to get going.

author: Enlargee79
author_rank: Contributor
timestamp: April 07, 2018, 05:08:43 pm
content: Thank you for your reply.I have toyed wiht the idea of using an arduino before, but then I thought - let's start with somthing a little more straightforward in a sense using discrete components. Seriously pondering it but I think I'd need to do far more preparation work to understand controlling *things* via software.BTW the issue with slow draining might not have been clear with my previous explanatin. Perhaps it is best explained with an example.The pump runs continuously, as long as both of the float switches are closed. Two things can happen1. Drain blocks. Water slowly fills the main tank until the upper float switch cuts power, but in order to get to this point ~10 or so litres excess is in the upper tank. If the pump had kept going then it would overflow, but the pump has cut off. The excess water will slowly drain down over, say 30 seconds or so. At this point the level drops and the switch closes again, starting up the pump and overfilling to the point that the upper switch cuts out again.2. Sump runs dry - over time and with evapouration eventually the circulating volume is low enough that the pump would run dry. To prevent this, there is a float switch in the lower tank, which cuts power below a certain level. However, similar to above there is some amount of water (eg 10 litres) still draining from the upper tank. The same cycle happens where the pump starts flowing, pushing some amount of excess into the upper tank before the switch cuts out again. This then flows down and starts the pump again, until there is not enough in the lower tank, causing another cut off.It's not a common approach to this issue, because people usually will have a sump that has at least enough capacity to catch all the excess in the case of a pump failure. I was able to get away with a smaller and simpler sump by creating the cut off circuit, and consequently I can have a much higher water level in the tank without risking an overflow.

author: picandmix
author_rank: Frequent Contributor
timestamp: April 07, 2018, 07:18:05 pm
content: Hi,Yes , do understand your problem, been reef keeping for many years, though as you say, most overcome such a problem by having good spare capacity in the sump, or are just lucky they don't have a fish stuck in the return pipe .For your circuit I would have thought that you need the float switch configured so that it allows voltage , via a resistor to slowly charge a capacitor, eg 10-30 seconds or so before it built up enough voltage to turn on the transistor, a method use in simple burglar alarms.If you want a few minutes, then probably using a 555 timer would be simpler.Do you have an Arduino tucked away ?

author: Enlargee79
author_rank: Contributor
timestamp: April 07, 2018, 07:45:08 pm
content: No, I don't have oneyet. The more I watch videos about this the more it seems like it would be a more efficient way to do this.Even though I have a pretty sweet PCB designed in easyEDA.

author: picandmix
author_rank: Frequent Contributor
timestamp: April 07, 2018, 08:00:10 pm
content: Hi,Was just by my little Arduino so just done this simple code for you to look at, its only got the odd user comment , so if its not clear let us know, the file opens in Wordpad etc.You can see whats called the Serial Monitor where you can get it to show the actions in progress while the code is running on the Arduino, a handy feature.hth

author: tautech
author_rank: Super Contributor
timestamp: April 07, 2018, 08:38:23 pm
content: Have a play with the gate simulators here until you find the gate types and configurations that does what you need:https://tams.informatik.uni-hamburg.de/applets/hades/webdemos/10-gates/00-gates/chapter.html(You need Java enabled in your browser.)

author: Enlargee79
author_rank: Contributor
timestamp: April 07, 2018, 09:36:19 pm
content: Thank youOf course I have to wait a week or so for the arduino to arrive, as well as the relay board. I've also got a plan to have it play various wav files via SD card and this libaryhttps://github.com/TMRh20/TMRpcm/wiki- but first the basics.I have normally closed float switches, so I might have to change tank state LOW <-> HIGH in a few places, but this is a massive starter.

author: IanB
author_rank: Super Contributor
timestamp: April 07, 2018, 10:20:37 pm
content: Not quite what you are asking about, but on looking at your new circuit it seems to be "upside down". You have Q1 and Q2 as NPN transistors, yet you have them on the high side of the load instead of the low side. When using NPN transistors as switches they work best when the load is on the collector, not on the emitter.Also, I can't see the difference between SW1 position I and II? To me, both positions look identical?

author: IanB
author_rank: Super Contributor
timestamp: April 07, 2018, 10:25:43 pm
content: Further hints:I would be best to have only one transistor instead of two doing the switching, and then have the logic function on the base of the transistor. Basically (no pun intended), you would have a pull-up resistor on the base to turn the transistor on for normal operation, and if either float switch goes into the "stop pump" position it should pull the base to ground and turn the transistor off.

author: Enlargee79
author_rank: Contributor
timestamp: April 08, 2018, 12:09:02 am
content: "Also, I can't see the difference between SW1 position I and II? To me, both positions look identical?"Yes that was the mistake I was referring to in the edit."I would be best to have only one transistor instead of two doing the switching,"yep, makes sense"and then have the logic function on the base of the transistor."umm"Basically (no pun intended), you would have a pull-up resistor on the base to turn the transistor on for normal operation,"ok now I'm lostand if either float switch goes into the "stop pump" position it should pull the base to ground and turn the transistor off.- I'm sorry, but I don't understand that at allAlso while working on this I've made a few changes. I knew that in all likelihood I would have chosen the wrong kind of transistors - that was guaranteed from the outset. The choice for two of them was to work as an AND gate, and also so that each LED can light when the respective switch is on. That's probably clearer in my updated version.Also, picandmix sure has made a compelling argument to scrap this idea and go with an arduino based approach.But just look how sexy this PCB is. Never in a billion years would I imagine designing my own PCB.

author: james_s
author_rank: Super Contributor
timestamp: April 08, 2018, 12:54:43 am
content: Once you've designed your first PCB, you can do it again even easier. I would rework most of that circuit, if you want to stick with discrete logic at least follow the advice of using just one transistor, put it on the low side and then use logic to control it. You should also have a diode across the relay coil to prevent spikes from damaging the transistor.

author: tautech
author_rank: Super Contributor
timestamp: April 08, 2018, 01:57:13 am
content: Quote from: Enlargee79 on April 08, 2018, 12:09:02 amMaybe to you but my mentor would call it gawd awful !As James said you need a back EMF diode on the relay.Edit many of the footprints to allow for a larger annular ring around the holes and some of them look oversize too.0.7mm hole works for many TH components.Component placement could be improved to allow better/neater routing.Try to resist placing more than a single trace to any pad and instead route like on the DC1_9V rail.Even with an overlay try to have important signifiers near an padandvisible even after the PCB is populated. (K, +, (pin)1 etc). In the absence of an overlay they can be done in copper alongside the appropriate pad.What's with the 2 different LED symbols ?Have a good think about what you need visible in the overlay....the R&C#'s not so much but the value, yes !Two good things to keep in mind for a PCB.What could PCB rework (repair) of my PCB be like.....would any components need to be removed in order to access another ? Can I get to it easy with an iron, DMM, test grabber and so on.Is there enough info on the PCB should I loose my documentation or someone else need to repair it ?

author: james_s
author_rank: Super Contributor
timestamp: April 08, 2018, 04:45:52 am
content: Quote from: tautech on April 08, 2018, 01:57:13 amI think that's a bit harsh. For a first PCB I'd call it rather good, sure there's room for improvement but PCB design takes practice. I've certainly seen worse boards from people who have done more of them.

author: IanB
author_rank: Super Contributor
timestamp: April 08, 2018, 05:24:38 am
content: Quote from: Enlargee79 on April 08, 2018, 12:09:02 amOK, you have your one transistor. You need to connect the emitter to the negative supply rail (where you have the ground symbol) and you place the relay coil between the positive rail and the collector. (In simple terms, put the transistor at the bottom, under the relay coil.)Now, the pull-up resistor is simply a resistor from the transistor base to the positive supply rail, of sufficient value to saturate the transistor and make it fully on.Next, to turn the transistor off when required you connect its base directly to the negative rail, causing it to be at 0 V. You do this with the float switch contacts. You can put both contacts in parallel between the transistor base and ground. Then either float switch closing will turn the transistor off, and thus interrupt the current through the relay coil.

author: paulca
author_rank: Super Contributor
timestamp: April 08, 2018, 10:29:30 am
content: A few thoughts.... as a beginner myself, so I might have made a few mistakes.LED 3 can never be lit, or is that a schematic anomaly? There is a path to bypass it regardless of transistor state so 0V will form across it. I would remove the bypass trace between D1 and the end of LED3. Also, no need for R3 as you have already current limited the circuits back at LED1/2 with 360Ohms. Note this limits the relay ON current also. The relay resistance might change the brightness of the LEDs as it will drop some voltage. Probably quite small though.The path to "ON" has to traverse 2 transistors + 1 diode + 2 LEDs (although one of them currently won't work). So the total voltage drop could be as high as 5V, More likely 0.7*5 = 3.5V leaving 5.5V for the relay to engage with. Actually the LEDs drop much more than 0.7V, blue LED will drop nearly 3V on it's own.Relay might need a flyback diode across the coil. The coil acts like an inductor, when energised it will hold charge, so when you suddenly remove the current from it it will might spike a large voltage backwards. D1 (and LEDs) "might" block it, depending on the coil it can be kilo volts!, but normally you put a diode reverse across the coil so the voltage just spins around in the diode until it decays. When the relay is powered current will flow through the coil. When it is off it will discharge itself backwards in a short circuit with itself.https://electronics.stackexchange.com/questions/146499/relays-flyback-diode-is-it-necessary/146514R1 and R2, the purpose of these is to stop the large amount of current that can flow from the transistor Base to Emitter. They need to be speced to be low enough to saturate the transistor, but not much more than that. It does then beg the question, if you are limiting the current that can flow from Base to Emitter with a resistor, just so the transistor can switch the un-restricted current from the same source.... you don't need a transistor at all. Transistors are used when you want to use a lesser current source to switch a higher one. Such as from the pin of a Microcontroller which couldn't power the relay. In your case you are just using switches, which can easily supply the relay on their own.I had a play with a schematic and the only difficulty here that can't be done with 2 switches are the LEDs for various states. However in your circuit LED5 will only light if LED4 is also lit. This can be done with switches, but I would assume you would want to have TANK_LOW, SUMP_HIGH, PUMP_ON LEDs independently.The Arduino, being fully digital micro-controller allows you to do all this stuff in software. Although depending on the relay coil current you might need a transistor to drive it and the flyback diode. A mosfet is probably easier to deal with, a logic level mosfet will work without current limit as it doesn't pull or leak current through it's gate like a normal bipolar does through it's base.You would then just need to connect your S1 and S2 to ground when on, floating (disconnected) when off, set the Arduino pins to internal pull up. Similar for the outputs of SW1, to ground when on. On output pins, you put current limit resistors for LEDS ( TANK LOW, SUMP HIGH, PUMP ON, RelayCoil ).Code:void loop() {// Depends on whether these float switches are on (LOW) or off (HIGH) for these states.// ! means NOT, ie, the reverse, I have assumed the switches pull LOW when on// Set the tank and sump status LEDs regardlessdigitalWrite( SUMP_HIGH_LED, !digialRead( SUMP_HIGH_SWITCH) );digitalWrite( TANK_LOW_LED, !digialRead( TANK_LOW_SWITCH) );// Override? Switch pump relay and it's LED on.if( ! digitalRead( SW_OVRDE ) ) {digitalWrite( RELAY, HIGH );digitalWrite( PUMP_ON_LED, HIGH );return;}// Normal mode, if pump AND sump are on, put pump relay on and it's LEDif( !digitalRead( SW_NORM ) {if( ! digitalRead( SUMP_HIGH_SWITCH ) && ! digitalRead( TANK_LOW_SWITCH ) ) {digitalWrite( RELAY, HIGH );digitalWrite( PUMP_ON_LED, HIGH );return;} else { // switch them offdigitalWrite( RELAY, LOW );digitalWrite( PUMP_ON_LED, LOW );return;}}// Remaining state is Over-ride off. No action. Although you could pulse an LED to show this state.} // end loopWhen doing a PCB one of the hardest parts is making absolutely sure your foot prints match your actual components. For example will that surface mount fuse holder fit the exact one you buy? LED 3 will never light.EDIT: There is a bug in the code, but I'll leave that up to you to findEDIT2: The other thing you will need is an "anti-short-cycle" to prevent ripples on the water surface and "switch bounce" from toggling the relay rapidly. Without the flyback diode this would be a good way to make a hipster aquarium switched boost converter to generate high voltageIt will also wear out the relay.

author: paulca
author_rank: Super Contributor
timestamp: April 08, 2018, 10:52:32 am
content: Oh, one final thing.The way you have wired the pump obviously won't work, unless pin 1 and 2 are remote switch pins on the pump.You will need:Plug ---> Mains Live -> FUSE --> Relay -> Pump <- Mains neutral <-- PlugThough, this opens arguments about mains polarity and depends on which country you are in and mains standards, but it might be better to send the Mains Live to the pump, then neutral via the relay, so that a water leak in the pump will cause a short to earth in the pump and blow the plug fuse or trip your RCD without any voltage going through your board.I might also consider mounting the relay off board, so you can handle the board without worrying about mains voltage.

author: Enlargee79
author_rank: Contributor
timestamp: April 08, 2018, 06:25:19 pm
content: Wow that's a lot of info. Clearly this is not straightforward.Just to get it out of the way - transistors baffle me somewhat. I know *how* they work, what they do, in general terms but the finer point of choosing a correct base current and specing the appropriate limiting resistor is still a bit mystifying.The only reason I went with two transistors is because that would make an AND gate. The nice part about that is that LED4 and LED5 could then act as a "this switch is currently closed, all's well" independent of each other. That works flawlessly in my EEImagination, although real life is probably in disagreeance.I can put a diode across the relay, that's no drama - I didn't know that was even an issue.I messed up with LED3 - it's obvious now. Originally it was in series with the relay, but I can't remember why I put it out parallel like that.As depicted the pump/fuse circuit probably doesn't represent the connection faithfully. The relay is set up to break/connect the active wire, and neutral simply goes back to the original cord. I do like the idea of having the AC portion completely separate but I was practicing with some of Dave's concepts of AC separation.This is basically my design philosophy:Have two floats that can independently switch off the pump in either an upper tank overflow or sump underrun conditionStatus indication LEDs showing that either switch is closedA general "things are all good" status LEDA big honkin' OFF switch in case there a shit-fan episodeOptionally: an override to turn the pump on manually, in times of troubleshooting but this isn't even necessary (just plug the pump into a normal socket).As it stands, my basic version performs the task adequately. No need for a status LEDreallysince the pump working is evidence enough of the pump working.I've oredered an arduino and I think that's the best way for me to get a fucntional system as per the above design. I'm not an electronics engineer; my field of expertise is actually in servicing the wetware (I'm a physician), and electronics is a hobby. Naturally I'm time-poor so I don't have a lot of free time to really study the finer points of discrete logic. I was hoping that I could build a functional latch using a reasonably simple approach with a couple of logic gates. With an arduino I can do some other fancy things that wouldn't be remotely feasible (for me) with regular parts.As for switching a relay with the arduino - that's solved using an off the shelf relay module for $5.The electronic components as they are, are sealed in an IP66 container. I've had an overflow a couple of time, which amusingly was not the fault of my unsightly electronics, but rather leaving the refilling hose connected while distracted. It was a regular power board that got wet, and also was a good test of the RCD fault breaker.

author: IanB
author_rank: Super Contributor
timestamp: April 08, 2018, 07:14:41 pm
content: It's not that complicated really.To use an NPN transistor as a switch, you turn it on by feeding current into the base terminal. Now the current going into the base terminal has to come out again through the emitter (the pointy arrow terminal) and return to ground. For the transistor to work efficiently as a switch there must be no obstacles in this current path. No other transistors, no relay coils, no resistors. The pointy arrow terminal must be connected directly to ground (the negative supply rail). (It must go directly to ground, must not pass Go, must not collect $200 on the way.)So you have your transistors Q1 and Q2 in exactly the wrong place. There is lots of stuff in the way between the pointy arrow terminal and ground.Secondly, about the AND gate. You don't need two transistors to make an AND gate. One is enough. Also, an AND gate is equivalent to an OR gate. So you can make your circuit use an OR function instead. Consider:"The pump is running if float switch 1 is good AND float switch 2 is good.""The pump stops running if float switch 1 activates OR if float switch 2 activates."See?So all you have to do is arrange that the single transistor Q1 is on while both float switches are open circuit, and turns off if either float switch closes. This is what I described in my earlier post. (This requires that you set the float switches to be open when the level is normal and closed when the level is abnormal. But I expect you can do this.)

author: paulca
author_rank: Super Contributor
timestamp: April 08, 2018, 07:29:22 pm
content: Quote from: Enlargee79 on April 08, 2018, 06:25:19 pmBreadboard, breadboard, breadboard. Prototype and play. Soon however the addiction starts with multi-meters (essential), then a scope, then ... then...If you hadn't ordered the Arduino already I would suggest ordering one with an "Electronics starter kit." Which will come with a bunch of components and a breadboard. You can order the electronics kit separately for 20 dollars or so."Good" breadboards cost about £10/$18. Cheap ones look like a bargain and they work "okayish", but can be frustrating when meerly touching your board causes miss-connections and everything has to get wiggled around to contact properly.On the relay and mains. The relay will happily switch 5V or 12V too, so while testing things on the bench, until you are 100% sure it's all fine, use a battery and a torch or an LED or something to test it with. Leave the mains until last.I think you are right, however it's contraversial in our current audience, but Arduinos make things so much more simple than analogue stuff like NPN transistors. Things are usually 1 or 0, HIGH/LOW, ON/OFF. It allows you to get stuff doing cool things without having to learn the nitty gritty of electronics engineering. You can still work towards the later while getting cool stuff to work in the meantimeThe $5 relay 5V boards are good, they are "usually" opto-isolated and include the driver transistors. I used one on a Raspberry PI for years to control a beer making fridge.Out of interest I nearly made a similar project as a "Auto water changer" based on a large bucket, heater and various valves and level and flow sensors to cycle the water in a tank. I might at some point return to it. Sort of like a temporary sump just to do a water change without actually manually doing it with hoses etc.

author: Ian.M
author_rank: Super Contributor
timestamp: April 08, 2018, 08:25:57 pm
content: *DON'T* trust $5 relay boards for switching mains. They are often designed by idiots who've never had to follow US or EU rules for safe creepage and clearance distances between mains and low voltage circuits, so may be less safe than a typical dollar store USB charger, and frequently use cheap relays that don't have a snowflake's hope in hell of surviving at the rated current and voltage marked on them. Also, the optoisolation is often useless because the idiot designer has used a common ground and/or supply rail for the input and output sides of the optocoupler, and even when they get that right, they often run tracks under the optocoupler, compromising the clearances required for it to meet its isolation voltage rating. If in doubt, post good closeups of both sides of the PCB here with a ruler in-shot for scale and we can assess its design for you. Ones that I'd trust at more than 50V and 1/3 of the nominal relay curreht rating are *RARE* like hen's teeth.If you want a nice boring life where your circuit doesn't electrocute you or blow up in your face, use an off-board genuine 1st world brand properly rated relay with screw terminals and a DIN rail, or chassis mount - either one piece or socketed, with a plug-in relay.If you fit the off-board relay in an insulating or grounded metal case, with a mains lead in, a fuseholder, two neon indicators, one for power in and the other for load power, and fit a mains socket to the case that meets local safety standards, then use something like a D connector for the low voltage wiring to the relay coil, and insulate and secure everything inside the case so there is absolutely no way the low voltage wiring can touch a mains connection even if a wire breaks, you can safely control it to switch a mains load from your breadboarded circuit.

author: james_s
author_rank: Super Contributor
timestamp: April 08, 2018, 09:22:14 pm
content: When you want to calculate the base resistor, look up the gain of the transistor, 90 is a reasonable guess for most small signal transistors. Then consider the current that your load is going to draw, divide that by the gain and then to make sure you drive it to saturation you might want to double the result, that is the base current you want. The junction is going to drop about 0.6V so use Ohms law (R = V / I) and there you have it. There are other considerations that can matter but for the time being don't worry about that, in practice you might need to tweak the value a bit but that will get you close enough that it will usually work.

author: Enlargee79
author_rank: Contributor
timestamp: April 08, 2018, 11:54:22 pm
content: Quote from: paulca on April 08, 2018, 07:29:22 pm

author: BradC
author_rank: Super Contributor
timestamp: April 09, 2018, 03:39:34 am
content: Why not use a double pole relay and put one pole in series with your float switches. Put a button in parallel with the whole switch chain. That will pull in and stay in when you press the button, and if either float switch opens up the relay drops out and stays dropped out. No transisors, no semiconductors. You could wire it such that the contact that drops out powers the led when the pump is inactive.

author: paulca
author_rank: Super Contributor
timestamp: April 09, 2018, 06:38:53 am
content: I think it's an improvement.For some reason, mostly I hate working with PNP, NPN transistors, I would consider Mosfets for Q1, Q2. Mosfets are voltage driven devices. They have different properties. You generally don't need to calculate gain and base/gate resistance and stuff like that. They don't "drop voltage" across them either.Although you would probably need pull up resistors, but then calculating R1 and R2 just needs them to be significantly lower than the pull up resistors.. or just remove them. The pull ups "pull" the gates of the P-Channel mosfets to 9V (in your case), so they say fully off. Until you pull the gates to ground with the switches when they come fully on.You need to move your load (relay) before the transistors though.Your next step is trawling datasheets. I'd start with the relay. Determine it's voltage, current etc. Then start picking transistors, based on the current and voltage requirements. Work out if they will need heatsinks etc. Then buy a handful of components and test things out on a breadboard.Finally, when you have decided on the components and have a prototype working, you can again check the datasheets for the footprints and layout a PCB.

author: tpowell1830
author_rank: Frequent Contributor
timestamp: April 09, 2018, 08:43:47 am
content: I have modified your original drawing to include the items in red, I have moved the power switch, fixed the 240VAC relay contacts, added labels. You can get float switches that have mechanical hysteresis via a sliding float. Just some suggestions, but thought that I would point out some easy fixes. You need to add resistors for the LEDs shown as diodes "POWER ON", "TANK SW" and "PUMP ON". I got lazy drawing the LEDs.Let me know if you have questions.Hope this helps...

author: james_s
author_rank: Super Contributor
timestamp: April 09, 2018, 06:05:38 pm
content: Don't forget the current limiting resistors for those diodes which I assume must be LEDs.

author: paulca
author_rank: Super Contributor
timestamp: April 09, 2018, 06:07:52 pm
content: I wonder what the simplest solution to get the Tank and Sump float switches to have LEDs independently is.

author: IanB
author_rank: Super Contributor
timestamp: April 09, 2018, 06:29:46 pm
content: Quote from: paulca on April 09, 2018, 06:07:52 pmCould do what household switches do: put the LED and resistor in parallel with the float switch. When the switch is closed the voltage across the LED is zero so it is out. When the switch opens the voltage appears across the LED and it lights up.

author: mrkev
author_rank: Regular Contributor
timestamp: April 09, 2018, 06:41:53 pm
content: Quote from: paulca on April 09, 2018, 06:07:52 pmCan you use float switches with opposite polarity (so they would conduct when the water is at the level youdon'twant)?

author: mrkev
author_rank: Regular Contributor
timestamp: April 09, 2018, 06:45:07 pm
content: Quote from: IanB on April 09, 2018, 06:29:46 pmThe problem with that is that his relay probably works with 20mA (or at least get into "weird" state). He would have to use low current LEDs.

author: Ian.M
author_rank: Super Contributor
timestamp: April 09, 2018, 08:20:33 pm
content: That's an easy fix if you don't mind wasting a bit of power - just put a suitable resistor across the relay coil to keep it well below its minimum operating voltage when passing the LED current. If you want to get cute and waste less power when the pump's running, use a JFET selected for an Idss > LED If, as a current sink.

author: mrkev
author_rank: Regular Contributor
timestamp: April 09, 2018, 09:05:47 pm
content: Since you are using normaly closed switches, you will have to first invert their signal for the LEDs. You could do something like this:http://tinyurl.com/y8jx99uo(100k and 100n are for the reasonable simulation, they would have to be much larger, something like 1M/470u)Or you could improve the slow switch on wit the LED (if you have higher voltage than what you need for relay):http://tinyurl.com/y8wwwpmcOn the other hand, it would be much easier with the reversed polarity floaters (when the water level reaches max, they conduct):http://tinyurl.com/ydcm9lj3(the 100k should be something like 1M and 100n at least 100u, which will give you delay of about 2 minutes)To the PCB and what tautech wrote, I don't think it's an awful design, far from it for a first timer.Things that you should always consider when making PCB:What is the manufacturing method. Are you gonna use company (f.e. I use AllPCB even for my prototypes and with something that I am able to do within few hours myself. Just because of the lazynes and the quality vs. price/time spend)Are you going to solder it by hand or do you have something better.How are you gonna mount that board (you are missing mounting holes, which is good to have even if you don't use them later)If you are making single sided PCB and you are planning to solder it by hand, you need bigger angular rings (around pins of each device). Those tiny ones are almost impossible to drill through and then solder without ripping them of the board. Drill sizes should be just enough to put those components thru, It will be hard to solder if you have too much space around the leg.On the other hand, if the PCB is going to be double sided (even if you don't have anything but the pads on the other side), you can get away with tiny holes - because the solder is going to fill the space inside the pad. In this case, it's good to make those holes a bit bigger in diameter so you have space between the leg and plated hole.If you would to use SMDs, there is a big difference in the footprints for different methods of assembly.

author: tautech
author_rank: Super Contributor
timestamp: April 10, 2018, 04:36:44 am
content: Quote from: mrkev on April 09, 2018, 09:05:47 pmWell done for seeing through my comments and adding further good advice.I never called the design 'awful', instead saying that my mentor would do so and I can tell you that really makes you focus on creating a better layout and taking more attention to detail. I hope the OP can see this too.Doing good layouts is a real craft and I learnt a lot from studying old PCB's in my junk pile to the point now I can look at a board and quickly know if the CAD artist has any pride in their work.One of the most challenging to do when you start is a dense single side board where the routing options can be very limited so much time and experimentation must be spent on placement and orientation otherwise your board looks like it was done by the other side 'jumper king'!Good boards take time and lots of time, but the satisfaction of knowing it can't be bettered is worth it.

author: BradC
author_rank: Super Contributor
timestamp: April 10, 2018, 05:05:39 am
content: Quote from: mrkev on April 09, 2018, 06:45:07 pmEvery red LED in my junkbox puts out a significant (like very usable for an indicator) amount of light at < 1mA. The greens and yellows, not so much.A red or blue Ultrabright at <1mA is well and truly enough for anything not in direct sunlight.

author: Enlargee79
author_rank: Contributor
timestamp: April 11, 2018, 09:08:40 pm
content: Quote from: tautech on April 10, 2018, 04:36:44 amIt'squite ok. I have thick skin, and of course my noob PCB is going to be flawed. I really only designed it to see if Ieven coulddesign a potentially functioning circuit board. I have no intention of sending any design off for building without being 100% satisfied that a prototype would even work. In fact, if I ever get that far I'll be sure to post a picture here for intense scrutiny.Quote from: mrkev on April 09, 2018, 09:05:47 pm1. Holy moley I was looking for a circuit simulator just like this to play around with. I trawled all sorts of places and couldn't find anything that wasn't behind a paywall or otherwise crazily complex.2. Hysteresis isn't a bad idea, and a slow turn on would actually reduce the relatively rapid on/off switching problem quite a bit. I really should have been more clear in stating that a latched error state is better since if it happens, then manual input is going to be needed anyway (ie. add more water or clear the drain blockage).I can't understate the beauty of that design though. When I get my breadboard I'll get some mosfets and try out that 3rd design.https://tinyurl.com/yd7q87brI added some normal state indicator LEDs (green). If I were to use superbrights (which is what I have): Vf 3-3.2, If 20mA, that would require a lower value resistor - but would that interfere with the mosfet at all?It's also entirely possible to reverse the float switches into a normally open state. One of them would be a big pain in the ass to change, but is entirely doable.Quote from: BradC on April 09, 2018, 03:39:34 amI really like this idea because it's simple and therefore robust. I think if that can be integrated with Mr Kev's design #3 that would satisfy all the requirements. One question - is it safe to be switching AC240V on one pole, and 9V on the other? That seems uncomfortably close in proximity. I suppose a second relay could run from the DPST though.Quote from: mrkev on April 09, 2018, 09:05:47 pmI'm hoping that I get to a point where I can actually implement this advice. Particularly, adding mounting holes is a legitimately good idea

author: mrkev
author_rank: Regular Contributor
timestamp: April 11, 2018, 10:20:56 pm
content: Quote from: Enlargee79 on April 11, 2018, 09:08:40 pmHey, I've done my first board 22 years ago, when I was 8yo. And I've done it by physicaly sticking resistors throught the squared paper, drawing the paths with pencil and then redrawing the design on copper board with fix and etching it in ferous chloride. The thing is tho, that you make the most progrees only after you try. And with every board, you get to know what is important in the desing.Quote from: Enlargee79 on April 11, 2018, 09:08:40 pmad 1. It's not anything perfect, but it's great for first design idea.ad 2. Then you want a R-S flip flop (or mono stable flip flop). You can do it with that relay (as someone else mentioned it before), or even with those transistors, since it's really easy. Also, if you are OK with having only "floater OK"signalization, it could be done something like this:http://tinyurl.com/yd9hqhqnHitting the "restart" pushbutton will switch on pump, and if any floater gets open, it will switch off and stay switched off untill you hit the "restart" button again (it's held by small current throught relay and third diode).Quote from: Enlargee79 on April 11, 2018, 09:08:40 pmIf it's safe, that deppends on the construction of the relay and PCB. On the other hand, you should always use DPST relay to switch 230/240VAC and switch both sides (L and N). You never know where the L actually is and you could be switching N, making the pump connected to the mains voltage even if it's switched off. It's in fact required by the law in most states (deffinitely here in EU).

author: Ian.M
author_rank: Super Contributor
timestamp: April 11, 2018, 10:52:31 pm
content: I really wouldn't want to have mains on one pole of an ordinary DPDT relay and low voltage on the other. OTOH that's no problem if you are using a proper contactor - the auxiliary contacts have *PLENTY* of insulation between them and the main contacts, and are intended for control circuit use. However contactors are big, expensive, power-hungry and noisy (an almighty thump when they open or close isn't unusual), so your idea of an auxiliary holding relay with its coil in parallel with the main one is probably preferable.Personally, I'd design the relay circuit to latch on when a fault occurs, and be reset by breaking the coil power rather than manually latching it and a fault causing it to drop out, as otherwise any brief interruption of the mains supply will cause the circulation pump to stop untill manually reset. Its easy enough to rearrange - put N.O. sensing switches in parallel to connect power to the coil when a fault occurs, with a N.O. auxillary contact in parallel with them all to latch the coil on, then use a N.C. contac pair to interrupt the load circuit.An alternative would be to do the latching in silicon. If you use athyristor(or SCR) with the fault conditions triggering it, it could hold the relay coil ON, so that the pump wired via a N.C. contact pair is held off until you clear the fault by removing power from the control circuit. Cathode to ground, Anode to relay coil, and fault switches can either be N.C., (multiple in series) shorting the Gate to the Cathode, with a pullup resistor to +V to trigger it when they open, or you can put a pulldown resitor from Gate to Cathode to prevent false triggering and connect a pullup resistor via a N.O. switch (multiple in parallel) to trigger it. Use multiple thyristors, one for each sensor switch, and add some steering diodes and you could even implement a latching fault indicator LED - they all operate the same relay, but only the one that was triggered lights its LED.Another thing to consider would be to add a SMS dialler so your tank can text you if something fails. A typical SMS dialler requires 12V power, a paid-up SIM card and has several inputs that cause it to send different messages when triggered. However at that point its probably worth making the whole system Arduino based using a SMS shield so you can easily add alerts for over or under temperature, or aeration pump failure (and cut in a backup heater or pump).

author: Enlargee79
author_rank: Contributor
timestamp: April 12, 2018, 01:29:03 am
content: Quote from: mrkev on April 11, 2018, 10:20:56 pmHa! That's perfect. I started this idea with an R-S monostable latch in mind, but I couldn't work out how to implement it into the main design.I tweaked it a little bit:http://tinyurl.com/y7oc33a8I tried putting in a couple of transistors that would switch the green LED to red (I have a couple of two state LEDs), but I just ended up making a bypass to the float switches. I think I'll stick to the Mr Kev Mk3B and just be done with it :pI think I'll get started designing this and try it out on a breadboard. I'll have to get some mosfets though. I'll post an update when I've made a prototype.

author: LiamKelly
author_rank: Newbie
timestamp: July 21, 2020, 02:17:50 pm
content: Hey, that's a great idea, really! I wanna see someone do it! I love aquariums that have been innovated by people who own them, that shows your interest in the success of your work! The aquarium pump controller shouldn't be plain and uninteresting. My friend has an amazing aquarium that was decorated all by himself! Even when appeared a problem with abristle worm, he solved it with fashion!I think it's great and wish you luck!

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: July 21, 2020, 10:24:53 pm
content: The relay wired as shown will never close the load circuit. You need to attach to the armature leg in the center.