Bird
Raised Fist0
Arduinoprogramming~20 mins

Rising, falling, and change triggers in Arduino - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Edge Trigger Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Detecting a Rising Edge Trigger
What will be the output on the serial monitor when the button connected to pin 2 is pressed (assuming it was previously not pressed)?
Arduino
const int buttonPin = 2;
int buttonState = 0;
int lastButtonState = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH && lastButtonState == LOW) {
    Serial.println("Rising edge detected");
  }
  lastButtonState = buttonState;
  delay(50);
}
AChange detected
BFalling edge detected
CRising edge detected
DNo output
Attempts:
2 left
💡 Hint
Think about when the button state changes from LOW to HIGH.
❓ Predict Output
intermediate
2:00remaining
Detecting a Falling Edge Trigger
What will be printed on the serial monitor when the button connected to pin 3 is pressed (assuming it was previously not pressed)?
Arduino
const int buttonPin = 3;
int buttonState = 0;
int lastButtonState = HIGH;

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

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW && lastButtonState == HIGH) {
    Serial.println("Falling edge detected");
  }
  lastButtonState = buttonState;
  delay(50);
}
ANo output
BRising edge detected
CChange detected
DFalling edge detected
Attempts:
2 left
💡 Hint
Focus on when the button state changes from HIGH to LOW.
❓ Predict Output
advanced
2:00remaining
Detecting Any Change Trigger
What will be printed on the serial monitor when the button connected to pin 4 changes state (pressed or released)?
Arduino
const int buttonPin = 4;
int buttonState = 0;
int lastButtonState = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    Serial.println("Change detected");
  }
  lastButtonState = buttonState;
  delay(50);
}
AChange detected
BNo output
CFalling edge detected
DRising edge detected
Attempts:
2 left
💡 Hint
Think about any difference between current and last button state.
🧠 Conceptual
advanced
2:00remaining
Understanding Interrupts with Rising and Falling Edges
Which statement correctly describes how to use interrupts to detect a falling edge on pin 2 in Arduino?
AattachInterrupt(digitalPinToInterrupt(2), ISR, RISING);
BattachInterrupt(digitalPinToInterrupt(2), ISR, FALLING);
CattachInterrupt(2, ISR, CHANGE);
DattachInterrupt(digitalPinToInterrupt(2), ISR, HIGH);
Attempts:
2 left
💡 Hint
Look for the correct interrupt mode for falling edge detection.
❓ Predict Output
expert
2:00remaining
Output of Combined Edge Detection with Interrupts
Given the code below, what will be the output on the serial monitor if the button connected to pin 3 is pressed and then released?
Arduino
volatile int count = 0;

void ISR() {
  count++;
}

void setup() {
  pinMode(3, INPUT_PULLUP);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(3), ISR, CHANGE);
}

void loop() {
  static int lastCount = 0;
  if (count != lastCount) {
    Serial.print("Interrupt count: ");
    Serial.println(count);
    lastCount = count;
  }
}
AInterrupt count: 2
BInterrupt count: 1
CInterrupt count: 0
DNo output
Attempts:
2 left
💡 Hint
Each press and release triggers one interrupt with CHANGE mode.

Practice

(1/5)
1. Which interrupt trigger type activates when a signal changes from LOW to HIGH on an Arduino pin?
easy
A. RISING
B. FALLING
C. CHANGE
D. LOW

Solution

  1. Step 1: Understand the meaning of RISING trigger

    The RISING trigger activates when the signal goes from LOW (0) to HIGH (1).
  2. Step 2: Compare with other triggers

    FALLING triggers on HIGH to LOW, CHANGE triggers on any change, LOW triggers when signal is LOW.
  3. Final Answer:

    RISING -> Option A
  4. Quick Check:

    LOW to HIGH = RISING [OK]
Hint: RISING means signal goes up from LOW to HIGH [OK]
Common Mistakes:
  • Confusing RISING with FALLING
  • Thinking CHANGE triggers only on RISING
  • Mixing LOW trigger with RISING
2. Which of the following is the correct syntax to attach an interrupt on pin 2 for a FALLING trigger in Arduino?
easy
A. attachInterrupt(2, ISR, RISING);
B. attachInterrupt(digitalPinToInterrupt(2), ISR, FALLING);
C. attachInterrupt(2, ISR, CHANGE);
D. attachInterrupt(digitalPinToInterrupt(2), ISR, LOW);

Solution

  1. Step 1: Identify correct function usage

    attachInterrupt requires pin number converted by digitalPinToInterrupt for portability.
  2. Step 2: Match trigger type FALLING

    attachInterrupt(digitalPinToInterrupt(2), ISR, FALLING); uses digitalPinToInterrupt(2) and FALLING correctly.
  3. Final Answer:

    attachInterrupt(digitalPinToInterrupt(2), ISR, FALLING); -> Option B
  4. Quick Check:

    Use digitalPinToInterrupt with FALLING [OK]
Hint: Use digitalPinToInterrupt(pin) with trigger type [OK]
Common Mistakes:
  • Using pin number directly without digitalPinToInterrupt
  • Mixing trigger types with wrong syntax
  • Using LOW trigger incorrectly
3. What will be the output on the serial monitor if the following Arduino code is run and the input pin changes from LOW to HIGH, then HIGH to LOW?
volatile int count = 0;
void ISR() { count++; }
void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  attachInterrupt(digitalPinToInterrupt(2), ISR, CHANGE);
}
void loop() {
  Serial.println(count);
  delay(1000);
}
medium
A. 0 0 0 ... (no change)
B. 1 1 1 ... (count increments once)
C. 2 2 2 ... (count increments twice)
D. Error: ISR cannot increment variable

Solution

  1. Step 1: Understand CHANGE trigger behavior

    CHANGE triggers on any signal change: LOW to HIGH and HIGH to LOW, so ISR runs twice.
  2. Step 2: Count increments in ISR

    Each ISR call increments count by 1, so after two changes count = 2.
  3. Final Answer:

    2 2 2 ... (count increments twice) -> Option C
  4. Quick Check:

    CHANGE triggers twice, count = 2 [OK]
Hint: CHANGE triggers on both edges, count increments twice [OK]
Common Mistakes:
  • Assuming CHANGE triggers only once
  • Forgetting volatile keyword importance
  • Thinking ISR cannot modify variables
4. Identify the error in this Arduino code snippet that tries to attach an interrupt on pin 3 for a RISING trigger:
void ISR() {
  // interrupt code
}
void setup() {
  attachInterrupt(3, ISR, RISING);
}
medium
A. ISR function must have parameters
B. attachInterrupt must be called in loop(), not setup()
C. RISING is not a valid trigger type
D. Pin number 3 should be converted using digitalPinToInterrupt()

Solution

  1. Step 1: Check attachInterrupt pin argument

    Pin number must be converted with digitalPinToInterrupt(pin) for correct interrupt mapping.
  2. Step 2: Validate other parts

    ISR has correct signature (no parameters), RISING is valid, attachInterrupt is correctly called in setup.
  3. Final Answer:

    Pin number 3 should be converted using digitalPinToInterrupt() -> Option D
  4. Quick Check:

    Use digitalPinToInterrupt for pin numbers [OK]
Hint: Always convert pin with digitalPinToInterrupt() [OK]
Common Mistakes:
  • Passing raw pin number directly
  • Thinking ISR needs parameters
  • Calling attachInterrupt in loop()
5. You want to count how many times a button connected to pin 4 changes state (pressed or released). Which interrupt trigger should you use and why?
hard
A. CHANGE, because it counts both presses and releases
B. FALLING, because it counts only releases
C. RISING, because it counts only presses
D. LOW, because it triggers when button is held down

Solution

  1. Step 1: Understand button state changes

    A button press changes signal from HIGH to LOW or LOW to HIGH depending on wiring.
  2. Step 2: Choose trigger to count all changes

    CHANGE triggers on any signal change, so it counts both presses and releases.
  3. Final Answer:

    CHANGE, because it counts both presses and releases -> Option A
  4. Quick Check:

    Count all changes = use CHANGE trigger [OK]
Hint: Use CHANGE to count all button state changes [OK]
Common Mistakes:
  • Using RISING or FALLING and missing half the events
  • Confusing LOW trigger with change detection
  • Not considering both press and release
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard