Interrupts are signals that pause the normal execution of an Arduino program to handle urgent events (like a button press or sensor trigger) immediately. They allow the microcontroller (e.g., ATmega328P in Arduino Uno) to respond to external or internal events without constant polling, saving power and CPU time.
Types of Interrupts in Arduino
1. External Interrupts
Triggered by hardware pins (e.g., a button press).
Supported pins (varies by board):
2. Pin Change Interrupts
3. Timer Interrupts
Triggered by internal timers (e.g., periodic tasks like reading sensors).
4. Software Interrupts
Triggered by code (e.g., volatile flags).
How to Use Interrupts in Arduino
1. Attach an Interrupt
Use attachInterrupt() to link a pin to an Interrupt Service Routine (ISR).
2. Interrupt Modes
3. Critical Notes
Example: Debouncing a Button with Interrupts
When to Use Interrupts
✔ Real-time events (e.g., emergency stop, rotary encoder pulses).
✔ Low-power applications (wake MCU from sleep on interrupt).
❌ Avoid for slow/complex tasks (use flags + loop() instead).
Interrupts vs. Polling
Supported Arduino Boards
For advanced use (e.g., timer interrupts), see the TimerOne or PCINT libraries.