Skip to Content
Circuitera

Which Uno R3 pins work with digitalPinToInterrupt()?

Check the difference between a board pin and an interrupt number and print the supported pin mappings with a small AVR sketch.

Choose the board pin first

On an Uno R3, D2 and D3 support the external interrupt interface used by attachInterrupt(). digitalPinToInterrupt(2) produces interrupt 0 and digitalPinToInterrupt(3) produces interrupt 1 on this core. Board pin numbers and interrupt indexes are different coordinates. Use the conversion when writing portable sketches.

Diagnose an input that never triggers

Print the conversion and compare it to NOT_AN_INTERRUPT before attaching. On this board D4 is invalid for this API. Other boards can differ. If the pin is valid but your routine does not run, check the selected edge, the actual pin, and its ground reference. An interrupt can see switch bounce, so a physical button can still need filtering. Keep routines short and defer serial printing to loop().

Open the exact Uno example

At 9600 baud the Uno R3 reports 2: 0, 3: 1 and 4: unsupported. Mapping checks require no switch.

void setup() {
  Serial.begin(9600);
  for (byte pin = 2; pin <= 4; ++pin) {
    const int irq = digitalPinToInterrupt(pin);
    Serial.print(pin);
    Serial.print(": ");
    if (irq == NOT_AN_INTERRUPT) Serial.println("unsupported");
    else Serial.println(irq);
  }
}
void loop() {}

Verified with [email protected] on Uno R3 (2026-12-05 UTC). This check did not use physical hardware.

Continue learning

Sources