# Interrupt (Hardware)

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

**Field:** Software Development  
**Category:** Embedded & IoT  
**Also known as:** Hardware Interrupt, Interrupt Service Routine, attachInterrupt

## Think of it like

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

## 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

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.

## Example code

```cpp
attachInterrupt(digitalPinToInterrupt(2), onPress, FALLING);
```

This line says: when pin 2 falls from high to low, run onPress at once.

## Why it matters

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

## 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.

## Three principles

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

## Related terms

- [General-Purpose Input/Output (GPIO)](https://learn.benibix.com/term/development/gpio)
- [Polling](https://learn.benibix.com/term/development/polling)
- [Real-Time Operating System (RTOS)](https://learn.benibix.com/term/development/real-time-operating-system)
- [Microcontroller (MCU)](https://learn.benibix.com/term/development/microcontroller)
- [Event Loop](https://learn.benibix.com/term/development/event-loop)

![Four rows, one per kind of pin signal. GPIO: a line that is either high or low, on or off. ADC: a knob turns a smooth voltage into a number from 0 to 1023. PWM: two square waves, one on a quarter of the time for a dim light and one on three quarters of the time for a bright one. Interrupt, lit up: a button press makes the chip stop its loop at once, run a short handler, then go back.](https://learn.benibix.com/diagrams/dev4-pin-signals.svg)

---

Source: https://learn.benibix.com/term/development/interrupt
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
