Push-button switches are the classic momentary switch, as they only remain in their "on" state as long as they’re being actuated (pressed, held, etc). (adapted from Sparkfun)
When pressed, the tactile button switches connect two points in a circuit by allowing electricity to flow through. Tactile Button Switches have four pins, which can be a little confusing, but because pins B and C are connected together as well as A and D, there are only really two electrical connections. (adapted from Adafruit)
When wiring a breadboard, the convention is for the positive and negative power lines to lie on opposite sides of the board. Therefore, the standard set-up is to place the push-button running across the middle of the breadboard, and connect the electrical leads to A and C, or B and D.
The below code and schematic sets up a circuit where pressing the button turns the LED on, and leaving the button off turns the LED off.
const int LEDPIN = 5;
const int BUTTONPIN = 11;
void setup()
{
pinMode(BUTTONPIN, INPUT);
pinMode(LEDPIN, OUTPUT);
}
void loop()
{
if (digitalRead(BUTTONPIN) == LOW)
{
digitalWrite(LEDPIN, LOW);
}
else
{
digitalWrite(LEDPIN, HIGH);
}
}