Why not use digitalPinToInterrupt() to completely hide this detail? [BTW you can always look in ..../hardware/arduino/avr/variants/mega/pins_arduino.h in your downloaded Arduino IDE to see exactly whats defined ] Answer from MarkT on forum.arduino.cc
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Arduino Mega interrupts - Programming - Arduino Forum
November 7, 2018 - The Arduino reference for attachInterrupt command gives this chart for interrupts and pins on the Mega board: BOARD INT.0 INT.1 INT.2 INT.3 INT.4 INT.5 Mega2560 2 3 21 20 19 18 However may pinout diagrams show: INT.0 on Pin 21 INT.1 on pin 20 ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Arduino Mega Interrupt pins - Programming - Arduino Forum
September 12, 2022 - Examples show interrupt 0 and pin 2, so the part of the code would be : byte FM_1_Interrupt = 0; // 0 = digital pin 2 // and in the void setup void setup(){ // The Hall-effect sensor is connected to pin 2, which uses interrupt 0. // Configured ...
Discussions

Pin Change Interrupt - PortC on Arduino Mega 2560
INT 0-7 are certainly the preferred pins, are those not available? I haven't looked up RAMPS pin mapping. even with PCINT it's possible to miss some ticks. you'd need to do a direct port read and go from there to speed it up to minimize that. PJRC has an encoder library that supports the hardware interrupts and polling and is easily configured. if the speeds are not too fast polling won't be too terrible. More on reddit.com
🌐 r/arduino
1
1
December 1, 2015
Arduino Mega R3 Interrupt pins
I know that on the Mega, only pins 2, 3, 18, 19, 20, and 21 are hardware interrupt-capable, which limits the number of readers I can connect. Is there any way to add more interrupt-capable pins or expand the hardware interrupts for handling more RFID readers? More on forum.arduino.cc
🌐 forum.arduino.cc
6
0
October 23, 2024
Arduino mega using any pin as an interrupt pin?
Hi. I am using an arduino mega and limit switches. I have pins corresponding to each of my (8) limit switches: pins 40 - 47. I can't change these pins given the project rn, but I need to enable interruptions on each of these pins. I'm trying to set it up so that when a limit switch is pressed, ... More on forum.arduino.cc
🌐 forum.arduino.cc
7
0
July 1, 2018
Arduino Mega 2560 AttachInterrupt to pin 20 & 21
Hi, I am using an IR phototransistor and an IR LED as motion detector. When the IR light which shines on the phototransistor is blocked, the transistor causes an open circuit and the voltage at the pin rises. When the voltage rises, an interrupt routine is executed. More on forum.arduino.cc
🌐 forum.arduino.cc
9
0
October 28, 2020
Top answer
1 of 2
2

You can double-up on pins if both devices signal in the same direction (HIGH or LOW) or their signals be conditioned to do so. When the interrupt fires, your interrupt routine first polls the devices to determine which one fired and then dispatches to the code for that one. If a race-condition is possible, you should remember the dual-firing (store it in a bool or as two one-bit flags) and dispatch to one after the other.

Update:

What do you mean with 'double-up on pins'?

Connect two devices' "ready" outputs to the same interrupt pin. The interrupt routine will have to determine which device is asking for service and act accordingly.

2 of 2
11

If you read data sheet of AVR chip, you might come across PCINT in addition to INT pins.

INT refers to the dedicated hardware interrupt pins described in Arduino Reference. The INT pin is linked to a dedicated interrupt vector so you always know what pin caused the interrupt when in the ISR.

PCINT refers to Pin-Change Interrupt that can be generated by almost(not always though) any of the I/O pins. PCINT has more overhead in determining what pin caused the interrupt as a group of pins(pins on the same GPIO port) share the same PCINT vector so you need to determine which pin caused the interrupt within the ISR before acting on it. Furthermore, PCINT can wake from sleep mode power down on change, while INT can only wake on low level. Depends on your application, PCINT is very good if you want to look at several pin status at once, for example, when using a rotary encoders.

This Article provides a good description and example on using PCINT, there is a library PinChangeInterrupt by NicoHood for using Pin Change Interrupt.

Specifically for ATmega2560, there are 24 PCINT-capable pins.

🌐
Sami Hamdi
full-skills.com › home › iot › arduino mega interrupt pins: exploring the potential
Arduino Mega Interrupt Pins: Exploring The Potential
November 4, 2023 - They allow a microcontroller to instantly respond to specific events, thus reducing the need for continuous polling and optimizing the efficiency of your code. In the context of the Arduino Mega, there are six interrupt pins marked as INT0 to INT5.
🌐
Reddit
reddit.com › r/arduino › pin change interrupt - portc on arduino mega 2560
r/arduino on Reddit: Pin Change Interrupt - PortC on Arduino Mega 2560
December 1, 2015 -

I'm trying to experiment with the RAMPS 1.4 board with a RepRapDiscount Full Graphic Smart Controller connected to it. I've gotten as far as displaying basic text on the screen and polling the pushbuttons/rotary encoder. I'm starting to hit a wall when trying to poll the rotary encoder via interrupt.

The encoder is connected to pins 31 and 33 on the Mega. These pins translate to PC6 (A14) and PC4 (A12) on the AtMega2560. Looking at multiple sources on external interrupts/pin change interrupts, it looks like the only pins supported for interrupts on the Mega are PCINT 0-23 and INT 0-7.

So now to the actual question. Can I trigger an interrupt on pins 31/33 changing in any way? I can make due with an interrupt triggering when either pin is changed. If I can't get that working, what are my alternatives? A timer interrupt that polls the pins seems like it might kinda sorta work, but it also seems expensive and likely to miss changes in the encoder state. Any help is appreciated!

🌐
Arduino
docs.arduino.cc › language-reference › en › functions › external-interrupts › attachInterrupt
attachInterrupt() | Arduino Documentation
April 24, 2025 - FALLING for when the pin goes from high to low. ... HIGH to trigger the interrupt whenever the pin is high.
🌐
Last Minute Engineers
lastminuteengineers.com › arduino-mega-pinout
Arduino Mega 2560 Pinout Reference
March 25, 2026 - PWM pins on the Arduino Mega are digital pins that can simulate analog output. They achieve this by rapidly switching the pin between HIGH and LOW states, creating a square wave signal.
Find elsewhere
🌐
GitHub
github.com › GreyGnome › EnableInterrupt
GitHub - GreyGnome/EnableInterrupt: New Arduino interrupt library, designed for Arduino Uno/Mega 2560/Leonardo/Due · GitHub
It is the same pin the Arduino uses to upload sketches, and it is connected to the FT232RL USB-to-Serial chip (ATmega16U2 on the R3). External Interrupts ------------------------------------------------------------ The following External Interrupts are available on the Arduino/MegaCore: MegaCore Pin PORT INT ATmega2561/1281 pin 18 PD0 0 25 19 PD1 1 26 20 PD2 2 27 21 PD3 3 28 4 PE4 4 6 5 PE5 5 7 6 PE6 6 8 7 PE7 7 9 Pin Change Interrupts ---------------------------------------------------------- ATMEGA2561/1281 (MegaCore) Pin Change Interrupts MegaCore Pin PORT PCINT 8/SS PB0 0 9/SCK PB1 1 10/MOSI PB2 2 11/MISO PB3 3 12 PB4 4 13 PB5 5 14 PB6 6 15 PB7 7 0 PE0 8 - this one is a little odd.
Starred by 336 users
Forked by 73 users
Languages   C++ 68.5% | C 31.1% | Shell 0.4%
🌐
The missing pieces
jdahlbom.wordpress.com › 2015 › 11 › 29 › using-up-to-24-interrupt-pins-on-arduino-mega
Using up to 24 interrupt pins on Arduino Mega. | The missing pieces
November 29, 2015 - Atmega 1280 – the IC running on Arduino Mega – provides a way to run a total of 24 interrupt pins by using PCINT0-PCINT23 -pins.
🌐
GitHub
github.com › GreyGnome › EnableInterrupt › blob › master › README.md
EnableInterrupt/README.md at master · GreyGnome/EnableInterrupt
It is the same pin the Arduino uses to upload sketches, and it is connected to the FT232RL USB-to-Serial chip (ATmega16U2 on the R3). External Interrupts ------------------------------------------------------------ The following External Interrupts are available on the Arduino/MegaCore: MegaCore Pin PORT INT ATmega2561/1281 pin 18 PD0 0 25 19 PD1 1 26 20 PD2 2 27 21 PD3 3 28 4 PE4 4 6 5 PE5 5 7 6 PE6 6 8 7 PE7 7 9 Pin Change Interrupts ---------------------------------------------------------- ATMEGA2561/1281 (MegaCore) Pin Change Interrupts MegaCore Pin PORT PCINT 8/SS PB0 0 9/SCK PB1 1 10/MOSI PB2 2 11/MISO PB3 3 12 PB4 4 13 PB5 5 14 PB6 6 15 PB7 7 0 PE0 8 - this one is a little odd.
Author   GreyGnome
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
Arduino Mega R3 Interrupt pins - General Guidance - Arduino Forum
October 23, 2024 - I'm working on a project with an Arduino Mega that uses Wiegand RFID readers, and I need to use hardware interrupts for the D0 and D1 lines of each reader. I know that on the Mega, only pins 2, 3, 18, 19, 20, and 21 are hardware interrupt-capable, ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Arduino mega using any pin as an interrupt pin? - Programming - Arduino Forum
July 1, 2018 - Hi. I am using an arduino mega and limit switches. I have pins corresponding to each of my (8) limit switches: pins 40 - 47. I can't change these pins given the project rn, but I need to enable interruptions on each of these pins. I'm trying to set it up so that when a limit switch is pressed, I use an interruption (the code will be the same for each interruption for these switches, which I think is good b/c the method I'm trying to use allows for two or more pins to share the same routine......
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Arduino Mega 2560 AttachInterrupt to pin 20 & 21 - Programming - Arduino Forum
October 28, 2020 - Hi, I am using an IR phototransistor and an IR LED as motion detector. When the IR light which shines on the phototransistor is blocked, the transistor causes an open circuit and the voltage at the pin rises. When the voltage rises, an interrupt routine is executed.
🌐
TutorialsPoint
tutorialspoint.com › arduino › arduino_interrupts.htm
Arduino - Interrupts
Most Arduino designs have two hardware ... including the additional interrupts ("interrupt2" through "interrupt5") on pins 21, 20, 19, and 18....
🌐
Instructables
instructables.com › circuits › arduino
Create External Interrupt in Arduino : 7 Steps - Instructables
October 5, 2017 - Create External Interrupt in Arduino: Adruino has several types of interrupts.Interrupt is a process by which arduino stops its regular task or stop its looping and go to interrupt function to complete its given interrupt function task.External interrupt created externally.There are onl…
🌐
Arduino Forum
forum.arduino.cc › other hardware › 3rd party boards
How to Enable the interrupts on pins D4, D12, A0-A5 on Arduino Mega 2560 board - 3rd Party Boards - Arduino Forum
September 12, 2013 - Hi, I have developed a sketch working on Arduino UNO, to enable interrupts on the following pins: D4, D12, A0-A5. That sketch uses <avr/io.h> and <avr/interrupt.h>. Now I wish to do the same on Arduino Mega 2560 Board…
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
How to make use of Interrupts on pins 20 & 21 of a Mega when using an I2c LCD - General Guidance - Arduino Forum
October 2, 2020 - Hi everyone, I want to make use of all 6 interrupts on an Arduino Mega. The project uses an I2C LCD which uses SCL and SDA which I have wired to and the LCD works fine. I have wired separate inputs to pins 20 & 21 which…
🌐
SparkFun Learn
learn.sparkfun.com › tutorials › processor-interrupts-with-arduino › all
Processor Interrupts with Arduino - SparkFun Learn
Most Arduinos have 2 external interrupts built in: interrupt0 (on digital pin 2) and interrupt1 (on digital pin 3). Some boards have more (like the Arduino Mega 2560) - refer to the user manual or datasheet for more information on what your specific board supports.
🌐
Medium
medium.com › @khanjungan › c-programming-for-arduino-a-practical-guide-single-interrupt-ce91ff44055e
C Programming for Arduino: A Practical Guide — Single Interrupt
January 7, 2024 - This interrupt is associated with a specific pin and can be configured to react to a change in that pin’s state, such as a rising or falling edge. In simpler terms, a single interrupt allows the Arduino Mega2560 to momentarily pause its ongoing tasks when a specified event occurs on a designated ...
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
Arduino Mega External Interrupts - General Guidance - Arduino Forum
April 18, 2015 - Hello! I am in the process of making an RC craft, and have successfully used a Mega 2560, with pins 2 and 3 for interrupts. The Mega 2560 is capable of 6 external interrupts, which are 0-5 on pins 2, 3, 21, 20, 19, 18 r…