All projects

Professional embedded

Hardware interrupt

Intermediate40 min

React instantly to an external event without polling the pin in a loop.

What you get

A pulse counter that never misses an event, even during a long computation.

Parts (simulated)

  • Arduino UNO board
  • Push button
  • LED and 220 Ω resistor

Nothing to buy: every component here is simulated in the browser.

Project steps

  1. 01Compare polling and interrupts on the same circuit.
  2. 02Attach an interrupt routine to a pin.
  3. 03Respect the three ISR rules: short, non-blocking, no Serial.
  4. 04Declare shared variables as volatile.

What you learn

  • Hardware interrupts
  • The volatile keyword
  • Debouncing
  • Polling vs interrupts

Other projects