CNAP
03 / Templates · beginner

PUSHBUTTON 6MM SERIAL

Open in Playground

Compact 6mm pushbutton that prints 'Button pressed!' to the Serial Monitor on each press. Uses INPUT_PULLUP — no external resistor needed.

beginnerbutton6mmserialdigital inputINPUT_PULLUP
Circuit
Code
sketch.inoArduino C++
15 lines
// 6mm Pushbutton — print message on press
const int BTN = 2;

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Press the button!");
}

void loop() {
  if (digitalRead(BTN) == LOW) {
    Serial.println("Button pressed!");
    delay(200);  // simple debounce
  }
}
Components
  • Arduino Uno
    01
  • Pushbutton 6mm (wokwi-pushbutton-6mm)
    02
Wiring
Component PinArduino Pin
Button pin 1.lPin 2
Button pin 2.lGND