Arduino All-in-One Getting Started Guide


Step 3: Wiring the Pushbutton Switch

Picture of Wiring the Pushbutton Switch
To keep things modular, the pushbutton switch also connects to your Arduino, but it's a very separate circuit.

Note that the little pushbutton switches commonly available have four legs. The pins on each side are permanently connected to one another, so the button actually makes a single connection between the two sides. If you're in doubt as to which posts are which, just check it with your multimeter.

In the circuit diagram you're going to notice that we are using two resistors. Again, the exact values aren't really important, but the relative values are. If you aren't familiar with the concept of pull-up/pull-down resistors, please take a minute to really understand this circuit. If you don't, you will likely get flaky results in future projects or -- worse yet -- burn out your Arduino.

When the switch is OPEN, the circuit is simply a connection from the digital input (pin 2 in our case) to ground through a couple of resistors. Since we are connected to ground the value at pin 2 is LOW (approximately zero volts). If we were connected only to the switch the value would be whatever noise the wires were picking up. Maybe it would be close enough to zero to work, but maybe not. We need that ground connection to make sure our reading is right.

When the switch is CLOSED, the 5V source is connected to ground across our 15k resistor. The 150 ohm resistor is negligible by comparison, so it has a minimal effect on the voltage our input pin is reading (5V) and the digital input is HIGH (~5V). The 150 ohm resistor keeps us from creating a short between the power source and the pin so that we don't damage the Arduino.

Again, the exact values of these resistors are not important. Just make sure R1 is MUCH bigger than R2 and that R2 is big enough to limit the current back to the board. My values were simply plucked from my parts bin.

Clarification: The resistor is a pull-DOWN resistor because it connects the digital input to ground. A pull-UP resistor would pull the normal (no button pressed) state of the input to 5V.
Remove these adsRemove these ads by Signing Up
DirtMcGurt5 years ago
I'm new to this stuff but wouldn't that be a pull down?
gunnk (author)  DirtMcGurt5 years ago
Correct. Thanks for the catch on that. I've clarified the text now. Pull-up/Pull-down refers to what happens when the switch is OPEN. A pull-up resistor would hold Digital Pin 2 to 5V. A pull-down resistor holds it to 0 when the switch is open. We're holding to 0V when the switch is open, so this is a pull-down resistor.