Skip to content
Home > Components > Sensors > Push Button

Push Button

A classic 12mm momentary tactile switch for providing digital input signals to the microcontroller.

Component Preview

Push ButtonTactile Button

A momentary tactile push button. When pressed, the circuit is closed, allowing current to flow between its terminals. When released, the connection is broken. It is fundamental for user interfaces and basic digital input.

SensorsDigital InputSwitch

Overview

Push buttons are fundamental input devices. This standard 4-pin tactile switch has two pairs of connected legs.

  • Legs on the same side (e.g., Top Left and Top Right) are permanently connected internally.
  • Legs across from each other (e.g., Top and Bottom) are disconnected until the button is pressed.

Pull-Up vs Pull-Down

To use a button reliably with a microcontroller, the input pin must not "float". It must be explicitly pulled HIGH or LOW when the button is not pressed.

  • Active-LOW (Recommended): Connect the button between the digital pin and Ground (GND). Enable the internal pull-up resistor using pinMode(pin, INPUT_PULLUP). The pin reads HIGH when idle, and LOW when pressed.
  • Active-HIGH: Connect the button between the digital pin and 5V, and add a 10kΩ external pull-down resistor from the digital pin to Ground. The pin reads LOW when idle, and HIGH when pressed.

Pin Reference

PinTypeDescription
1LpassiveTerminal 1 Left. Connected to 1R internally.
2LpassiveTerminal 2 Left. Connected to 2R internally.
1RpassiveTerminal 1 Right. Connected to 1L internally.
2RpassiveTerminal 2 Right. Connected to 2L internally.

Configurable Attributes

AttributeTypeDefaultDescription
colorstringgreenVisual button cap color (e.g., `red`, `blue`, `green`, `yellow`, `black`).

Wiring Diagram

Example of connecting the Push Button (Active-LOW) to an Arduino Uno.

Wiring Diagram

Example Arduino Code

This example demonstrates the recommended Active-LOW wiring using the internal pull-up resistor. No external resistors are required.

cpp
const int buttonPin = 2;

void setup() {
  Serial.begin(9600);
  
  // Enable internal pull-up resistor. 
  // Pin will be HIGH when button is NOT pressed.
  pinMode(buttonPin, INPUT_PULLUP);
  
  Serial.println("Push Button Ready");
}

void loop() {
  // Read the button state
  int buttonState = digitalRead(buttonPin);
  
  // Since we use INPUT_PULLUP, LOW means the button is pressed
  if (buttonState == LOW) {
    Serial.println("Button is PRESSED!");
  } else {
    Serial.println("Button is released.");
  }
  
  delay(100);
}

Simulation Notes

  • In the OpenHW Simulator, you can simply click the button on the canvas while the simulation is running to toggle the signal and observe the input behavior immediately.

Released under the MIT License.