Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use Rotary Encoder: Examples, Pinouts, and Specs

Image of Rotary EncoderDesign with Rotary Encoder in Cirkit Designer

Introduction

The Rotary Encoder (Arduino ABX00107) is an electromechanical device designed to convert the angular position or motion of a shaft into an analog or digital signal. This versatile component is widely used for position sensing, control systems, and user input in various applications. Unlike potentiometers, rotary encoders can rotate continuously without limits, making them ideal for applications requiring infinite rotation or precise incremental adjustments.

Explore Projects Built with Rotary Encoder

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino UNO-Based Rotary Encoder Interface: A project utilizing Rotary Encoder in a practical application
Arduino UNO-Based Rotary Encoder Interface

This circuit features a rotary encoder (로터리 엔코) interfaced with an Arduino UNO microcontroller. The encoder's outputs A and B are connected to digital pins D2 and D3 for rotation detection, while its push button is connected to D4, potentially for a user input function. The encoder, push button, and a switch are all debounced using resistors, and the microcontroller is set up to receive these signals for processing, although the provided code is empty and does not define specific behaviors.

Open Project in Cirkit Designer
Image of Arduino Mega 2560 Multi-Encoder Interface System: A project utilizing Rotary Encoder in a practical application
Arduino Mega 2560 Multi-Encoder Interface System

This circuit is designed to interface multiple rotary encoders with an Arduino Mega 2560 microcontroller. Each encoder's DT (data) and CLK (clock) pins are connected to specific digital input pins on the Arduino, allowing the microcontroller to read their rotational position changes. The encoders are powered by the Arduino's 5V output and share a common ground, suggesting that the circuit may be used for input devices in a user interface or control system.

Open Project in Cirkit Designer

Common Applications

Technical Specifications

The following table outlines the key technical details of the Arduino ABX00107 Rotary Encoder:

Parameter Specification
Manufacturer Arduino
Part ID ABX00107
Operating Voltage 5V
Output Signal Digital (Quadrature: A and B phases)
Maximum Rotational Speed 100 RPM (recommended)
Shaft Type Continuous rotation
Detents 20 detents per revolution
Push Button Integrated (momentary switch)
Operating Temperature -20°C to 70°C
Dimensions 11.5mm x 12.5mm x 15.5mm

Pin Configuration and Descriptions

The rotary encoder has five pins, as described in the table below:

Pin Name Description
1 GND Ground connection
2 +5V Power supply (5V)
3 SW Push button output (active LOW)
4 DT Data signal (B phase of quadrature output)
5 CLK Clock signal (A phase of quadrature output)

Usage Instructions

How to Use the Rotary Encoder in a Circuit

  1. Power Connections: Connect the +5V pin to the 5V output of your microcontroller and the GND pin to ground.
  2. Signal Connections:
    • Connect the CLK pin to a digital input pin on your microcontroller.
    • Connect the DT pin to another digital input pin.
    • If using the push button, connect the SW pin to a digital input pin with a pull-up resistor.
  3. Debouncing: Rotary encoders may produce noisy signals due to mechanical contacts. Use software debouncing or external capacitors to filter the signals.

Arduino UNO Example Code

Below is an example code snippet for interfacing the rotary encoder with an Arduino UNO:

// Rotary Encoder Example Code for Arduino UNO
// Manufacturer: Arduino
// Part ID: ABX00107

#define CLK 2  // Connect CLK pin to digital pin 2
#define DT 3   // Connect DT pin to digital pin 3
#define SW 4   // Connect SW pin to digital pin 4

int counter = 0;  // Variable to store the encoder position
int currentStateCLK;
int lastStateCLK;
bool buttonPressed = false;

void setup() {
  pinMode(CLK, INPUT);
  pinMode(DT, INPUT);
  pinMode(SW, INPUT_PULLUP);  // Use internal pull-up resistor for the button
  Serial.begin(9600);

  // Read the initial state of CLK
  lastStateCLK = digitalRead(CLK);
}

void loop() {
  // Read the current state of CLK
  currentStateCLK = digitalRead(CLK);

  // If the state of CLK has changed, a rotation has occurred
  if (currentStateCLK != lastStateCLK) {
    // Determine the direction of rotation
    if (digitalRead(DT) != currentStateCLK) {
      counter++;  // Clockwise rotation
    } else {
      counter--;  // Counterclockwise rotation
    }

    // Print the updated counter value
    Serial.print("Position: ");
    Serial.println(counter);
  }

  // Update the last state of CLK
  lastStateCLK = currentStateCLK;

  // Check if the button is pressed
  if (digitalRead(SW) == LOW) {
    if (!buttonPressed) {
      Serial.println("Button Pressed!");
      buttonPressed = true;
    }
  } else {
    buttonPressed = false;
  }
}

Important Considerations and Best Practices

Troubleshooting and FAQs

Common Issues

  1. Unstable or Erratic Readings:

    • Cause: Signal noise or lack of debouncing.
    • Solution: Implement software debouncing or add capacitors to the signal lines.
  2. No Response from the Encoder:

    • Cause: Incorrect wiring or loose connections.
    • Solution: Double-check all connections and ensure proper power supply.
  3. Push Button Not Working:

    • Cause: Missing pull-up resistor or incorrect pin configuration.
    • Solution: Use an internal or external pull-up resistor and verify the pin setup in the code.
  4. Incorrect Direction Detection:

    • Cause: Swapped CLK and DT connections.
    • Solution: Reverse the connections of the CLK and DT pins.

FAQs

Q1: Can the rotary encoder be used with 3.3V systems?
A1: The Arduino ABX00107 is designed for 5V operation. For 3.3V systems, use a level shifter or ensure compatibility with the microcontroller's input voltage range.

Q2: How many detents does the encoder have per revolution?
A2: The encoder has 20 detents per revolution, providing precise incremental control.

Q3: Can the encoder be used for high-speed applications?
A3: The recommended maximum rotational speed is 100 RPM. For higher speeds, ensure proper signal filtering and processing.

Q4: Is the push button momentary or latching?
A4: The push button is momentary, meaning it only remains active while pressed.

By following this documentation, users can effectively integrate the Arduino ABX00107 Rotary Encoder into their projects for reliable and precise control.