arduino Interrupts

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


  • digitalPinToInterrupt(pin); // converts a pin id to an interrupt id, for use with attachInterrupt() and detachInterrupt().

  • attachInterrupt(digitalPinToInterrupt(pin), ISR, mode); // recommended

  • attachInterrupt(interrupt, ISR, mode); // not recommended

  • detachInterrupt(digitalPinToInterrupt(pin));

  • detachInterrupt(interrupt);

  • noInterrupts(); // disables interrupts

  • interrupts(); // re-enable interrupts after noInterrupts() has been called.


interruptId of the interrupt. Not to be mistaken for pin number.
ISRInterrupt Service Routine. This is the method which will be executed when the interrupt occurs.
modeWhat should cause the interrupt to trigger. One of LOW, CHANGE, RISING, or FALLING. Due boards also allow HIGH.


Interrupt Service Routines (ISRs) should be as short as possible, since they pause main program execution and can thus screw up time-dependent code. Generally this means in the ISR you set a flag and exit, and in the main program loop you check the flag and do whatever that flag is supposed to do.

You cannot use delay() or millis() in an ISR because those methods themselves rely on interrupts.

Got any arduino Question?