0
0
AutocadConceptBeginner · 4 min read

Rising, Falling, Change in Arduino Interrupt Explained

In Arduino interrupts, RISING triggers when a signal changes from LOW to HIGH, FALLING triggers when it changes from HIGH to LOW, and CHANGE triggers on any change in the signal state. These modes help detect specific signal edges to run code immediately when the signal changes.
⚙️

How It Works

Imagine a doorbell button connected to your Arduino. When you press it, the signal goes from off (LOW) to on (HIGH). The RISING interrupt watches for this exact moment when the signal rises from LOW to HIGH, like noticing the doorbell being pressed.

The FALLING interrupt is like noticing when the doorbell button is released, the signal falling from HIGH back to LOW. The CHANGE interrupt notices both pressing and releasing, reacting to any change in the signal.

This lets your Arduino react quickly and only when the signal changes, saving time and power compared to constantly checking the signal in a loop.

💻

Example

This example shows how to use RISING, FALLING, and CHANGE interrupts on a button connected to pin 2. It prints which event happened.

arduino
volatile int state = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(2), risingISR, RISING);
  // Commenting out the following two lines because multiple interrupts on the same pin are not supported
  // attachInterrupt(digitalPinToInterrupt(2), fallingISR, FALLING);
  // attachInterrupt(digitalPinToInterrupt(2), changeISR, CHANGE);
}

void loop() {
  // Main loop does nothing, interrupts handle events
}

void risingISR() {
  Serial.println("RISING detected: LOW to HIGH");
}

void fallingISR() {
  Serial.println("FALLING detected: HIGH to LOW");
}

void changeISR() {
  Serial.println("CHANGE detected: Signal changed");
}
Output
RISING detected: LOW to HIGH
🎯

When to Use

Use RISING when you want to react only when a signal turns on, like detecting a button press or sensor activation.

Use FALLING to detect when a signal turns off, such as a button release or sensor deactivation.

CHANGE is useful when you want to detect both pressing and releasing or any signal change, for example, counting pulses or monitoring switches.

These interrupts are great for real-time reactions without wasting time checking signals constantly.

Key Points

  • RISING triggers on LOW to HIGH signal change.
  • FALLING triggers on HIGH to LOW signal change.
  • CHANGE triggers on any signal change.
  • Use interrupts to respond immediately without delay.
  • Attach interrupts using attachInterrupt() with the desired mode.

Key Takeaways

RISING triggers when signal goes from LOW to HIGH.
FALLING triggers when signal goes from HIGH to LOW.
CHANGE triggers on any signal state change.
Use these modes to react instantly to signal edges with interrupts.
attachInterrupt() sets the interrupt and mode on a pin.