Skip to main content

On all Arduinos except the DUE, attachInterrupt() does not use the pin number as first argument but the interrupt number, which is diferent:

void attachInterrupt(uint8_t interrupt, void (*ISR)(void), int mode);

As documented on Arduino reference, for an Arduino UNO, the mapping is as follows:

  • Interrupt 0 -> Pin 2
  • Interrupt 1 -> Pin 3

So just change the code in setup() to:

attachInterrupt(0, inter, CHANGE);

And that should work for pin 2.

jfpoilpret
  • 9.1k
  • 7
  • 37
  • 54