Read buttons, limit switches, and contact sensors with stable internal pullups.
Open in compiler →/*
Roboda verified Arduino sample 0477
Feature: Digital Input Pullup
Generated for online build, classroom practice, and hardware upload testing.
*/
const byte buttonPin = 10;
const byte outputPin = 13;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(outputPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
bool pressed = digitalRead(buttonPin) == LOW;
digitalWrite(outputPin, pressed ? HIGH : LOW);
Serial.println(pressed ? "pressed" : "released");
delay(325);
}
How it works
Read a button or limit switch reliably using the internal pullup resistor.
- Wire one side of the switch to the input pin and the other side to GND.
- Enable INPUT_PULLUP so no external resistor is required.
- Treat LOW as pressed and HIGH as released.
- Mirror the state to D13 and Serial Monitor.
Connections
| Pin | Connect to | Note |
|---|---|---|
| D10 | Push button or limit switch to GND | Pressed reads LOW because the internal pullup is enabled. |
| D13 | Built-in LED or indicator LED through resistor | D13 is safe for the onboard LED on most Arduino boards. |