Skip to content
BENIBIX Learn

Interrupt (Hardware)

Development🔌 Embedded & IoTInputs and Outputs

Also known as Hardware Interrupt, Interrupt Service Routine, attachInterrupt

A signal that makes a chip drop its work at once and deal with an event.

Think of it like

It is like a doorbell. You do not keep checking the door, because the bell tells you.

Example

On an Arduino Uno, only pins 2 and 3 can trigger an interrupt. Jack wires a button to pin 2, and each press runs his handler right away.

Why it matters

Events like a button press can be over in a blink. An interrupt makes sure the chip never misses one.

Definition

An interrupt is a signal that makes a chip stop what it is doing at once. A pin change, a timer or a new byte of data can trigger one. The chip jumps to a short piece of code called an interrupt handler. When the handler ends, the chip goes back to where it was. This beats checking the pin over and over in a loop.

Example code

cpp
attachInterrupt(digitalPinToInterrupt(2), onPress, FALLING);
This line says: when pin 2 falls from high to low, run onPress at once.
An interrupt, bottom row, breaks into the loop and then hands back.

Common mistake

Doing slow work inside the handler, like waiting or printing. Keep it short, set a flag, and do the rest in the main loop.

Key takeaways

  1. 1
    Instant. The chip stops what it is doing.
  2. 2
    Short handler. Do the least, then return.
  3. 3
    No polling. No need to keep checking.