Rotary Encoder Module — CLK/DT/SW Output, 20 Detents, Arduino Compatible (KY-040)
Rotary Encoder Module CLK/DT/SW Output, 20 Detents, Arduino Compatible (KY-040)
Compatible JST cables for sensors and modules — secure & reliable. Shop now.
Couldn't load pickup availability
Rotary Encoder Module — CLK/DT/SW Output, 20 Detents, Arduino Compatible (KY-040)
This rotary encoder module (KY-040 compatible) is an incremental position sensor that reports the direction and amount of shaft rotation, plus a pushbutton press when the shaft is depressed. It's the essential input device for Arduino menu navigation, volume control, and any application requiring continuous rotary input without a mechanical stop. The module includes a built-in pull-up resistor on the SW pin and a 5-pin header for direct connection to Arduino.
Module Specifications
- Type: Incremental rotary encoder (no absolute position)
- Detents per Revolution: 20 (20 clicks = 1 full rotation)
- Outputs: CLK (A), DT (B), SW (pushbutton)
- Operating Voltage: 3.3V – 5V DC
- Pushbutton: Active LOW (shaft press)
- Rotation: Continuous (no mechanical stop, infinite turns)
- PCB Dimensions: 26 × 20mm
- Shaft Height: 30mm total
5-Pin Header Connections
- GND: Ground
- +: VCC (3.3V or 5V)
- SW: Pushbutton output (active LOW) → Arduino digital input
- DT: Direction output (B phase, 90° lag) → Arduino digital input
- CLK: Clock output (A phase) → Arduino digital input
Direction Detection Logic
- Clockwise (CW): When CLK changes state, DT ≠ CLK
- Counter-Clockwise (CCW): When CLK changes state, DT = CLK
- Compare CLK and DT states on each CLK edge to determine rotation direction
Arduino Wiring
- GND → Arduino GND | + → 5V
- CLK → D6 | DT → D5 | SW → D7 (with INPUT_PULLUP)
Typical Applications
- LCD menu navigation: Scroll through menu items (rotate) and select (press) — the most common use case
- Volume / parameter control: Adjust audio volume, motor speed, or any continuous parameter
- Stepper motor control: Rotate encoder to drive stepper motor in same direction and amount
- Odometer / distance measurement: Attach wheel to shaft and count pulses for distance
- Position tracking: Track relative position from power-on reference point
Package Contents
- 1 × Rotary encoder module (KY-040 compatible) with 5-pin header
20 detents, infinite rotation, CLK/DT/SW outputs — the KY-040 rotary encoder module is the go-to input device for Arduino menu navigation, volume control, and continuous rotary position sensing.

Blog posts
View all-
Best JST Connector Crimping Tools in 2026: Engi...
Choosing the wrong crimping tool ruins JST connectors and wastes wire. This guide compares the top crimping tools for JST SH, GH, PH, XH, and VH series — including Engineer...
Best JST Connector Crimping Tools in 2026: Engi...
Choosing the wrong crimping tool ruins JST connectors and wastes wire. This guide compares the top crimping tools for JST SH, GH, PH, XH, and VH series — including Engineer...
-
Molex KK 254 vs Mini-Fit Jr. vs Micro-Fit 3.0: ...
Choosing between Molex KK 254, Mini-Fit Jr., and Micro-Fit 3.0? This guide compares pitch, current rating, locking mechanism, wire gauge, and typical applications — with decision tables, part number references,...
Molex KK 254 vs Mini-Fit Jr. vs Micro-Fit 3.0: ...
Choosing between Molex KK 254, Mini-Fit Jr., and Micro-Fit 3.0? This guide compares pitch, current rating, locking mechanism, wire gauge, and typical applications — with decision tables, part number references,...
-
DuPont Connector vs JST PH 2.0: Pinout, Specs &...
Not sure whether to use a DuPont 2.54mm or JST PH 2.0mm connector? This guide compares pitch, locking mechanism, current rating, pinout, and best use cases — so you can...
DuPont Connector vs JST PH 2.0: Pinout, Specs &...
Not sure whether to use a DuPont 2.54mm or JST PH 2.0mm connector? This guide compares pitch, locking mechanism, current rating, pinout, and best use cases — so you can...