# Converting Momentary Switch to Latching

Hi ,
Is there a simple way to convert a momentary push button switch to a latching switch?

1 Like

Hi Brian,

There are a few options out there, but each has their trade-off so it depends on your application which is more sensible.

If your switch is an input to a microcontroller then you can use code to handle the debouncing and remember the switchâ€™s â€śvirtual stateâ€ť so it behaves like a latching switch.

If you need a physical solution you could build a circuit to remember the switch state using a flip-flop memory circuit.

There are also off the shelf options like the Pololu Pushbutton Power Switch modules that let a small momentary switch behave like a larger mechanical latching switch.

Finally, because we never discount the most simple answer, you can try and find an actual latching switch instead.

1 Like

Hi Trent,

Yes, i could buy a couple of latching switches but already have the momentary switches so would like to utilise them.
One switch is to turn on and off the main 12v power coming into a control circuit for an automated water pump system, the other is a bypass switch for the pump if i need to top up water.

Thanks

Brian M

1 Like

hi @Brian225828
Here is a simple python code snip to make an external input behave internally as a latched switch.
It will only change on rising transitions of the debounced input pin - i.e. a 0 â†’ 1 transition.

``````# init
Q = False;	# the pseudo 'switch' state
i = 20;

def pulseQ(t):
global Q;

if t == 1:
Q = not Q;

while i != 0:
T = 0;			# this is the debounced input pin state
pulseQ(T);
print(T, Q, i);	# printing the input pin, the 'switch' state (and the loop counter
i -= 1;
T = 1;
pulseQ(T);
print(T, Q, i );
``````

and a run of the snip

``````%Run junk.py
0 False 20
1 True 19
0 True 19
1 False 18
0 False 18
1 True 17
0 True 17
1 False 16
0 False 16
1 True 15
0 True 15
1 False 14
0 False 14
1 True 13
0 True 13
1 False 12
0 False 12
1 True 11
0 True 11
1 False 10
0 False 10
1 True 9
0 True 9
1 False 8
0 False 8
1 True 7
0 True 7
1 False 6
0 False 6
1 True 5
0 True 5
1 False 4
0 False 4
1 True 3
0 True 3
1 False 2
0 False 2
1 True 1
0 True 1
1 False 0
>>>
``````

cheers
Murray

2 Likes

Thanks Murray

Thanks

Brian M

1 Like

Hi Brian
If you donâ€™t mind a bit of hardware the Texas Instruments data sheet for a 4013 dual flip flop has a latching circuit, push on push off style

There are 2 flip flops in this package, one for each switch.
The resistor/capacitor and the first IC is a filter and schmidt trigger to de bounce the switch. The Q output would drive a Mosfet switch/relay combination to switch power to your pumps which you are going to need whichever way you go about latching anything.
Cheers Bob

3 Likes

Okay thanks will have a look.

Thanks

Brian M

1 Like

Hi Brian
That SN74VC1G17 is a single non inverting schmidt trigger and I think only comes in little surface mount package.

the more common schmidt triggers are 6 devices in a 14 pin DIP package and are inverting. You can use these by connecting 2 devices in series. I would suggest input to 1A, connect 1Y to 6A and take the output from 6Y. You have 2 buttons so use another 2 for the second button, that leaves 2 unused, I suggest use 1 and 6 in series then 2 and 5 or 3 and 4 this allows to connect straight across the IC package and keeps things tidy.
The one I would suggest is 74HC14.
Both the CD4013 (or just 4013) and 174HC14 are readily available from Jaycar

The resistor and cap in that circuit would not be all that critical and I would start with 10kÎ© and 0.1ÂµF (100nF). This should be enough but if you still get a little bit of bounce increase the 0.1ÂµF a bit.
Cheers Bob

2 Likes

Hi Brian
Thought the name rang a bell.
If that second push button is the override button to start the pump if your rain water tank is not quite full this button does not have to latch It will do so with the latching contacts in the pump start relay I think is RL 1.
Cheers Bob

1 Like

Hi Robert,
Yes, you are correct with the second switch being for the pump override. Iâ€™ll wire this in as indicated on the schematic. With the main switch Iâ€™ll have a look at the info you sent through and decided if i look at converting or buy a switch that is latching.

Thanks

Brian M

1 Like

Hi Robert
Does it matter what type Cap is used, i.e. Monolithic, Electrolytic etc.?

Thanks

Brian M

1 Like

Hi Brian

I thought this looked familiar and when you mentioned main power and pump /water the penny dropped.
Yes this switched when wired as per schematic will energise the pump relay which in turn will latch and continue until one of the switch off conditions is met.

But it will not start if
There is no water in the rain water supply tank.
Both water tanks are full.
Basically any condition that would stop the pump during normal operation.
Cheers Bob

1 Like

Hi Brian

Monolithic or Polyester. These go to 1ÂµF and 1.5ÂµF which would be plenty. If you needed more I would throw the switch away. You should not have to go much above 0.1ÂµF or about 0.22ÂµF at most but if you have to go a bit more it is OK as it is still quicker that you can remove your finger.
You should not have to get into electrolytic values.
Cheers Bob
PS: This is getting to be fairly exotic to switch power on and off as you will still need a relay or something to do the actual switching. Even if the push button contacts are heavy enough it is not the button switch that actually latches but the flip flop output. Originally I was thinking of a larger (about 10A or so) toggle switch.

1 Like

Hi Robert,
Thanksâ€™ again for the information and your assistance. Yes, the more i delve into it i think it would be better to look for a suitable latching switch for the main power supply isolation as you suggested i will look for something more suitable.
I was just trying to use what i already had in my spares box thus the question about converting a momentary to latching.

Thanks

Brian M

HiBrian
Yes sounds easy when you say it quick. You could use a button switch to latch a relay as I had done with your main circuit but you need a second button with normally closed contacts to unlatch it. If you want to use the same button the only way is some form of latching electronics and the simplest one I know is the 4013 as suggested. A very useful IC is that 4013, keep it in mind.
Pleased to help when I get feed back such as yours.
Cheers Bob

Thanks Robert,
I might get the components and have a bit of a play with the switch i have and see how it goes. I think the switch i have will be heavy duty enough as it is a 12v industrial switch so should be okay.

Thanks

Brian M

Hi Brian
You only need a lightweight switch to drive the latching electronics.
As I said it is not the switch that latches but the flip flop output. You have to drive something else to do any real switching of any sort of current. You wonâ€™t be able to switch your 12V supply with that switch directly and have it latch.

By the way that â€ś3Vâ€ť indicated on that TI circuit above can be 5V if you need.
Cheers Bob

Okay thanks

Thanks

Brian M

Hi Brian
Sorry, must have had a complete brain freeze (a bit more than a senior moment).
That latching circuit needs to be powered all the time to work.
But you are turning the power on and off. OK to turn off but how do you turn it on again with no power.

I do have one excuse though. I did answer your original question.

It is only my knowledge of exactly what you are trying to do that leads me to later replies. So armed with this knowledge and the preference to keeping things simple (especially as any malfunctions are likely to occur when you are miles from nowhere in your caravan) I would suggest procuring a mechanically latched push switch or a suitable toggle switch.

If you prefer button consider the emergency stop units. They push off and require the mushroom bit to be rotated to restore contact. Have a look at Jaycar SP0786 which can apparently be wired either way as it has NO and NC connections.
Cheers Bob

1 Like

Hi Robert,
Yeah, Iâ€™ve been looking at some switches and would like a push button. Iâ€™m not in a hurry so will keep my options open for now. Thanks again for your time and assistance.

Thanks

Brian M