KY-040 Rotary Encoder Module
Components

KY-040 Rotary Encoder Module

5.0(1)
1
The KY-040 Rotary Encoder Module is a digital knob that turns endlessly, counts one step per click and works as a push button when its shaft is pressed. Unlike a potentiometer, it reports how far and in which direction it was turned instead of an absolute position; one turn usually has 20 clicks. As the shaft turns, the CLK and DT pins produce two square waves shifted 90 degrees from each other, and the direction comes from which one changes first. The module has 5 pins (CLK, DT, SW, + and GND), runs on 3.3–5 V and has pull-up resistors on CLK and DT. In a typical setup, + goes to 5 V (3.3 V on ESP32 and Pico), CLK and DT to two interrupt-capable pins (D2 and D3 on the Arduino Uno) and SW to a pin set as INPUT_PULLUP. Because the contacts bounce, debouncing or interrupts prevent missed clicks. It is used for LCD and OLED menus, volume and brightness control, counters and stepper motor position control.

Projects using this component

ESP32 Smart Lamp with Rotary Encoder Menu (KY-040 + OLED + NeoPixel Ring)
#214Intermediate
Premium

ESP32 Smart Lamp with Rotary Encoder Menu (KY-040 + OLED + NeoPixel Ring)

One knob, five settings! Turn the KY-040 rotary encoder to scroll the menu on the 0.96 inch OLED, press it to edit the color, brightness, effect, sleep timer or warm-cool white. The 24-LED NeoPixel ring shows every change instantly. Settings live in the ESP32 flash, so after a power cut the lamp comes back exactly as you left it. Interrupt-based encoder reading and a menu UI in one project.

Raspberry Pi Pico Timelapse Camera Slider (NEMA 17 + A4988 + KY-040 + OLED)
#241Intermediate
Premium

Raspberry Pi Pico Timelapse Camera Slider (NEMA 17 + A4988 + KY-040 + OLED)

Build your own slider for cinematic sliding shots! The Raspberry Pi Pico turns a NEMA 17 stepper very slowly and smoothly through an A4988 driver, and the carriage carries a phone or camera along a rail. With a KY-040 encoder you pick the mode, distance, time, direction and frame count from a menu. In VIDEO mode the carriage eases in and out; in TIMELAPSE mode it stops at every frame and waits for the shake to settle. The OLED shows progress and time left.

Arduino Countdown Socket Timer (KY-040 Rotary Encoder + I2C LCD + Relay)
#242Intermediate
Premium

Arduino Countdown Socket Timer (KY-040 Rotary Encoder + I2C LCD + Relay)

Pick a time, press, and let the timer do the rest! The KY-040 rotary encoder sets anything from 5 seconds to 12 hours, and turning fast jumps in 10-minute steps. The relay has three modes: off when time is up, on when time is up, or an on/off cycle. The I2C LCD shows the time left, beeps warn you in the last seconds, the last setting is kept in EEPROM and the relay always starts safely off after a power cut.

ESP32 Hangman Game (OLED + KY-040 Rotary Encoder + Buzzer)
#245Intermediate
Premium

ESP32 Hangman Game (OLED + KY-040 Rotary Encoder + Buzzer)

The classic notebook game hangman on an ESP32 and a 0.96 inch OLED! Turning the KY-040 rotary encoder slides the alphabet strip, pressing it guesses the selected letter. A correct letter flies into place and the green LED lights up; a wrong one adds a piece to the gallows while the red LED and the buzzer complain. Turkish and English words, three categories, a best streak and a two-player mode.