What Is an Interrupt? Wiring and Errors (2026 Guide)

What Is an Interrupt? Wiring and Errors (2026 Guide)

Normal code runs top-to-bottom in a loop. An interrupt is a hardware-level "stop everything, handle this now" signal — the moment an event happens (a pin changes, a timer fires), the CPU freezes whatever it was doing, jumps to a small ISR function, runs it, and resumes exactly where it left off, even mid-delay().

Quick answer: Polling checks a pin every loop and can miss a fast pulse; an interrupt is notified by the hardware itself, instantly. On an Arduino Uno/Nano, only pins 2 and 3 are interrupt-capable — an ESP32 can attach almost any GPIO. Keep the ISR itself tiny: no delay(), no Serial.print(), just a flag or counter.

Proof of work: the explanation and code below are Soldr's actual answer to "What is an Interrupt and how do I use it?", asked through Compoden's AI build assistant on 11 August 2026. Published 11 August 2026 · Last updated 11 August 2026.

Soldr's answer explaining interrupts: polling vs interrupt, attachInterrupt syntax, and the ISR rules that prevent lockups
Soldr's build log answering "What is an Interrupt and how do I use it?" — the polling-vs-interrupt distinction and a button-press counter sketch generated in the same session.

Which pins support interrupts, and how do you attach one?

On the Uno/Nano's ATmega328P, only pins 2 and 3 are interrupt-capable — a real hardware limit, not a software choice. An ESP32 is a different league entirely and lets you attach an interrupt to almost any GPIO. You wire one up with attachInterrupt(digitalPinToInterrupt(pin), myISR, mode), where mode is RISING, FALLING, CHANGE, or LOW depending on which edge of the signal you care about.

Interrupts at a glance
Property Value
Uno/Nano interrupt pins 2 and 3 only
ESP32 interrupt pins Almost any GPIO
Attach function attachInterrupt(digitalPinToInterrupt(pin), isr, mode)
ISR rules No delay(), no Serial.print(), no long loops — keep it to a couple of lines
Shared variables Must be declared volatile

How do you count button presses with an interrupt on an Arduino Uno?

Wire one button leg to D2 and the other to GND, with the internal pull-up enabled — pressing reads LOW, so the interrupt triggers on the FALLING edge. This is the exact setup from Soldr's session:

const byte BTN_PIN = 2; // Uno: interrupt-capable pins are 2 and 3 only
volatile unsigned long presses = 0;
volatile bool pressed = false;

void setup() {
  Serial.begin(9600);
  pinMode(BTN_PIN, INPUT_PULLUP); // button to GND, internal pull-up
  attachInterrupt(digitalPinToInterrupt(BTN_PIN), buttonISR, FALLING);
  Serial.println("[SOLDR] interrupts-demo | board:Uno | v1.0");
}

void buttonISR() {
  presses++;
  pressed = true;
}

void loop() {
  if (pressed) {
    pressed = false;
    Serial.print("Presses: ");
    Serial.println(presses);
  }
}

The setup() and the interrupt-capable pin comment are verbatim from the session's Firmware tab; buttonISR() and loop() follow the exact pattern the session's own explanation describes ("the ISR just sets a flag / increments a counter; loop does the actual work") rather than being independently invented — not independently compile-checked for this post.

Why does my board freeze or behave strangely with an ISR attached?

The classic mistake is putting real work inside the ISR — calling delay(), printing to Serial, or running a long loop. Serial itself is interrupt-driven, so calling Serial.print() from inside another interrupt can deadlock the board. A close second: forgetting volatile on any variable shared between the ISR and loop() — without it, the compiler can optimize away the fact that the value ever changes, and your loop reads a stale copy forever.

What do you need to try this yourself?

An Uno R3 CH340G ATmega328P Board (Rs.230) — pins 2 and 3 are exactly what the demo above uses — and a Tactile Button Pack (10x 6mm Switches) (Rs.95).

Frequently asked questions

Interrupt aur polling mein kya fark hai?

Polling mein aap loop ke har cycle mein pin check karte hain, jisse ek bahut fast pulse miss ho sakta hai. Interrupt mein hardware khud CPU ko turant batata hai jab event hota hai, chahe CPU kitna bhi busy ho - isliye interrupt polling se zyada reliable hai fast events ke liye jaise rotary encoders ya HC-SR04 timing.

Why can't I use delay() inside an interrupt service routine?

delay() itself depends on an interrupt-driven timer internally, and calling it from inside another interrupt can hang the board since interrupts are typically disabled while an ISR runs. Keep the ISR to setting a flag or incrementing a counter, and do any real work - including delays - back in loop() once the flag is checked.

What is the price of an Arduino Uno for learning interrupts in India?

The Uno R3 CH340G ATmega328P Board costs Rs.230 at Compoden, with cash on delivery available across India. Add a Tactile Button Pack (Rs.95) for the exact button-counter demo in this guide - Rs.325 total. Prices checked 11 August 2026.

Do I need to declare every variable volatile?

No - only variables that are written inside an ISR and also read in loop() (or vice versa) need volatile. It tells the compiler not to optimize away re-reads of that variable, since its value can change at any moment from the interrupt, independent of the normal flow of loop().

Back to blog