Introduction
Interrupts allow a microcontroller to respond immediately to important external or internal events.

Types of Interrupts
- Hardware Interrupts: Triggered by external signals on specific pins.
- Timer Interrupts: Triggered at fixed intervals based on timers.
Interrupt Modes
Mode | Description |
---|---|
RISING | Triggered when signal goes from LOW to HIGH |
FALLING | Triggered when signal goes from HIGH to LOW |
CHANGE | Triggered when signal changes state |
LOW | Continuously triggers while signal is LOW |
Example Code
const int interruptPin = 2;
volatile int counter = 0;
void setup() {
pinMode(interruptPin, INPUT_PULLUP);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(interruptPin), countInterrupts, FALLING);
}
void loop() {
Serial.println(counter);
delay(1000);
}
void countInterrupts() {
counter++;
}
Common Issues & Solutions
Ensure debouncing for mechanical buttons to avoid false triggers. Do not use delay() inside ISRs.