Intro: Use a Momentary or Tactile Switch As a Pushbutton Switch.
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
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.