Infinite Dials: Rotary Encoder Setup
A potentiometer stops turning at 270 degrees. But the volume knob on your car radio turns forever. That is a Rotary Encoder, a digital sensor that measures "clicks" of rotation instead of analog resistance.

Quadrature Output Logic
The Encoder outputs two digital signals (Pin A and Pin B) in a specific overlapping pattern known as "Gray Code" or "Quadrature."
- When you turn clockwise, Pin A triggers slightly before Pin B.
- When you turn counter-clockwise, Pin B triggers slightly before Pin A.
- The Arduino relies on Hardware Interrupts to read exactly which pin triggered first, updating a global variable (e.g.,
volumeLevel++orvolumeLevel--).
Key Hardware
- Arduino Uno/Nano.
- KY-040 Rotary Encoder Module: This comes with a built-in push-button on the shaft.
- An Output: A piezo buzzer to test frequency changing, or an I2C LCD to display the current volume number from 0 to 100.
Debouncing a Nightmare
Rotary encoders are notoriously "noisy." Because they rely on physical metal contacts scraping inside the dial, one "click" might register as ten rapid clicks to the Arduino. You must use hardware debouncing (capacitors) or software libraries to ensure you only read one clean number-jump per turn. This is an advanced signal-processing skill!