Rotary encoder module (KY-040)
Knob that turns endlessly and gives clicks plus a push button.
What is the Rotary encoder module (KY-040) and what is it used for?
Knob that turns endlessly and gives clicks plus a push button. Makers use it for menus, volume knobs.
Two switches close in a staggered (quadrature) pattern as the shaft turns, so the order of the pulses shows direction.
Key specifications
| Sensor spec | Value |
|---|---|
| Measures | Rotation steps and direction |
| Range | 20 detents per turn typical |
| Interface | Two quadrature digital outputs plus switch |
| Supply voltage | 5 V |
Pinout
How to use it
Read CLK and DT with interrupts or a library such as Encoder. Direction comes from which output changes first. Mechanical contacts bounce, so filter in software or with 100 nF capacitors to ground.
Applications
Builds that use it
Rotary encoder menu on an OLED
Tap tempo metronome
LCD menu system
USB macro keypad
ESP32 internet radio
Voice-style multi kitchen timers
Function generator with DDS
FM radio with station names (RDS)
Alternatives
- AS5600 magnetic angle encoderAbsolute angle with no contact wear
- Incremental rotary encoder 600 PPRHigh resolution optical encoder
Common questions
What is the Rotary encoder module (KY-040) used for?
In maker projects: menus, volume knobs.
How does the Rotary encoder module (KY-040) work?
Two switches close in a staggered (quadrature) pattern as the shaft turns, so the order of the pulses shows direction.
What voltage does the Rotary encoder module (KY-040) need?
5 V.
How do I connect the Rotary encoder module (KY-040) to an Arduino or ESP32?
Two quadrature digital outputs plus switch. Pins: CLK (Output A), DT (Output B), SW (Push switch, LOW when pressed), + (3.3 to 5 V for the pull-ups), GND (Ground).
What can I use instead of the Rotary encoder module (KY-040)?
AS5600 magnetic angle encoder and Incremental rotary encoder 600 PPR.
