Bourns PEC11R Rotary Encoder Counter

Turn a clicky 24-detent knob and watch a counter increment or decrement live — the foundation of every menu wheel and volume knob.

Difficulty: Breadboard. Estimated build time: about 30 minutes. Estimated parts cost: about US$3.50. 5-line bill of materials. Compare supplier offers when available. An incremental rotary encoder that converts the motion of your knob into a stream of digital pulses, decoded by the Arduino into a signed counter.

Wire the encoder

The PEC11R has five pins: A, GND (common), B on one side, plus two button pins on the other side. Solder it to a small bit of perfboard or to a breakout (Sparkfun and Adafruit both sell ones). Connect A to Arduino D2, common to GND, and B to D3. D2 and D3 are the UNO's two external-interrupt-capable pins — important for fast decoding. Wire the button pins to D4 with the other side to GND.

Enable internal pull-ups

Configure D2, D3, and D4 with INPUT_PULLUP. The encoder switches the channels to GND when closed; with the internal pull-ups, the idle state of each channel is HIGH and the active state is LOW. No external resistors needed. The button works the same way: pressed = LOW.

Decode quadrature in an interrupt

Attach an interrupt on D2 (channel A) triggered on CHANGE. In the ISR, read channel B's current state with digitalRead(3). If A and B disagree (one HIGH, one LOW), the knob turned one direction; if they agree, it turned the other. Increment or decrement a volatile long counter accordingly. Print the counter in loop() so you can see clicks add up live in Serial Monitor.

Add debouncing for the button

The shaft push-button bounces for a few milliseconds each press. In loop(), check digitalRead(4); if it's been stable LOW for >5 ms, count one press. This is the same software debouncer as any other tactile switch. With the counter and the press both working, you've built the minimum-viable scroll wheel — swap the Serial print for an OLED and you have a navigable menu.