Fundamentals

Latching Circuits

Several methods to make latching circuits

Daniel Koch

Issue 65, December 2022

A selection of latching circuits for single-button on/off switching applications. - by Dan Koch.

We're bringing you a Fundamentals instead of a Classroom this month, because the content here doesn't really fit our criteria for Classroom. We are going to present some different latching circuits. Not logic data processing latches like you would find in the 74 or 4000 series ICs, but the kind of circuit you might build if you want to turn a circuit on and off with a single momentary tactile button, for example.

LATCHING BASICS

A latch is a device or situation with two stable states that can be manually actuated to change between the two. It is not limited to electronics, as even the spring-loaded devices used for handleless kitchen cupboard doors are a latch. Think the type you push on, then the spring pops the door open enough to get your fingers onto. There are plenty of other situations to find if you look around, too.

In electrical terms, one of the most common and simplest latches is the humble switch. Switches are either momentary, or latching. If the state stays after you activate the switch, it's latching. So, the basic toggle switch is almost always a latching device, although momentary ones exist too. Pushbuttons are spread between both categories, but rocker switches are most often latching, too. Almost all domestic light switches are latching rocker switches.

So why then, do we have electronic ones? In many cases, this is for data processing. Latches are the basic unit of memory in logic circuits, and we will recap them soon. However, they are not our primary focus. Electronic latching circuits for power have a different emphasis. Sometimes, this is so a stand-by power supply can be kept running to keep time, volatile memory, or the like.

In other circumstances, it allows an auto-off feature, because the input to the latch can have parallel inputs from both a button and a timer. Some people cite cost as a reason, and in some regions and times, this is true. However, at current market prices we have found no examples outside Ali Express or the like where you can buy the components for less than the price of a toggle switch. Also, if you place value on your time, the situation changes further.

The ability of the latching circuit to keep some parts of a circuit active and be controlled by manual or electronic signals is one of the most appealing reasons to use a latching circuit. The other is related, in that the parallel inputs are unlimited. If you have a circuit that needs to be turned on or off from many different places, wiring small momentary pushbuttons is easier than wiring interconnected latching switches.

Think of a hallway, where you may wish to turn lights on or off from either end. The standard way of doing this is with two latching switches (usually rockers in domestic mains lighting), and is shown here. If either switch is moved, the circuit is made or broken.

If you need more than two switches, however, you will need special intermediate switches, designed with a mechanism inside which rotates by 90° every time the switch is actuated. This makes or breaks the circuit much like the previous version. In both cases, a length of twin-core is used between the switches, and a single core is used at both ends. In mains wiring, this is required to be twin active, and single double-insulated (SDI) respectively.

Replacing this with a latching circuit means that the lights are controlled by the latching circuit, and any number of any type of momentary switch can be used to activate the circuit, as long as they are wired in parallel.

RECAP - LOGIC LATCHES

Many logic-level IC latches are available, with most having several points in common. They generally have two outputs, one labelled 'Q' which is the main output, and some have another labelled 'Q' which is the inverse of 'Q'. If Q is high, Q is low. Most also have two inputs, and are a Set/Reset operation (SR latch). This means a high is needed on one input, the 'set' input, to set the latch one way, then a high is needed on the other input, the 'reset', to toggle it back. There are all sorts of other types of latches but most are a variation on this theme. The JK latch, for example, is an SR latch with gated inputs which need to be enabled for any change to take place, so they can be controlled more easily and protected from spurious data. You cannot generally just connect the set and reset inputs together, because both would receive a high at the same instant and the latch would not respond, or would respond unpredictably.

There are a variety of other latch ICs, and they are generally sold in packages with two or four together in one IC.

Latches are also called flip flops, although the two terms actually differ. While often seen as synonymous terms, latch means that the inputs are live all the time and change is instant, while flip flops are enabled in some way on command and only read inputs and change outputs at this instant. Most latch/flip flop ICs are really flip flops, using some form of clocking and used for serious data storage so that the change only happens on command. You can make most of the latch types available with other logic ICs, like AND gates and so on, but there is little reason to besides for the sake of the exercise and learning process. We covered logic latches and flip flops in some depth in Issue 57.

THE RELAY LATCH

Relays can be used to make a pseudo-latch, one which is manually started but automatically stops. This has its applications for some situations but needs to have power manually removed to reset the relay. It is, in fact, not a one-button latch but a Set/Reset latch. The reset is performed by a limit, reed or float switch, however, and by some action not manually controlled by the operator. This basic circuit has uses like manually turning on a water tank fill pump, then using a float switch to turn it off when full. One of the DIYODE team uses this circuit with a pushbutton in the side of their power meter box, and a limit switch in the cover. When the meter reader comes and opens it, the relay drops out and the light goes off, indicating that the property's access gate can be locked again.

When the pushbutton is pressed, current flows to the relay coil, which closes the contacts. Current now flows from the supply, through the normally open relay contact, to the coil, even after the button is released. The switch on the other side of the coil is a normally open switch, in this case, held down by the lid or door and is therefore closed during this operation. Alternatively, it could be a normally closed type which opens when activated, like a float switch on a full water tank. In either case, at the start, the switch is closed and the current flows out of the coil and to ground, completing the circuit. The latch only resets when the power is removed, or when the reset switch is activated.

For a single-button on/off relay latch, there needs to be a bit more going on. There are quite a few very simple designs floating around the internet, but most present a brief short-circuit during activation which will shorten the life of the switch and some types of power supply. There are latching relays available as pre-made devices. Some have two inputs, because there are two coils inside, and the contacts are moved depending on which coil is energised externally. Others have internal contacts and one set of inputs, so that the decision of which coil to activate is handled internally. However, these are not common on the domestic market.

The most reliable way to make a single-button on/off latching relay is by adding some semiconductors. Some people want to avoid that for various reasons but as noted above, there are no simple relay-only circuits to do the job that are not without appreciable caveats. However, by adding semiconductors, we have lost most of the argued advantages for using a relay in the first place. If you need really high current without using a MOSFET, then a relay as an output stage on any of the following circuits would be just fine. All of the options which do not involve semiconductors use more than two relays.

USING LOGIC FLIP FLOPS

This circuit uses a flip flop IC and turns it into a latching circuit with power output. We're cheating a little here. Of the many types of flip flop, all are gated and so need a clock pulse to work. They only change state, depending on what the other inputs are doing, when the clock input is pulse. However, in this circuit, we use the clock input as our switch input, and tie all other inputs to known places.

The D flip flop has one state input, two outputs with one being the opposite of the other, and a clock input. Many also have S and R inputs but if not needed, these can be tied to ground. If we tie the input to the Q output, which is the opposite of the Q output, then every time the clock input receives a high, the output will change state. The D flip flop will change the Q output to whatever is on the D input when clocked, which is why we need to use the Q output. If we used the Q output, the state would never change! Most flip flops will trigger on the rising edge of the clock pulse but you can find examples which trigger on the falling edge. That means low going to high, or high going to low. It is the edge that triggers, so the length of button press is irrelevant.

It is possible to use flip flops to make a latch. Most flip flop ICs have gated inputs and need a clock

In practice, it is not that simple. We experimented with this for a while. We found a few reference designs online, but few worked on a breadboard at all, and none worked well. There are several challenges. The biggest is that the input pulse from the switch is much longer than the clock input needs to be. This is fine in theory, because the clock should only change on the rising or falling edge. However, that rise time is often long enough that the outputs are changing state too. Unless the flip flop has schmitt inputs, or is fitted with a schmitt trigger input as a separate IC, the outputs can feed back to the inputs during the clock cycle. This creates an unstable state and the output often stays on, ignoring further button presses.

In addition, many of the flip flops on the domestic market have other quirks, which require careful reading of datasheets to know if it will behave in the expected manner. All of the challenges have solutions, but we had so much success with some of the other circuits that it was not worth the time and effort to pursue this. We have a basic circuit diagram here just to show the concept, but note that it has no part numbers. It is a concept only and needs work before it will function as intended.

BJT LATCHING CIRCUIT

Parts RequiredIDJaycar
3 x 1kΩ Resistors *R6, R8, R9RR0572
1 x 4.7kΩ Resistor *R3RR0588
2 x 100kΩ Resistors *R4, R7RR0620
1 x 200kΩ Resistor *R5RR0627
1 x 240kΩ Resistor *R2RR0629
1 x 430kΩ Resistor *R1RR0635
1 x 1µF Capacitor *C1RE6032
2 x BC547 NPN TransistorsQ1, Q3ZT2152
1 x BC557 PNP TransistorQ2ZT2164
1 x BC337 NPN TransistorQ4ZT2115
1 x Pushbutton Switch *-SP0600
1 x 12V Light Globe-SL2685

You can build a latching circuit with Bipolar Junction Transistors (BJTs), the most common category of transistor that most makers use. If you search online for 'transistor latching circuits', you will find plenty of results, and they look invitingly simple. However, the vast majority showing a single button are like the relay latch circuit, requiring power to be disconnected or the addition of a separate button in order to reset the circuit.

This circuit is more complicated, but it is a true one-button transistor-based latch. To do this, we need the use of a capacitor. When current is first applied, all transistors are off and the capacitor C1 is charging via R1 and R2. The circuit stays in this state. R7 exists to ensure stability, feeding a small voltage to Q2's base to ensure it stays off when idle.

When switch SW1 is pressed, the voltage on the now charged capacitor is presented to the base of NPN transistor Q3 through R6. Some current will also pass through R5 to ground and R4 and R3 to Q1 but the high values of R4 and R5 in comparison to R6's 1kΩ make this negligible. Q3 is now turned on, which allows current to flow from emitter to base in PNP transistor Q2, through R8, R9, and Q4, which is an NPN output stage with a higher current capacity than the other transistors.

Now, the current flowing through the emitter-collector path of Q2 keeps Q3 on, via R4 and R6, latching the circuit. The current also flows via R3 to Q1, turning it on. This drains the charge from C1 via the 240kΩ R2, through Q1 to ground, but not instantly thanks to the high value of R2 and the fact that current can flow from Q2 via R4 through the switch to keep the capacitor charged. Thus, after the button is released, the circuit is latched on but C1 falls to 0V potential.

When switch SW1 is pressed again, the capacitor voltage is again presented to the base of Q3. This time, however, that voltage is 0V and the capacitor can sink current, meaning that the current from Q2 via R4 will drain to the capacitor rather than the higher-impedance R6/Q3 path. Q3, therefore, turns off, which turns off Q2 because its emitter-base current can no longer reach ground, and Q1 is turned off too. This resets the circuit to 'off' and allows C1 to charge again.

We found that this circuit works reliably but did need some component changes depending on the output transistor used. You might light to tweak other values too, for stronger saturation on some of the transistors, but this will be situation-specific.

MOSFET LATCHING CIRCUIT

Parts RequiredIDJaycar
3 x 100kΩ Transistors *R1, R2, R3RR0620
1 x 10µF Capacitor *C1RE6066
2 x BC547 NPN TransistorsQ1, Q2ZT2154
1 x IRF9540N P-Channel MOSFETQ3ZT2467
1 x Pushbutton Switch *-SP0600
1 x 12V Light Globe-SL2685

This MOSFET latching circuit is conceptually similar to the BJT version above, but is aimed more at controlling power to a whole circuit rather than a specific load or section of a circuit. The MOSFET is the ideal component for that, thanks to its low losses and minimal heat when turned on fully.

Under normal circumstances, the P-Channel MOSFET Q3 is held in the off state by the 100kΩ resistor R2, and the capacitor C1 is charged by the 100kΩ resistor R1. We're pretty used to N-channel MOSFETs in DIYODE pages, which are turned on by applying a voltage to the gate, but P-channel MOSFETs turn off when a gate voltage is present. They need a path from the gate to ground for charge to dissipate in order to work.

That path comes when the pushbutton switch SW1 is pressed. This supplies current to the base of Q2 via R1, and turns on Q2. The gate of MOSFET Q3 is now low, and so the MOSFET turns on. This supplies power to the load, but also to the 100kΩ R3, which is connected to the base of both Q1 and Q1, both BC547s.

The capacitor is important here, because Q1 being on would ground, through the pushbutton, Q2's base and thus instantly turn it off/ However, the voltage across the capacitor dumps through Q1 and it takes time to do so, maintaining a voltage at the collector and switch junction until the switch is released. However, the capacitor is not being charged up again, because Q1 is shorting it to ground. Next time the button is pressed, the base of Q2 is grounded because there is no longer a voltage here, and it turns off, allowing the gate of Q3 to be pulled high by R2 and turning off the circuit. We are now back to where we started.

When we built this circuit, we found it a bit unreliable. Sometimes it worked exactly as intended, while another built on a different breadboard with a different batch of components, turned on but not off. In fact, it turned off quickly with a button press but came back on immediately. When power was reset, it stayed off until the button was pressed. We chose this one because it's very simple, but it may be a bit too simple. We have no idea why one worked and another did not.

INVERTER LATCHING CIRCUIT

Parts RequiredIDJaycar
1 x 1kΩ Resistor *R3RR0572
1 x 33kΩ Resistor *R1RR0608
1 x 510kΩ Resistor *R2RR0637
1 x 100nF Capacitor *C1RM7125
1 x TIP31C NPN TransistorQ1ZT2285
1 x CD4069 Hex InverterIC1ZC4069
1 x Pushbutton Switch *-SP0600
1 x 12V Light Globe-SL2685

This latching circuit makes use of inverter ICs, and not a lot else. The circuit is also self-debouncing, a feature which some of the options presented here have and others do not. On power-up, the first inverter has a low input, and therefore a high output. The high output flows to the input of the second inverter, which is then held with its output low because the input is high. The capacitor C1 charges through R2.

When the pushbutton is pressed, the capacitor voltage is transferred to the input of the first inverter, showing as a high on its input. Now, its output switches low. That low is presented to the input of the second inverter, the output of which now goes high and is connected by the feedback resistor R1 to the input of the first inverter, holding this in the high state after the pushbutton is released. At this point, the capacitor is discharged and stays that way because it is connected to the low section between the two inverters. The inputs are fairly high-impedance, so only a small capacitor is needed when compared to some of the other circuits shown in these pages.

The next time the button is pushed, the capacitor presents a lower impedance to the current through R1 than the input of the first inverter, so it charges, dropping the voltage at first. Before it can charge up again, the output of the first inverter goes high in response to the low input. Now, the capacitor can charge through R2, but slowly because of its value. The input of the second inverter is now high, so its output goes low, removing the high provided by R1. As the button is released, this state is maintained and the capacitor charges through R2 ready for next time.

While very simple, this circuit is somewhat sensitive to the length of the button press. If the button is held, the circuit may show a tendency to oscillate. We have added a transistor drive output stage here with another pair of inverters in between. The CD4069 has six anyway, so it isn't really a penalty. The advantage of doing so is maintaining a buffer between the output of the second inverter and the output stage, so that the (relatively) low-impedance path through the output transistor does not adversely affect the feedback network. Some makers choose to omit this second pair of inverters, and others choose to only use one inverter. One does the job but means the output will be high on power-up.

One of the advantages of this circuit is that it can be configured so that it starts in the on or off mode. The fact that the buffer stage consists of two inverters means that you could cut one out and connect the transistor to the third inverter rather than the fourth. Choosing one or the other decides whether the output is high at power up, and the first button press turns it off, or vice versa. You could even use jumpers to pick and choose during use.

NAND LATCH

Parts RequiredIDJaycar
2 x 1k Resistors *R3, R4RR0572
2 x 100kΩ Resistors *R1, R2RR0620
1 x 100nF Capacitor *C2RM7125
1 x 1µF Capacitor *C1RE6032
1 x BC547 NPN TransistorQ1ZT2154
1 x BD140 PNP TransistorQ2ZT2190
1 x CD4011 Quad NAND gateIC1ZC4011
1 x Pushbutton Switch *-SP0600
1 x 12V Light Globe-SL2685

In a variation of the previous inverter circuit, a logic latch can also be made with NAND gates. The circuit shown here is the same one commonly used in electronics trade and engineering courses in many regions, and only a few

examples even use different component values! It functions almost the same way as the inverter circuit. In fact, the NAND gates have been made into inverters by the connection of their inputs. The same can be done with NOR gates.

NE555 LATCHING CIRCUIT

Parts RequiredIDJaycar
1 x 1kΩ Resistor *R4RR0572
2 x 10kΩ Resistors *R2, R3RR0596
1 x 100k Resistor *R1RR0620
1 x 100nF Capacitor *C2RM7125
1 x 2.2µF Capacitor *C1RE6042
1 x TIP31C TransistorQ1ZT2285
1 x NE555 Timer ICIC1ZL3555
1 x Pushbutton Switch *-SP0600
1 x 12V Light Globe-SL2685

When an NE555 first powers up, its output is low. The two 10kΩ resistors hold the trigger and threshold inputs both at half the supply voltage, while we know they function at one third and two thirds of the supply voltage respectively. However, when the button is pressed, these two combined pins are exposed to whatever the output voltage is. The first time, the output is low and not just low as in 'not high, just off' like some logic ICs, but connected to ground so that it sinks current. This means that pin 2 sees less than one third supply voltage, and the internal flip flop changes state. The output now goes high. However, there is a capacitor, C1, connected here as well. This starts to charge, via the 100kΩ resistor R1, and therefore the voltage does not increase above two thirds until after the button is released (unless you hold it).

Now, the output at pin 3 is high and the capacitor is charged via R1. When it is, the voltage at the junction of R1, C1, and SW1 will be the output voltage. Next time the switch is pressed, this voltage is presented to pins 2 and 6, with pin 6 now seeing its conditions for activation and setting the flip flop. The voltage is maintained very momentarily because the capacitor discharges through R1 into the now current-sinking pin 3, slowly enough to allow time for the button to be released before the voltage falls to one third supply.

One of the great things about this circuit is that the NE555 is pretty hard to kill, and can handle a source/sink current of 200mA. However, using all of this to drive a thirsty load risks altering the conditions by which the capacitor charges and discharges, so it is best to still use a transistor output to drive even smaller loads above 50mA or so. We have used the TIP31C, a 3A transistor with a fairly low gain, hence the smaller-than-common base resistor R4, to allow a high enough current to the base.

As expected with anything with an NE555 in it, this circuit was very reliable and rugged. The output can be used directly for the small 100mA 12V globe we used for testing, and if your circuit draws less that around 180mA, leaving some current for the charging components when they spike, then you do not even need the output transistor. Additionally, the output could drive either N or P channel MOSFETs, making this a favourite of ours from the whole selection.

OP AMP TOGGLE SWITCH

Parts RequiredIDJaycar
1 x 1kΩ Resistor *R10RR0572
7 x 10kΩ Resistors *R12, R3, R4, R5, R7, R8, R9RR0596
1 x 220kΩ Resistor *R6RR0628
1 x 1MΩ Resistor *R1RR0644
1 x 100nF Capacitor *C1RM7125
1 x IRF9540N P-Channel MOSFETQ1ZT2467
2 x UA741 Op AmpsIC1, IC2ZL3741
1 x Pushbutton Switch *-SP0600
1 x 12V Light Globe-SL2685

By using positive feedback and an op amp, a different latching circuit can be made. This one is based on the UA741, an outdated but rugged, cheap, and accessible op amp. It was superseded long ago for audio or signal processing but its price, durability, and continued widespread availability mean that it is in the parts box of many makers. When used as a comparator, its shortcomings as an op-amp are rarely relevant. This circuit isn’t quite a comparator, but close, and again the shortcomings do not get in the way.

Initially, the output is low. The gain is set quite high, with some of the output fed back to the non-inverting input via R6. The non-inverting input is held at half the supply voltage by the voltage divider formed by R3 and R4. There is also 10kΩ of resistance between the middle of this voltage divider, and both the inverting input through R2 and the non-inverting input through R5.

Therefore, the output voltage fed through R6 to the non-inverting input is the only difference. Because it is a high-gain amplifier, there will generally have been enough noise on power-up that the output would have gone high at some point. With the output low, capacitor C1 is at 0V potential. When push button switch SW1 is pressed, this voltage is passed to the inverting input. Because the non-inverting input is held at half the supply, the inverting input is now well below, at 0V, and this is inverted and amplified, meaning the output swings to nearly Vcc. Now, C1 is charging through R1.

Because of the two 10kΩ resistors R2 and R4 providing a ground path, C1 will not charge significantly, and definitely, not above the reference voltage at the non-inverting input, this state stays the same until the button is released. The output state stays locked, because there is positive feedback to the non-inverting input via R6. The capacitor, however, is now free to charge to the output voltage. Next time the button is pressed, this voltage is presented to the inverting input, and is well above the reference voltage at the non-inverting input. In fact, it is the full output voltage, so that is inverted, and the output goes low. Now, the circuit is back where it started.

The output is sent to another UA741. This one is set up as a comparator and its sole purpose is to buffer the output. Using transistor drives directly here alters the performance of the first op amp, because alternative current paths are then provided. The high-impedance inputs of the op amp stop this happening, and its output drives the MOSFET directly. With only a small current and a decent sized gate resistor, turn-on is slow as the capacitance at the gate times time to charge. However, for on/off rather than PWM applications, it's still ok. You could also build it with a small MOSFET driving the power MOSFET, or a transistor drive.

NOTES, DEBOUNCING AND OUTPUT STAGES

Most of these designs use a pushbutton switch as depicted, but any input can be used in most cases. For example, another MOSFET arrangement could be employed if there is some sort of control circuitry connected to a microcontroller on the always-powered side of the output stage, or a bipolar transistor option will usually work, too. Then, the circuit would have wake-on-command capability as from a timer or network signal monitored by the low-power, always-on circuit. Exactly how this should be implemented will vary depending on which circuit you choose or even which input source is available and the end-use circumstances.

If a pushbutton switch is used, some circuits are inherently debounced by default, while others need the button to be debounced for reliable operation. In particular, the circuits which use a capacitor as part of their switching operation are likely to operate reliably without debouncing, while others which feature direct connection between signals may oscillate or false-trigger with a plain pushbutton. Debouncing with a capacitor of between 1nF and 100nF depending on the noise and quality of the switch is generally sufficient, with the capacitor connected straight across the switch terminals. The D Flip Flop circuit is an example of this.

The output stages can generally be anything you want. MOSFETs, bipolar transistors, and relays will all work in most cases. Just consider the output current capability. So, a relay will likely need a drive transistor and a MOSFET needs to have its substantial gate current considered. The op amp circuit, for example, will not drive the gate of a IRF540N MOSFET terribly quickly. This is why the MOSFETs here are usually driven by another transistor. Speed is not such an issue with circuits like these, so BJTs are perfectly adequate for driving the gates of the MOSFETS, which will not be turning on and off anywhere near fast enough for operation in the linear region to become an issue.

When it comes to MOSFETs, however, consider the gate drive voltage. As we detailed in Classroom issue 32, just because a MOSFET has a gate threshold voltage of, say, 3V, does not mean it is fully on at 3V. In fact, this is where the gate starts to charge and at 5V, the MOSFET is almost certainly still in the linear region and generating a lot of heat for current passing through it. It will also, being in the linear region, not be able to pass its full rated current, but rather a percentage of that. Most of the circuits presented here are detailed for 12V but can be used for 5V or even 3.3V with the correct component choices.

ORIGINALITY AND CAUTION

These are a selection of many of the circuits around which can function as a latching switch. There are many more, but some floating around online are terribly designed and asking for trouble. Some we found didn't look right to us and on testing, did not even work! We have adapted or altered these designs here because at this simple level of electronics, there is no 'reinventing the wheel': Someone has already come up with every possibility somewhere, and the laws of physics and the available components mean that coming up with something new is nearly impossible. As a result, if you are doing your own research, you will likely find circuits which look similar but have a few differences. This does not mean one is right and one is wrong, but always be cautious because anyone can put anything on the internet, even if it is wrong!

FINAL WORDS

Don't hesitate to adapt and experiment. Just because we showed a circuit with a bipolar transistor output does not necessarily mean that it can only be used that way. Most of the time, the outputs are adaptable. Some of the component values are critical, while in other circuits, they're flexible and the behaviour of the circuit, like the minimum or maximum length of time a button press can be, can be changed.

We hope these building blocks can further your electronics projects by providing an additional way to control power to your circuits or part thereof. Whether you need to use another circuit to control power on and off, or whether you need to use a momentary waterproof button because you can't access the right one that latches, these circuits are a good starting point.