Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
Rotary encoder board with a knob and header connections for a menu control

Make a Rotary Encoder Menu Respond Reliably: Quadrature, Bounce and Detents

A rotary encoder can feel excellent mechanically and still produce an irritating menu: one click sometimes moves twice, fast turning loses steps, or pressing the knob changes the selected value. These faults usually become easier to solve when the electrical signals, decoder and user-interface behaviour are tested separately.

PMD Way's rotary encoder collection includes an encoder board with knob in a five-pack. The listing specifies 20 notches per revolution and 3.3 V or 5 V operation. A notch count does not establish the number of electrical transitions per turn, and a board that operates at either supply does not automatically translate between logic voltages.

Read two signals as one movement

A basic incremental quadrature encoder provides two channels, usually described as A and B. Their sequence identifies direction. One valid sequence is 00, 01, 11, 10, 00; reversing the movement reverses that sequence. Which physical direction you call positive depends on channel order and the installed orientation.

At each valid transition only one bit changes. A jump from 00 directly to 11 is ambiguous: an intermediate state was missed, or the signals are not being read reliably. A decoder should not invent a direction from that observation. Track invalid transitions as a diagnostic, then investigate their cause.

The PJRC Encoder library documentation explains quadrature and its four-count-per-cycle approach. Use its documented behaviour when integrating the library; do not assume its raw count is already one increment per mechanical click.

Verify the board's pull-up arrangement

With power disconnected, identify ground, supply, both encoder signals and any push-switch output from the actual board markings or schematic. Header order is not standardised by the appearance of the module. Check whether resistors pull signals up to the board's supply.

If a board pulls its outputs towards 5 V, connecting those outputs directly to inputs limited to 3.3 V can exceed the host's limits. Use a verified compatible supply arrangement or suitable level translation. Check the switch output too: it can have a different resistor arrangement from the rotary channels.

After confirming compatibility, measure the idle levels and observe both channels while turning slowly. A logic analyser is useful for recording the sequence; an oscilloscope can reveal slow edges and electrical noise that a simple digital capture may hide. Keep the initial wiring short and establish a reliable ground connection.

Do not confuse detents, pulses and counts

A detent is the tactile click. An electrical pulse is part of the waveform. A decoded count depends on whether software counts one, two or four edges per cycle. These quantities are related by the particular encoder and decoding method, not by a universal multiplier.

The Bourns PEC11R datasheet illustrates this clearly by offering different detent and pulse combinations. It is a manufacturer example, not an identification of the component fitted to the PMD Way board.

Make a bench record: start at a detent, turn ten clicks slowly clockwise and note the raw count; return ten clicks and check the result. Repeat in both directions. Observe the signal state at rest. Use those measurements and the component documentation to choose a full-step or half-step decoding mode, or another appropriate count conversion.

Handle bounce without throwing away real motion

Mechanical contacts can produce several rapid changes around a transition. Bourns specifies contact bounce and a suggested filter for its example encoder. The relevant times and filter values must come from the actual component and input circuit; do not transfer them blindly to another module.

A state-machine decoder follows the allowed two-bit sequence. With sufficiently complete sampling, brief forward-and-back transitions can cancel before a completed movement is reported. This is more informative than treating every edge as a new menu action. It still cannot reconstruct states that the software failed to observe.

A long fixed pause after every edge can suppress bounce but also discard genuine movement. Similarly, adding large capacitors indiscriminately can delay one channel relative to the other and distort the sequence. Evaluate any filtering with the fastest intended hand movement and the input's switching thresholds.

Keep acquisition separate from drawing

Polling can work when the program checks the inputs frequently enough. The danger is a long display update, serial print or blocking delay that stops sampling. Interrupt-driven acquisition can reduce that problem, but long periods with interrupts disabled can still lose transitions.

Arduino's attachInterrupt documentation lists supported pins for each board and recommends using digitalPinToInterrupt when attaching an interrupt. Keep the interrupt routine short. Record movement there and update the display in the main program; do not call delay or perform slow screen drawing inside the handler.

If an interrupt and the main program share a multi-byte counter, use the platform's appropriate atomic access or a library that handles it. Declaring a variable volatile does not by itself make every multi-byte read indivisible. Prefer the library's supported read method rather than accessing its internal state.

Turn movement into a predictable menu

Convert validated motion into user-interface events such as next item, previous item or increase value. Keep this conversion separate from the raw signal decoder. That makes it possible to change menu behaviour without changing the electrical interpretation.

For a value with limits, clamp it at the minimum and maximum. For a circular list, deliberately wrap from the last item to the first. Do not let integer overflow accidentally choose the behaviour. Make the displayed value and the value used by the application agree.

Disable acceleration during initial testing. Once one click consistently produces one intended action, optional acceleration can make large changes easier. Reset its speed history after a pause or direction reversal so a careful correction is not interpreted as another fast sweep.

Test the push switch independently

If the encoder includes a push switch, debounce it as a separate input. Decide whether activation happens on the press or release, and distinguish a short press from a long press only if both actions are needed. A single physical press should not accidentally trigger both.

Test pressing without turning and turning while maintaining light pressure. Ensure the knob clears the panel and the board is supported. If the raw rotary count changes when pressing a stationary knob, inspect the mechanical movement and signal trace before masking the symptom in menu code.

Use an acceptance test before adding features

  • Move twenty clicks forward and twenty back slowly; confirm the expected final selection.
  • Repeat quickly while the display redraws and communication is active.
  • Reverse direction midway between detents and check for an unexplained jump.
  • Leave the control untouched and verify there are no spontaneous events.
  • Restart the device and confirm the initial displayed value is intentional.

Keep the raw count, invalid-transition count and final menu action available during development. When a failure occurs, these reveal whether the problem began at the contacts, in signal acquisition or in the menu logic. That separation produces a control that remains dependable when the rest of the project becomes more demanding.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat