A simple "On-Off" push-button circuit is easily implemented with a D-type flipflop. However, I need my flipflop to turn ON when the push-button is pressed and OFF when the push-button is pressed and held for several seconds.

The few simple criteria as follows. The last criterion is there to remove any ambiguity in the scenario:

  • The momentary push-button is part of a rotary encoder and shares its common anode;
  • The ON 'press time' should be under 0.5 seconds, but still incorporate some debounce;
  • The OFF 'press time' must be at least 5 seconds;
  • The current draw when idling must be as low as possible;
  • The solution must be purely hardware - I cannot use a uC.

After much deliberation and shouting I came up with the following circuit. It performs to the specification, except I'd like to know if there is a way of doing it with a lower component count. Schematic

Vcc = 3.7V. U1 (MAX942) is currently a simulation stop-gap and will likely be replaced with a lower-power equivalent, if there is one. The R/C values give suitable timimgs at present.

The circuit is quite simple: Q2 charges C1 and C2 through 1k resistors. When 'SWITCH' is pressed the caps will discharge through R3 and R5, respectively. When a capacitor's voltage drops below THR the compartor will go HIGH, providing a rising edge to CLK. However, when the flipflop is ON, Q4 shorts the output of U1:A, denying CLK of said edge. If the button is held down for long enough then C1 will eventually discharge below THR and U1:B will provide the rising edge to CLK.

I can't think of a simpler solution; everything I've tried ends up spiralling into complexity. Any recommendations would be appreciated.


Let me just start by saying that really, using a μC is infinitely easier. Tiny10, for example, would even be cheaper than many other chips you'd need in any of the solutions and be as small as a transistor. But hey, here goes:

If you don't mind it "flip-flop'ing" every 5.5seconds, this will do:


simulate this circuit – Schematic created using CircuitLab

Say Output is Low, NOT1 is pulling up the capacitor through R3, to compensate leak and such, when you press the switch you discharge C1 through D1 and R1 at a rate dictated by R1. At some point the output will toggle high.

Now NOT1 keeps the capacitor discharged, just as it kept it charged before. It will also re-charge the cap if you happened to hold the switch 2 seconds, then waited a while before trying to turn it off.

If you now press the switch, you will charge the capacitor through D2 and R2 at a lower rate dictated by R2.

The pressence of NOT1 and R3 will mess a bit with the standard NE555 rule of t=1.1*RC, so some tweaking of the cap or resistors will be needed, but in principle, these values should be close to what you need.

As said though, keeping SW1 pressed will toggle on/off repeatedly until you let go.

If there's instability when no button is pressed R3 might be too weak to compete with input pin currents, that depends on how old your NE555 is, most likely, in which case decreasing the Resistors and increasing C1 accordingly should help.

You could even get rid of the NOT1 by:


simulate this circuit

(and then add the rest of the earlier schematic)

Since the 100k on 3.3M will not make any difference to the tuning to any noticeable extend.

If you need a single-ramp-up, you can also do something like this:


simulate this circuit

When you press the switch C1 will charge through R2 and eventually pass the threshold of OA2, which will trigger the SET output, if you keep the button pressed it eventually passes the OA1 threshold, triggering the RESET output, which then also resets the SET to low.

You can feed that into your fevourite R-S-Latch/FlipFlop. If you need to feed it into a J-K Flipflop with R and S, you will probably need active low outputs, so you will need to flip the op-amps' inputs, to get inverted operation and then make the transistor a PNP connected to VCC in stead of GND.

When you let the switch go the capacitor will discharge through R1 and D1, which will go much more quickly. The residual charge left by the diode voltage drop will eventually be eliminated by R2 and R1 together, but with a BAT54 type the residual will be below 0.25V.

First you tune the set-time with R2 and C1 or by fiddling with R5, then you can tune the reset-time by fiddling with the balance between R3 and R4 (keeping R4+R3 approcimately the same, else you will also again change the set-time).

Some R-S latch/flipflop types do have a Last-Signal behaviour when both Set and Reset are active, then you won't need the R7 and Q1. They are only needed if the chosen latch has "Undefined Behaviour" when both S and R are active.

Check that the final op-amp choice reaches close enough to both supply rails to be able to give reliable coupling to the logic. Very old fashioned ones (uA741, for example) may not even manage that when powered with only 5V. But most moderny ones will probably do so.

  • \$\begingroup\$ I never thought of using a dedicated uC, but even an ATtiny10 is twice the price of an LMV358 (rail-to-rail op-amp). Also, uploading code to the blighter would be an inconvinience. The 55 timer option is a no-go: the 'every-N-seconds-switching' is undesirable; the slow dis/charge of the capacitor after the button is released means repeated presses could be mistaken for a long-press. The S-R approach looks good, but what would be the reasons for considering this as a replacement rather than an alternative, if any? \$\endgroup\$ – CharlieHanson Jul 22 '15 at 12:04
  • \$\begingroup\$ @CharlieHanson Yes, the Tiny is more expensive than just one op-amp chip. But a 555, or an op-amp chip + logic + transistors + diodes + caps + resistors (not mentioning board space, which racks up in cost too) is going to be more expensive for sure. The S-R System is a "better alternative" exactly because of that: Lesser components, less complexity, less tuning = less risk and/or time spent. As for getting code in a Tn10, that depends on only using 1 ever or using them regularly, of course. I have a set-up that cost $80 to build and has earned itself back long ago in my contract work. \$\endgroup\$ – Asmyldof Jul 22 '15 at 12:57
  • \$\begingroup\$ That said, you asked for suggestions and opinions, so I gave those. Yours works and if you like that solution there's no document of law prohibiting you. \$\endgroup\$ – Asmyldof Jul 22 '15 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.