Arduino Interrupts: Respond in Microseconds, Not Loops
A loop that checks a button a thousand times a second still misses pulses that happen between checks. Interrupts invert the model: the hardware interrupts your program the instant a pin changes, running a small function before returning to exactly where execution left off.
> At a glance: 8 minute guide · part 6 of 10 in the complete Arduino guide track · includes a worked example and a quick-reference table.
## How interrupts work
You attach a function to a pin event RISING, FALLING, CHANGE or LOW with attachInterrupt(). Pins 2 and 3 carry external interrupts on the Uno. When the event fires, the CPU suspends the main loop, runs your ISR, then resumes. Response latency is microseconds, not loop iterations.
| A | s | p | e | c | t | | | |
| — | — | — | — | — | — | — | — | — |
| P | o | l | l | i | n | g | | |
| I | n | t | e | r | r | u | p | t |
| Latency | One loop pass (ms) | Microseconds | | | | | | |
| CPU cost | Constant checking | Zero until event | | | | | | |
| Code complexity | Simple | Strict ISR rules | | | | | | |
| Best for | Slow switches | Encoders, pulses, timing | | | | | | |
## The ISR rules
Keep it short, keep it simple. ISRs should set a volatile flag or capture a value never Serial. print, never delay(), never wait for anything. Variables shared with the loop must be declared volatile. Multi-byte shared values need brief interrupt disabling while the loop reads them.
## What interrupts buy you
Rotary encoders without missed steps, frequency counting, precise timing between events. Background response while the main loop is busy driving displays or sleeping. Debouncing still matters: hardware RC or a timed software filter prevents one press firing five ISRs.
## How to apply this in your build
Work through the sequence below each step assumes the previous one passed. For numbers that need calculating, the linked tools at the end of this guide do the arithmetic instantly.
1. Reserve pin 2 or 3 for the interrupt source
2. Write a minimal ISR that sets a volatile flag
3. Handle the real work in the main loop when the flag is set
4. Debounce the source so one edge means one interrupt
### Worked example
A 600 PPR encoder at 300 RPM throws 3,000 edges per second polling misses steps at that rate, while an ISR counting edges delivers a stable position every loop. Run the numbers yourself with the related calculator and the result should agree to within rounding.
> Practical note from the bench. Pattern we reuse everywhere: ISR sets flag → loop does work → loop clears flag. Nothing in the ISR but a single assignment.
## Pitfalls that cost real hardware
– Calling delay() or Serial.print() inside an ISR
– Forgetting volatile on shared variables the optimiser caches them
– Assuming one button press equals one interrupt without debouncing
## Key takeaways
– How interrupts work the foundation of this guide; revisit it if any measurement here surprises you.
– The ISR rules the foundation of this guide; revisit it if any measurement here surprises you.
– What interrupts buy you the foundation of this guide; revisit it if any measurement here surprises you.
## Prerequisites and preparation
Before starting: reserve pin 2 or 3 for the interrupt source and write a minimal isr that sets a volatile flag. Keep a calculator to hand every number in the worked example is reproducible. Total time including the bench steps: about 6–8 minutes.
## Who benefits most
Hobbyists meeting this topic for the first time, students who want the version with real numbers instead of abstract symbols. Returning engineers refreshing a corner of the craft. The mistake list alone justifies the visit every entry in it was learned the expensive way.
### Quick reference card
| Aspect | Where to find it in this guide |
| — | — |
| Core theory | How interrupts work |
| Application steps | How to apply this in your build |
| Worked numbers | Worked example |
| Failure modes | Pitfalls that cost real hardware |
## How this fits the complete Arduino guide track
This guide is one stop in the structured learning path. Start from the [complete Arduino guide](/tutorial/arduino-complete-guide) pillar page for the full map, or continue with [GPIO pin functions](/tutorial/arduino-gpio-pinout-guide) and [PWM output explained](/tutorial/arduino-pwm-explained).
## Frequently asked questions
How fast can interrupts run on an Uno?
Tens of kHz are manageable; beyond that, ISR overhead dominates and hardware counters are the right tool.
What does volatile actually do?
It forces the compiler to re-read the variable every access instead of caching it in a register.
Where do I go next?
Back to the [complete Arduino guide](/tutorial/arduino-complete-guide) pillar page it indexes every guide in this track and updates as new ones are published.
## Continue this track
– Building a foundation? The [arduino & microcontrollers complete guide](/tutorial/arduino-complete-guide) maps every step in order.
– Next: [Driving LCD and OLED Displays with Arduino](/tutorial/arduino-lcd-oled-displays)
– Next: [I2C vs SPI: Choosing and Using Both on Arduino](/tutorial/arduino-i2c-vs-spi)
– Next: [Powering Arduino Projects: USB, Battery and Supply Design](/tutorial/powering-arduino-projects)
– Work the numbers: [LED resistor finder](/tools/led-resistor) · [battery runtime estimator](/tools/battery-life) · [555 timer frequency tool](/tools/timer-555-astable)
## Bench verification habits
When a result here disagrees with your expectation, write down both numbers before changing anything. The gap between predicted and measured is where the real engineering lives. It is usually a tolerance, a parasitic or an assumption that was never checked.
Keep a lab notebook entry for every build in this track. The measured values, the deviations from the guide and the reason for each. Six months from now, those notes are worth more than any tutorial. They describe your bench and your components rather than a general case.
## Formulas and checks from this guide
Verification checklist for this track. Check pin assignments against the sketch header before wiring, confirm supply polarity twice. Serial-print one variable at a time when debugging. Keep each sketch’s pin map in a comment block so the next build inherits working documentation.
Bookmark this page against your next build in the track. The checklist above is the same one used across 15 guides in this series.
## From our lab notebook
Uninitialised variables and pins left floating. Set every pinMode and initial state in setup.
Anything with motors, servos or many LEDs needs external supply with common ground. USB is for logic only.
Procirel