Introduction: Use a Momentary or Tactile Switch As a Pushbutton Switch.

Just a Moment
Tactile switches (a specific type of momentary switch) are everywhere and they are especially popular on DIY  electronics and microcontroller boards because they are well suited to act as a boot option or reset switch.  Particularly, momentary switches are switches that don't save their state when you depress the switch.  That is, when you push the switch (and while you have the switch depressed) the circuit is ON, but once you let off the switch it reverts back to OFF.


In this micro-instructable, I will show you how to convert those ubiquitous tactile and general momentary switches into pushbutton switches that toggle and save their state.  It's very easy and extremely straight forward so you can implement it immediately in your designs if you're interested in doing so.

Step 1: Get Yer Switches

The most obvious part of the necessary components is a momentary switch.  Go grab one, or two, or a handful if you're OCD and can't decide.  There are lots of different kinds of momentary switches from panel switches, to PCB tactile switches, to toggle momentary switches.  I have collected several different kinds in the picture below. 

In this instructable, I'm going to use tactile switches.  There's just something wholly satisfying about the force required to activate the switch and the crisp *click* you get is quite rewarding.  Feel free to use whatever switches you have around.  If you haven't scoped the video, check it out now.  I have setup two tactile switches. One in a normal configuration with an LED and requisite resistor on the high side, and then driving to ground on the other.  It does what you would expect when you press the button: the nice little blue LED comes on and stays on for as long as you hold the switch down, then immediately goes off when the switch is depressed.

The second switch is attached to a MC14027 J-K flip-flop IC, as well as having two LED's attached to the flip-flops.  Turn the page and learn about flip-flops!

Step 2: Sequential Circuits

The key behind this circuit is a flip-flop; a J-K flip-flop to be precise.  A flip-flop does what its name suggests: it changes between its previous state Qn and its next stateQn+1based on the values to the J and !K inputs (note the bang before the !K; I use this notation to signify that it is an active LOW input).  A flip-flop is one of a family of ICs that are known to keep it's state.  In fact, it's next state is a product in some way of its previous state(s).  These circuits are called sequential circuits and also include counters and shift registers. This is in contrast to combinatorial circuits, which include our favorite logic gates; the output, for example, of an AND gate only depends on it's current inputs and the previous inputs (or it's previous output/state has no bearing on its current output). 


There are several flavors of flip-flop to choose, the two major categories being master-slave and edge/level triggered along with the type of flip-flop, like an S-R, D, T, and J-K.    J-K flip-flops can be built using two S-R latches in a sequential arrangement or with NAND gates, among others.

  Here is a list of a few flip-flop IC's.  The asterisk (star) means we're not concerned with the logic family (ie ALS, HC, HCT, LS, F, etc).  For example, 74*109 could be an 74LS109 or a 74F109. Also, "(+)" or "(-)" is my shorthand for positive edge-triggered and negative edge-triggered, respectively.

74*74   Dual (+) D flip-flops
74*107  Dual J-K flip-flop (-) triggered
74*109  J-K (+) flip-flop
74*112  Dual J-K w/ set/reset; (-) trig.
74*173  Dual D, (+) 3-state
74*273  High-speed CMOS Logic Octal D flip-flop w/ reset (+)
74*374  High-Speed CMOS Logic Octal D flip-flop; 3state, (+) triggered
74*377  Octal D type w/ enable; (+) 
4027    Dual J-K (+) flip-flop

Edge-triggered flip-flops are activated at the rising or falling edge of a clock signal and provides a synchronous input to the output.  Some flip-flops also have asynchronous set and reset inputs that allow changing the output irrespective of the state of the clock signal.  Along with the J-K inputs, there is also a complementary output pin, !Qn+1.

Check out the block diagram below.  You will note there are J, K, clock, set, reset, Q, and !Q pins available in a dual configuration.  The logic/excitation table can be found in the datasheet as well as on my schematic that I have attached to the next page.  The permutations of inputs are unimportant to us except for the toggle state. When J is HIGH (1) and !K is HIGH (1), then Qn+1 = !Qn.  This is just saying that whatever the present state of the flip-flop, the output will be its complement/inverted.

Turn the page and let's get this flip-flop working for us and make our switch!

Step 3: Using the J-K Flip-flop

You may need to refer back to the pinout on the previous page when making your connections to the J-K flip-flop.  The big picture we're working with is that we're going to use the state saving feature of the flip-flop along with its ability to easily toggle an output to push 5V and around 6mA to 24mA (each flip-flop IC has varying characteristics so make sure you check out yours).  The one I'm using currently has an Io of ~ 10mA.  We're going to drive an LED with the Q's ~ 5V output  and sink Vcc with !Q, Q's complement.  In other words, when Q is HIGH, !Q is LOW and vice versa.

You will recall that the J-K input to toggle the current state is to have both inputs driven HIGH so I've tied the J and K input to a 10k pullup resistor to Vcc (5V).  The set (!SD) and reset/clear (!RD) are often both active LOW, but on this IC they are active HIGH  so I've tied them to a pulldown to GND. 

So if both inputs are permanently tied to 5V, how do we input anything?  Remember the clock signal?  The Q and !Q outputs are available one setup clock after a positive transition from the rising edge of the clock signal.  All we have to do is connect our momentary switch from 5V into the clock signal and when we press the switch and close the connection, we will send a positive edge-trigger to the flip-flop which will have it toggle the output.  So, If the Q output is HIGH (ie it's sourcing 5V to the LED) when we press the button again, it will go to LOW (ie off) and when we press it again next it will toggle back to HIGH (on) and so on.

Make sure you look at the picture of the schematic (you don't have to have Eagle and look at the *actual* schematic...there's a picture of it below) if you're unclear about anything.  Also, you'll notice I've included a 2-input terminal block to allow the board to accept a 5V and a GND signal.

And that's it.  Now your nifty momentary/tactile switch is a push-and-stay-on pushbutton switch.

Step 4: Conclusion

Using the state-saving feature of a sequential circuit like a flip-flop allows us to add a state to our stateless momentary switch with a minimum of external components.  I hope you've enjoyed the instructable and maybe I've been able to share a trick or two with you.  As always, I welcome your comments and suggestions.

Cheers!
Gian

Comments

author
pletchman made it!(author)2012-02-27

Question. I've found some really nice momentary switches but wanted to know if they can be used for my needs. Basically I am looking for an On-On-Off switch. I have a drawer with low level LED lighting and full LED lighting. I want to be able to have a single button that if pressed once turns on the red LEDS -- press it again it turns on the white LEDs (thereby also turning off red LEDs) -- press it again and both sets of LEDs are turned off. How do I accomplish this the most easily? I've found basic little ON-ON-OFF switches but like some of the nicer illuminated momentary switches. Thanks in advance for your expertise

author
dreadlord_avis made it!(author)2017-04-01

Use a 4bit shift register, loop 3 of them in a closed loop and use the last one for initial condition setting
https://ibb.co/gL5c1F

author
nevdull made it!(author)2012-04-06

I'm not sure how you wold do this with an "on-on-off" switch as I've never seen those before. One possible option could be using a momentary switch connected to a counter IC (say, a 4017 decade counter) with the appropriate string of LEDs connected to the appropriate output of the counter. With each clock transition (ie button press) the outputs will go high in sequence.

Just a thought.

Good luck!

author
lysergd made it!(author)2014-12-09

Hey can anyone help I'm trying to make a simple on on off circuit using 1 small button what I need is first click led1 on second click led1 off led2 on third click led2 off please help :) Thanks.

author
dreadlord_avis made it!(author)2017-04-01

Use a 4bit shift register, loop 3 of them in a closed loop and use the last one for initial condition setting
https://ibb.co/gL5c1F

author
jacobsteel made it!(author)2017-03-26

Great! Thanks!

author
Sebaaly made it!(author)2016-10-12

In order to switch the motor rotation direction, you will need 3 push button switches: sw1 and sw2 and reset. When sw2 is pressed after sw1, the motor should turn in one direction. When sw2 is pressed twice the motor should turn in the other direction, the motor remains on in any direction even if the switches are released. The reset button is pressed in order to stop the motor and before the direction change. Some 1 help me with this.

author
LeslieP28 made it!(author)2016-07-26

hi, this is a marvelous guide! is it possible to power up your circuit with 3x AAA batteries? would you help me calculate the resistors value if it's possible? thx for the very nice guide! :)

author
kawa5292 made it!(author)2016-02-19

Thank you so much. This helps with my simple problem and I can continue with my sons pokemon electronic game board. my next step is to count each led as a number on 3- 7 segment displays. You have helped so much and when I am done with this project I would like to send you pics. Have a good night and God Bless.

author
frogamic made it!(author)2015-12-31

Did you have any trouble with switch bouncing?

author
manicmonday made it!(author)2015-09-09

What happens when you kill the power to the circuit?

author
Bjarneec made it!(author)2015-07-23

Hi. I need 4/5 flashing LEDs to light when a momentary switch is pushed and to stop when pushing againg. (Like your project) is this the one I need? What Else do I need? Thanks :)
http://m.ebay.com/itm/5-PCS-MC14027BD-SOP-16-MC14027-14027B-CD4027-SOP-14-Flip-Flop-/371086035414?nav=SEARCH

author
nevdull made it!(author)2015-07-28

Thanks for the comment. I hope this instructable can help you out!

author
Bjarneec made it!(author)2015-07-29

What kind of resistors are you using? And are you only using the Flip-flop, 4 resistors and 2 LED's? Thanks.

author
RachmanB made it!(author)2015-07-02

if you need more that 2 state.. try use 4017 connected to relay. example for fan 0-off 1=speed1 2=speed2 ...

author
nnkk made it!(author)2015-04-18

I need to make a push button mechanism to run a motor rated ( 3v - .64A) . This circuit can turn on/off an led fine, but could not start the motor. What change i ned to make to get enough current to run the motor. is there any other way i can make a pushbutton for this motor

author
matys292 made it!(author)2014-10-12

Hello i got chip HCF4027BE. When i connect it like your circuit only 1 led is ON. When i push button it doesn't work. It's possible that pins of chips are on sorted otherway? That's datasheet of my chip: http://pdf.datasheetarchive.com/datasheetsmain/Databooks-4/Book615-2788.pdf

author
diywannaber made it!(author)2014-09-06

Wouldn't it be simpler and cheaper to just use a push button switch that locks on to the state instead of a momentary one and then the whole flip flop implemented using an IC.

author
nevdull made it!(author)2014-09-06

hi,
You ask would it be simpler? Yes, most definitely an integrated solution would be simpler. Cheaper? I'm not sure. Switches can be quite expensive. Your mileage may vary.
Cheers!

author
w4op made it!(author)2014-02-18

Will this circuit always start up in the OFF state when power is first applied- or can it be modified to do so- perhaps with an R-C on the SET input?

Thanks,

Dale

author
tpark4 made it!(author)2014-01-14

Hey, I know this is an old guide, but I found it very useful, took the idea and made a push-button 4 mode switcher for an RGB LED! But now that all my logic is done, I found that my flip-flop is only rated for 2mA at 5V, when my LED can pull up to 70mA! Should I use a transistor to use the flip flop output to switch a larger power supply, or should I find a more heavy duty flip flop? Please help me out!

author
anglin made it!(author)2013-05-03

hi a newbee here , how do i open the files

author
nevdull made it!(author)2013-05-04

Hi. The schematic and board file were created in Eagle CAD, so you'll need that to open/edit them. There is a free version you can use. Just google 'eagle cad' for the download.

author
ElPablo made it!(author)2013-03-08

Thank you so much for this circuit. I've been looking for examples of using the 4027 but they've been hard to find. I do have one question though... If I connect LED2 the way it's shown in the schematic it doesn't work as expected... if I reverse the polarity and connect it just like LED1 (Pin 2 -> 1K Resistor -> LED2 -> GND) it works perfectly .
Now I suspect that I may have messed something else up since I new to this but I've double-checked and everything else seems to be ok. Any ideas?

author
nevdull made it!(author)2013-03-21

Hi! Thanks for the kind words. About your problem....hmmm, that is odd. It ostensibly shouldn't be able to work since Q and !Q are orthogonal and complementary (that is, when one is sourcing the other is sinking). Could you possibly have your LED2 connected into the *other* Q output of the second J-K flipflop on the IC?

author
dailodai78 made it!(author)2011-04-05

HI, I've always wanted to make a pushbutton switch from a tactile switch but I don't know anything about the IC circuits. I'm a bit clueless when it comes that. If possible, can you upload a better picture of the wiring diagram and explain what you used in creating the pushbutton circuit (besides the tactile switches and LED lights)?

author
EZELab made it!(author)2011-03-10

Thanks for this circuit, could you explain how to connect a 5V relay ?

author
nevdull made it!(author)2011-03-13

Just hook the output of the flip-flop into the trigger lead of the relay and connect your relay's other side to whatever you're wanting to control in the normal way you would any relay. Make sure your relay's excitory level (the voltage level that triggers the relay) works for the level of voltage you're pushing out of your flip-flop.

author
EZELab made it!(author)2011-03-13

The out put is very low, cant i connect a transistor or something to the out put that pass the ( - ) to the relay, and the other relay pin to ( + ). like the circuit i attached, this one i found on the internet, buy never worked for me !
Yours worked perfect ! but just missing the relay connection :)

I Think we need a good transistor that just passes the negative to the relay !

LED ON OFF 4027--.PNG
author
nevdull made it!(author)2011-03-13

Maybe put the relay where the LED would be in your schematic and run the output into the base of the transistor. Maybe that would work for you?

author
verdastel made it!(author)2010-09-02

This is a very useful instructable, thanks a lot for sharing!

author
nevdull made it!(author)2010-09-04

Thanks a lot!

author
xVirus made it!(author)2010-08-31

can I put a relay instead of a led

author
nevdull made it!(author)2010-09-04

yep you sure can, just ensure the excitory level on the relay works with your Vcc.

author
jeff-o made it!(author)2010-08-31

Fantastic info! In a situation where you aren't using a microcontroller, this is just the thing for implementing a non-momentary switch.

author
nevdull made it!(author)2010-09-04

Thanks jeff-o! I appreciate the kind words!

About This Instructable

193,402views

89favorites

License:

Bio: Gian is a computational biologist and is the Managing Director at Open Design Strategies, LLC. He holds a BA in Molecular/Cellular Biology and an ... More »
More by nevdull:Create A Custom Medieval-/Fantasy-Style Calligraphy QuillPractical DACsUsing Enumerated Types as Bitflags
Add instructable to: