Live robotics updates
Segway Navimow wins two Red Dot awards for next-generation robotic lawn mowersRobotics & Automation NewsRotaku launches Domo humanoid robot platform starting at $2,999 for developersRobotics & Automation NewsMachine Vision Systems Are Expanding the Need for Scalable Media InfrastructureRobotics & Automation News5 Best GPS Time Tracking for Field CrewsRobotics & Automation NewsWiz Alternatives in 2026: 7 Tools Compared – Best for Cloud and Code SecurityRobotics & Automation NewsDo Robotics Firms Need Microsoft 365 BackupsRobotics & Automation NewsHow an Email Domain Can Make a Business Look More ProfessionalRobotics & Automation NewsSimulation vs. digital twin: A strategic lens on virtual manufacturingThe Robot ReportRobot.com turns autonomous robots into mobile advertising network with launch of R-ads platformRobotics & Automation NewsSortera uses physical AI to double capacity in a Tennessee sorting facilityThe Robot ReportSegway Navimow wins two Red Dot awards for next-generation robotic lawn mowersRobotics & Automation NewsRotaku launches Domo humanoid robot platform starting at $2,999 for developersRobotics & Automation NewsMachine Vision Systems Are Expanding the Need for Scalable Media InfrastructureRobotics & Automation News5 Best GPS Time Tracking for Field CrewsRobotics & Automation NewsWiz Alternatives in 2026: 7 Tools Compared – Best for Cloud and Code SecurityRobotics & Automation NewsDo Robotics Firms Need Microsoft 365 BackupsRobotics & Automation NewsHow an Email Domain Can Make a Business Look More ProfessionalRobotics & Automation NewsSimulation vs. digital twin: A strategic lens on virtual manufacturingThe Robot ReportRobot.com turns autonomous robots into mobile advertising network with launch of R-ads platformRobotics & Automation NewsSortera uses physical AI to double capacity in a Tennessee sorting facilityThe Robot Report
View all
Back
Arduino sample guide

roboda-sample-0052 - Digital Input Pullup 03

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

Step-by-step build

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

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.

Important code parts

These are the sections learners should understand before changing the sketch.

INPUT_PULLUP

Keeps the input HIGH until the switch connects it to GND.

bool pressed

Converts the raw pin read into a meaningful state.

Serial.println()

Prints the state so learners can debug wiring.

Pin mapping for this sample

Use this first table for the exact sample wiring, then use the board-family table when moving the sketch to another Arduino board.

Code nameSample pinModeConnect toNote
buttonPinD4INPUT_PULLUPPush button or limit switch to GNDPressed reads LOW because the internal pullup is enabled.
outputPinD13OUTPUTBuilt-in LED or indicator LED through resistorD13 is safe for the onboard LED on most Arduino boards.

Arduino board pin reference

The code names stay the same; only the physical board pins may change by family. Always confirm with the board silkscreen when using clones or special variants.

Board familyDigitalPWMAnalogI2CSPIInterrupt
Uno / Nano / Pro MiniDefault target for these samples.D0-D13D3, D5, D6, D9, D10, D11A0-A5A4 SDA, A5 SCLD10 SS, D11 MOSI, D12 MISO, D13 SCK / ICSPD2, D3
Mega 2560Best for many sensors or multiple serial ports.D0-D53D2-D13, D44-D46A0-A15D20 SDA, D21 SCLD50 MISO, D51 MOSI, D52 SCK, D53 SS / ICSPD2, D3, D18, D19, D20, D21
Leonardo / MicroUSB serial can behave differently because the main MCU handles USB.D0-D13D3, D5, D6, D9, D10, D11, D13A0-A5 plus extra analog-capable pins by boardD2 SDA, D3 SCLICSP headerD0, D1, D2, D3, D7
Nano Every / Uno WiFi Rev2Check the board package pinout for exact PWM labels.D0-D13PWM-marked digital pinsA0-A7 on Nano Every, A0-A5 on Uno WiFi Rev2SDA/SCL marked pinsICSP/SPI marked pinsUse pins supported by digitalPinToInterrupt()
Uno R4 Minima / Uno R4 WiFi5V logic board; still confirm shield/library compatibility.D0-D13PWM-marked digital pinsA0-A5SDA/SCL marked pinsICSP/SPI marked pinsUse digitalPinToInterrupt(pin)
Due3.3V logic only; protect pins from 5V sensors.D0-D53PWM-marked digital pinsA0-A11SDA/SCL and SDA1/SCL1SPI headerUse digitalPinToInterrupt(pin)
MKR / Nano 33 family3.3V logic. Some AVR-only libraries may need alternatives.Board-marked digital pinsPWM-marked pinsBoard-marked analog pinsSDA/SCL marked pinsSPI marked pinsUse digitalPinToInterrupt(pin)

Full sample code

/*
  Roboda verified Arduino sample 0052
  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(150);
}

Teacher notes

  • Compile the sample before changing wiring or constants.
  • When changing boards, keep the code names the same and update only the pin number constants.
  • For 3.3V boards, level-shift 5V sensors and modules before connecting signal pins.
  • Use the first compiler error and the Roboda diagnostic suggestion before fixing later warnings.
Roboda support Leave a message

New messages appear in the Finite LiveChat Ops Android app.