Author Topic: Design help with basic logic gates for a simple aquarium pump controller.  (Read 8080 times)

0 Members and 1 Guest are viewing this topic.

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
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 line


However 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.

Edit I've noticed my mistake with the override, currently working on fixing that. |O
« Last Edit: April 07, 2018, 02:18:42 pm by Enlargee79 »
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
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.
« Last Edit: April 07, 2018, 02:53:07 pm by picandmix »
 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
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 happen
 1. 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.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
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 ?

 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
No, I don't have one yet. 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.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
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

 
The following users thanked this post: Enlargee79

Offline tautech

  • Super Contributor
  • ***
  • Posts: 28141
  • Country: nz
  • Taupaki Technologies Ltd. Siglent Distributor NZ.
    • Taupaki Technologies Ltd.
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.)
Avid Rabid Hobbyist
Siglent Youtube channel: https://www.youtube.com/@SiglentVideo/videos
 
The following users thanked this post: Vgkid, Enlargee79

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
Thank you :)

Of 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 libary https://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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
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?
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
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.
 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
"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 lost  :-//
and 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 all :(

Also 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.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
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.
 

Offline tautech

  • Super Contributor
  • ***
  • Posts: 28141
  • Country: nz
  • Taupaki Technologies Ltd. Siglent Distributor NZ.
    • Taupaki Technologies Ltd.
But just look how sexy this PCB is.
Maybe 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 pad and visible 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 ?  :scared:
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 ?

Avid Rabid Hobbyist
Siglent Youtube channel: https://www.youtube.com/@SiglentVideo/videos
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us

Maybe to you but my mentor would call it gawd awful !


I 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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
"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 lost  :-//
and 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 all :(

OK, 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.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4003
  • Country: gb
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/146514

R1 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: [Select]
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 regardless
digitalWrite( 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 LED
if( !digitalRead( SW_NORM ) {
    if( ! digitalRead( SUMP_HIGH_SWITCH  )  && ! digitalRead( TANK_LOW_SWITCH ) ) {
       digitalWrite( RELAY, HIGH );
       digitalWrite( PUMP_ON_LED, HIGH );
       return;
   } else {  // switch them off
       digitalWrite( 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 loop

When 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 find :)

EDIT2:  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 voltage :)  It will also wear out the relay.
« Last Edit: April 08, 2018, 10:45:39 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 
The following users thanked this post: Enlargee79

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4003
  • Country: gb
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 <-- Plug

Though, 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.
« Last Edit: April 08, 2018, 10:54:28 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
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 condition
  • Status indication LEDs showing that either switch is closed
  • A general "things are all good" status LED
  • A big honkin' OFF switch in case there a shit-fan episode
  • Optionally: 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 LED really since 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.
 
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
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.)
 
The following users thanked this post: Enlargee79

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4003
  • Country: gb
Wow that's a lot of info. Clearly this is not straightforward.

Breadboard, 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 meantime :)

The $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.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 
The following users thanked this post: Enlargee79

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
*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.
« Last Edit: April 08, 2018, 08:33:48 pm by Ian.M »
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
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.
 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
Wow that's a lot of info. Clearly this is not straightforward.

"Breadboard, breadboard, breadboard.  Prototype and play.  Soon however the addiction starts with multi-meters (essential), then a scope, then ... then..."

Got one coming, along with loads of hookup wires. I will definitely be testing out my ideas before ordering any PCBs.

"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."
Sound advice, and I already do/did that. In my original design I quadruple checked which terminals were which on the relay and tested with a 9V battery.

"The $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."
I ordered one that seems quite popular, and plenty of folks have videos of them switching mains voltage, and continue to post videos - so they appear to still be alive at this point. I'll post pictures once I get them, particularly so Ian can scruitinise the construction.

"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."

I may or may not steal your ideas.

So... Integrating the ideas and advice from this thread, I've redesigned and come up with this (below). But even if it works as I imagine, then there's still the issue of hysteresis, and although fancier this design would be functionally equivalent to the original, but with 20% more bling. Bling is nice, but not really the intended design purpose. Basically, if there's something that triggers a shut-off event, then it should latch in that state until manual intervention. That was indeed the driving force behind making this thread in the first place, but we got a bit sidetracked.

I should also point out that I still have the two transistors in the design (at least the thinking is) so that the indicator LEDs can be activated independently. I'm probably doing this wrong but I couldn't get my head around not using two for this objective.
« Last Edit: April 09, 2018, 01:10:13 am by Enlargee79 »
 

Offline BradC

  • Super Contributor
  • ***
  • Posts: 2104
  • Country: au
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.

 
The following users thanked this post: janoc, Enlargee79

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4003
  • Country: gb
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.
« Last Edit: April 09, 2018, 06:40:36 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline tpowell1830

  • Frequent Contributor
  • **
  • Posts: 863
  • Country: us
  • Peacefully retired from industry, active in life
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...

« Last Edit: April 09, 2018, 08:52:16 am by tpowell1830 »
PEACE===>T
 
The following users thanked this post: Enlargee79

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Don't forget the current limiting resistors for those diodes which I assume must be LEDs.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4003
  • Country: gb
I wonder what the simplest solution to get the Tank and Sump float switches to have LEDs independently is.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11790
  • Country: us
I wonder what the simplest solution to get the Tank and Sump float switches to have LEDs independently is.

Could 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.
 

Offline mrkev

  • Regular Contributor
  • *
  • Posts: 225
  • Country: cz
I wonder what the simplest solution to get the Tank and Sump float switches to have LEDs independently is.
Can you use float switches with opposite polarity (so they would conduct when the water is at the level you don't want)?
 

Offline mrkev

  • Regular Contributor
  • *
  • Posts: 225
  • Country: cz
I wonder what the simplest solution to get the Tank and Sump float switches to have LEDs independently is.

Could 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.
The 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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
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.
 

Offline mrkev

  • Regular Contributor
  • *
  • Posts: 225
  • Country: cz
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/y8wwwpmc

On 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.
 
The following users thanked this post: Enlargee79

Offline tautech

  • Super Contributor
  • ***
  • Posts: 28141
  • Country: nz
  • Taupaki Technologies Ltd. Siglent Distributor NZ.
    • Taupaki Technologies Ltd.
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.
Well 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.  :)
Avid Rabid Hobbyist
Siglent Youtube channel: https://www.youtube.com/@SiglentVideo/videos
 

Offline BradC

  • Super Contributor
  • ***
  • Posts: 2104
  • Country: au
The 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.

Every 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.
 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au

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.

It's quite ok. I have thick skin, and of course my noob PCB is going to be flawed. I really only designed it to see if I even could design 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.

Cool simulations

On 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)
1. 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/yd7q87br I 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.

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.
I 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.

Things that you should always consider when making PCB:
  • Sage PCB advice
I'm hoping that I get to a point where I can actually implement this advice. Particularly, adding mounting holes is a legitimately good idea :)
 

Offline mrkev

  • Regular Contributor
  • *
  • Posts: 225
  • Country: cz
It's quite ok. I have thick skin, and of course my noob PCB is going to be flawed. I really only designed it to see if I even could design 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.
Hey, 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.

1. 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 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?
ad 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/yd9hqhqn
Hitting 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).

I 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.
If 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).
 
The following users thanked this post: Enlargee79

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
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 a thyristor (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).
 

Offline Enlargee79Topic starter

  • Contributor
  • Posts: 24
  • Country: au
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/yd9hqhqn
Hitting 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).

Ha! 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/y7oc33a8

I 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 :p

I 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. :D
 

Offline LiamKelly

  • Newbie
  • Posts: 1
  • Country: us
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 a bristle worm, he solved it with fashion! :D I think it's great and wish you luck!
« Last Edit: July 30, 2020, 05:39:54 pm by LiamKelly »
 

Offline Ground_Loop

  • Frequent Contributor
  • **
  • Posts: 642
  • Country: us
The relay wired as shown will never close the load circuit.  You need to attach to the armature leg in the center.
« Last Edit: July 21, 2020, 10:29:50 pm by Ground_Loop »
There's no point getting old if you don't have stories.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf