The Four-Pin Switch: Hooking it up
So in the past few projects that I've worked on, I've been using a four-pin switch, and I hadn't thought about how to connect it until well that moment, so I thought I'd break up the XBee smorgasboard of posts with one about my four-pin switch!
Okay so 4 lovely pins, but how do you know which pins go where? So usually, you have to monitor a specific pin on your microcontroller which lets your program know when the button's been pressed, or not. Or if it's all analog, when you click down the button, you're completing a circuit.
- Button not pressed = disconnected circuit
- Button pressed = connected circuit.
But this still doesn't answer WHICH pin. So what happens is you'll need your multimeter.
When the button is not pressed, the following are electrically connected (zero resistance):
But when the button is pressed, the following are electrically connected:
Here's an example of one way to connect this such that Pin 7 will notice the pushbutton being pressed when ...pressed :p.
- 3.3V power goes nowhere! It goes to the great unknown.
- Pin 7 (MCU pin) is connected to ground through a resistor.
- 3.3V power goes to Pin 7 (MCU Pin)
- 3.3V power goes nowhere! It goes to the great unknown.
- Pin 7 (MCU pin) is connected to ground through a resistor.
- 3.3V power goes to Pin 7 (MCU Pin) - bypassing the resistor. The electrons will take the path of least resistance and as long as the resistor is of greater resistance than the pin, power will go from 3.3V to the pin.
Note - take care to note if you put the switch on one side of a breadboard with no electrically isolated space between the pins, that you may end up getting pins electrically connected even when you don't want them to!