A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

Digital Input Pullup 14

Read buttons, limit switches, and contact sensors with stable internal pullups.

Open in compiler →
/*
  Roboda verified Arduino sample 0327
  Feature: Digital Input Pullup
  Generated for online build, classroom practice, and hardware upload testing.
*/

const byte buttonPin = 4;
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(115);
}

How it works

Read a button or limit switch reliably using the internal pullup resistor.

  1. Wire one side of the switch to the input pin and the other side to GND.
  2. Enable INPUT_PULLUP so no external resistor is required.
  3. Treat LOW as pressed and HIGH as released.
  4. Mirror the state to D13 and Serial Monitor.

Connections

PinConnect toNote
D4Push button or limit switch to GNDPressed reads LOW because the internal pullup is enabled.
D13Built-in LED or indicator LED through resistorD13 is safe for the onboard LED on most Arduino boards.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.