2 · Inputs & sensors
Hardware interrupts
Expert25 min
Goal
Count pulses without ever missing one thanks to attachInterrupt().
Why it matters
An interrupt suspends the loop instantly: essential for a tachometer or a flow meter.
Steps
- 01Wire the pulse source to pin 2 (INT0).
- 02Declare volatile unsigned long counter = 0;
- 03attachInterrupt(digitalPinToInterrupt(2), isr, FALLING);
- 04Print the counter inside loop() (never inside the ISR).
This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.
Next tutorials
- Read a push button
Light the LED only while the button is pressed.
- Toggle button (debounced)
One press turns on, the next turns off — with no contact bounce.
- Read a potentiometer
Print the analog value of A0 on the serial monitor.
- Convert to volts (map & float)
Turn the ADC's 0–1023 into a 0.00–5.00 V reading.