Controller Digital

Rotary Encoder Module

A KY-040 rotary encoder reports rotation steps and direction with two digital signals, plus a press switch.

Part images

KY-040 Module Photo. Module Photo for the KY-040 Rotary Encoder Module. Image source: Joy-IT SensorKit KY-040 module documentation
KY-040 Pinout / Module Diagram. Pinout / Module Diagram for the KY-040 Rotary Encoder Module. Image source: Joy-IT SensorKit KY-040 module documentation
KY-040 Arduino Wiring Diagram. Arduino Wiring Diagram for the KY-040 Rotary Encoder Module. Image source: Joy-IT SensorKit KY-040 module documentation
KY-040 Raspberry Pi Wiring Diagram. Raspberry Pi Wiring Diagram for the KY-040 Rotary Encoder Module. Image source: Joy-IT SensorKit KY-040 module documentation

What it is

A KY-040 rotary encoder reports rotation steps and direction with two digital signals, plus a press switch.

How students use it

Students use it for menus, volume knobs, scrolling values, games, and precise input controls.

Pins and power

CLK, DT, SW, +/VCC, and GND on common KY-040 boards.

Passive/digital encoder module. Use Pico-safe pull-ups or module output wiring.

CLK and DT are quadrature outputs. Compare which signal changes first to determine direction.

Voltage and safety

Use Pico-safe logic levels on CLK, DT, and SW.

Do not twist past mechanical stops or soldered mounting stress.

Module internals

Main component: Incremental rotary encoder with push switch.

Encoder contacts, push switch, pull-up/support components, PCB, and header.

Datasheet notes

Mechanical encoders bounce, so code should debounce and handle step state carefully.

Common libraries

Use machine.Pin interrupts or polling with debouncing.

Common mistakes

Reading only one signal, missing debounce, counting multiple transitions per click unexpectedly, and swapping CLK/DT.