03 / Templates · beginner
PUSHBUTTON 6MM SERIAL
Open in PlaygroundCompact 6mm pushbutton that prints 'Button pressed!' to the Serial Monitor on each press. Uses INPUT_PULLUP — no external resistor needed.
beginnerbutton6mmserialdigital inputINPUT_PULLUP
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
}
}- Arduino Uno01
- Pushbutton 6mm (wokwi-pushbutton-6mm)02
| Component Pin | Arduino Pin |
|---|---|
| Button pin 1.l | Pin 2 |
| Button pin 2.l | GND |