4-pin momentary tactile push button. Pins 1-2 are connected (left rail), pins 3-4 are connected (right rail). Pressing the button bridges both rails.
| Pin | Signal | Description |
|---|---|---|
1 |
digital_input | Left top — connect to digital pin (INPUT_PULLUP) |
2 |
gnd | Left bottom — connect to GND |
3 |
digital_input | Right top — same as pin 1 (internally connected) |
4 |
gnd | Right bottom — same as pin 2 (internally connected) |
Connect pin 1 to a digital GPIO pin (use INPUT_PULLUP) and pin 2 to GND. Pins 3-4 are the same connection as 1-2 (they are internally shorted in pairs). Only 2 wires needed: one to GPIO, one to GND.
| From | To | Wire |
|---|---|---|
board:D2 |
x1:1 |
green |
board:GND |
x1:2 |
black |
This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.
// Tactile switch example
// Wiring:
// - Switch pin 1 to Arduino D2
// - Switch pin 2 to Arduino GND
// Use the internal pull-up resistor, so the input reads HIGH when released
// and LOW when the button is pressed.
const int buttonPin = 2;
const int ledPin = 13;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Tactile switch demo started");
}
void loop() {
bool pressed = (digitalRead(buttonPin) == LOW);
digitalWrite(ledPin, pressed ? HIGH : LOW);
Serial.print("Button state: ");
Serial.println(pressed ? "PRESSED" : "RELEASED");
delay(50);
}
Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.
Start for free