The 5 pins of a typical rotary encoder (e.g., mechanical or incremental) serve specific functions to detect rotation direction, position, and user interaction. Here’s a breakdown of their roles:
5-Pin Encoder Pinout and Functions
Pin | Name | Function |
---|---|---|
1 | GND | Ground connection (0V reference). |
2 | VCC | Power supply (usually 3.3V or 5V). |
3 | SW | Switch Pin: Outputs a signal when the encoder knob is pressed (like a button). |
4 | DT (B) | Channel B (Data): One of two quadrature outputs to detect rotation direction. |
5 | CLK (A) | Channel A (Clock): Primary output for rotation pulses. Combined with DT, determines direction. |
How It Works
-
Rotation Detection (CLK + DT):
-
Quadrature Output: Channels A (CLK) and B (DT) produce square waves 90° out of phase.
-
Direction: The phase difference indicates direction (e.g., CLK leading DT = clockwise; DT leading CLK = counterclockwise).
-
Resolution: Each "click" generates a pulse on both pins (e.g., 24 pulses per rotation).
-
-
Button Press (SW):
-
Acts as a momentary switch (connects to GND when pressed).
-
Often used for menu selection or reset in interfaces.
-
-
Power (VCC + GND):
-
Powers the encoder’s internal circuitry (if active) or provides reference for pull-up resistors (if passive).
-
Example Circuit Connection
Key Notes
-
Pull-Up Resistors: Required on CLK, DT, and SW (typically 10kΩ) to ensure clean signals.
-
Debouncing: Software or hardware debouncing is needed for SW and rotation signals to avoid false triggers.
-
Types: Some encoders omit the SW pin (3-pin or 4-pin versions).
Common Applications
-
Volume knobs, motor control, menu navigation (e.g., Arduino, Raspberry Pi projects).
Let me know if you need help wiring or coding it!