Search for your product name or keyword, or use the product categories below

KY-040 Rotary Encoder / Rotation Sensor Module

< All Topics

KY-040 Rotary Encoder / Rotation Sensor ModuleThe KY-040 rotary encoder / rotation sensor module is a 360-degree rotary input device (i.e. a control knob) that provides an indication of how much the knob has been rotated AND which direction it is rotating in.

The KY-040 rotary encoder has a fixed number of 20 positions per revolution. These positions are felt as small “clicks” when you turn the encoder. Inside the encoder, there are two switches. One switch connects pin A to pin C and the other switch connects pin B to C. In each encoder position, both switches are either opened or closed. Each click causes these switches to change states. If both switches are closed, turning the encoder either clockwise or counterclockwise one position will cause both switches to open. If both switches are open, turning the encoder either clockwise or counterclockwise one position will cause both switches to close.

Determining which switch changed states first is how the direction of rotation is determined. If A changed states first, the switch is rotating in a clockwise direction. If B changed states first, the switch is rotating in a counter clockwise direction.

A push button switch is built into this encoder. If you push on the shaft, the normally open switch “SW” will close. This can be used as an On/Off switch, or to change control functions, ranges, etc.

KY-040 Rotary Encoder Module Pin-Outs

CLK: Encoder Pin A
DT: Encoder Pin B
SW: Pushbutton On/Off Switch
+: +5V DC Power Supply
GND: Ground (Encoder Pin C)

KY-040 Rotary Encoder References and Tutorials

There are numerous online tutorials, references and videos covering the use of the KY-040 Rotary Encoder. Rather than rehashing them here, below are links to some that we have found to be most helpful:

How Rotary Encoder Works and How To Use It with Arduino on How To Mechatronics: https://howtomechatronics.com/tutorials/arduino/rotary-encoder-works-use-arduino/

Coding a KY-040 Rotary Encoder on a Raspberry Pi Pico on GurgleApps.com: https://gurgleapps.com/learn/electronics/ky-040-rotary-encoder-on-a-raspberry-pi-pico-detailed-explanation-and-step-by-step-code

Wiring of KY-040 Rotary Encoder plus Demo Code on the Arduino Forum: https://forum.arduino.cc/t/wiring-of-ky-040-rotary-encoder-plus-demo-code/235847

Best code to use with a KY-040 Rotary Encoder? Let’s find out! on Brainy Bits: https://www.brainy-bits.com/post/best-code-to-use-with-a-ky-040-rotary-encoder-let-s-find-out

How to use Rotary Encoder with Arduino video by Mario’s Ideas on YouTube:

Copyright © 2024 Envistia Mall
www.envistiamall.com

EM-ECOMP-0004

Table of Contents