Skip to main content
3 of 4
improved formatting,grammar, spelling
BrettFolkins
  • 4.4k
  • 1
  • 14
  • 26

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

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