0

I tried to run a sketch that tests my AVR's interrupts, I have an UNoriginal Arduino Uno, and I've checked pins 2 and 3 like the following:

- at void setup()
attachInterrupt(2, inter, CHANGE);
- at void inter()
Serial.println("Interrupt pin 2");

I did the same on pin 3, I checked them by attaching the pins to a button with a Pull-Up, When I click the button it goes from HIGH to LOW. But yet, the arduino doesn't run the 'inter'. Is it possible that because my Arduino is not original it won't work? And this type of interrupts are software not hardware right?

2

On all Arduino boards 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.