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

How to Use Rotary encoder with button: Examples, Pinouts, and Specs

Image of Rotary encoder with buttonDesign with Rotary encoder with button in Cirkit Designer

Introduction

A rotary encoder with an integrated push button is a versatile electronic component used to convert rotational position into an analog or digital signal. This component is widely used in various applications, including:

Explore Projects Built with Rotary encoder with button

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 with button 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

Technical Specifications

Key Technical Details

Parameter Value
Operating Voltage 3.3V to 5V
Maximum Current 10mA
Output Type Digital (Quadrature)
Push Button Rating 10mA @ 5V
Rotational Steps 20 steps per revolution
Debounce Time 5ms (recommended)

Pin Configuration and Descriptions

Pin Number Pin Name Description
1 GND Ground
2 +V Supply Voltage (3.3V to 5V)
3 SW Push Button Output
4 DT Data Output (Quadrature Signal B)
5 CLK Clock Output (Quadrature Signal A)

Usage Instructions

How to Use the Component in a Circuit

  1. Power Supply:

    • Connect the +V pin to a 3.3V or 5V power supply.
    • Connect the GND pin to the ground of your circuit.
  2. Rotary Encoder Outputs:

    • Connect the CLK pin to a digital input pin on your microcontroller.
    • Connect the DT pin to another digital input pin on your microcontroller.
  3. Push Button Output:

    • Connect the SW pin to a digital input pin on your microcontroller.

Important Considerations and Best Practices

Example Code for Arduino UNO

// Rotary Encoder with Button Example Code for Arduino UNO

#define CLK 2  // Pin connected to CLK
#define DT 3   // Pin connected to DT
#define SW 4   // Pin connected to SW

int counter = 0;  // Counter to track encoder position
int currentStateCLK;
int lastStateCLK;
bool buttonPressed = false;

void setup() {
  pinMode(CLK, INPUT);
  pinMode(DT, INPUT);
  pinMode(SW, INPUT_PULLUP);  // Enable internal pull-up resistor

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

  Serial.begin(9600);  // Initialize serial communication
}

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

  // If the state of CLK has changed, then we have a pulse
  if (currentStateCLK != lastStateCLK) {
    // If the DT state is different than the CLK state, then
    // the encoder is rotating counterclockwise
    if (digitalRead(DT) != currentStateCLK) {
      counter--;
    } else {
      // Encoder is rotating clockwise
      counter++;
    }

    Serial.print("Position: ");
    Serial.println(counter);
  }

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

  // Read the state of the push button
  if (digitalRead(SW) == LOW) {
    if (!buttonPressed) {
      Serial.println("Button Pressed");
      buttonPressed = true;
    }
  } else {
    buttonPressed = false;
  }
}

Troubleshooting and FAQs

Common Issues Users Might Face

  1. Noisy Signals:

    • Solution: Implement software debouncing to filter out noise.
  2. Unstable Readings:

    • Solution: Ensure proper pull-up resistors are used for the SW, CLK, and DT pins.
  3. Incorrect Direction Detection:

    • Solution: Verify the connections of the CLK and DT pins. Ensure they are correctly mapped in the code.

Solutions and Tips for Troubleshooting

By following this documentation, users can effectively integrate and utilize a rotary encoder with a button in their projects, ensuring accurate and reliable performance.