Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

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

Image of Rotary Encoder
Cirkit Designer LogoDesign with Rotary Encoder in Cirkit Designer

Introduction

A rotary encoder is an electro-mechanical device that converts the angular position or motion of a shaft into analog or digital output signals. Rotary encoders are widely used in various applications, including industrial controls, robotics, position sensing, and user input devices like volume controls and navigational menus.

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!
Arduino Mega and Nano-Based Dual Rotary Encoder Controller with AC-DC Power Supply
Image of dual_encoder_v1: A project utilizing Rotary Encoder in a practical application
This circuit features an Arduino Mega 2560 and two Arduino Nano microcontrollers interfacing with two rotary encoders for input. The system is powered by an AC-DC PSU board converting 220V AC to 5V DC, and the microcontrollers communicate with each other via serial connections. The setup is designed for reading rotary encoder inputs and potentially processing or transmitting the data.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Rotary Encoder Interface
Image of encoder: A project utilizing Rotary Encoder in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Mega 2560 Multi-Encoder Interface System
Image of 엔코더: A project utilizing Rotary Encoder in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
RP2040 Zero Rotary Encoder Interface with Serial Monitoring
Image of test: A project utilizing Rotary Encoder in a practical application
This circuit features an RP2040 Zero microcontroller interfaced with a rotary encoder. The encoder's clock, data, and switch pins are connected to the microcontroller's GPIO pins 29, 28, and 27, respectively, allowing the microcontroller to read the encoder's state and print it to the serial monitor.
Cirkit Designer LogoOpen Project in Cirkit Designer

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 dual_encoder_v1: A project utilizing Rotary Encoder in a practical application
Arduino Mega and Nano-Based Dual Rotary Encoder Controller with AC-DC Power Supply
This circuit features an Arduino Mega 2560 and two Arduino Nano microcontrollers interfacing with two rotary encoders for input. The system is powered by an AC-DC PSU board converting 220V AC to 5V DC, and the microcontrollers communicate with each other via serial connections. The setup is designed for reading rotary encoder inputs and potentially processing or transmitting the data.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of encoder: 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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of 엔코더: 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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of test: A project utilizing Rotary Encoder in a practical application
RP2040 Zero Rotary Encoder Interface with Serial Monitoring
This circuit features an RP2040 Zero microcontroller interfaced with a rotary encoder. The encoder's clock, data, and switch pins are connected to the microcontroller's GPIO pins 29, 28, and 27, respectively, allowing the microcontroller to read the encoder's state and print it to the serial monitor.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

  • Position Sensing: Rotary encoders are used to determine the position of a moving part.
  • Speed Control: They can monitor and report the speed of a rotating shaft.
  • User Input: Encoders provide input for devices, allowing users to scroll through menus or adjust settings.
  • Industrial Automation: They are integral in control systems for feedback on motor positioning.

Technical Specifications

Key Technical Details

  • Voltage Rating: 3.3V to 5V
  • Current Rating: 10mA to 30mA
  • Output Signal: Quadrature (Incremental) or Absolute
  • Resolution: Typically ranges from 12 to 1024 pulses per revolution (PPR)

Pin Configuration and Descriptions

Pin Number Name Description
1 VCC Power supply (3.3V to 5V)
2 GND Ground connection
3 OUTA Output A - Quadrature output 1
4 OUTB Output B - Quadrature output 2
5 SW Switch (push button)

Usage Instructions

How to Use the Component in a Circuit

  1. Power Connection: Connect the VCC pin to a 3.3V or 5V power supply and the GND pin to the ground.
  2. Output Connection: Connect OUTA and OUTB to two digital input pins on a microcontroller to read the encoder's rotation.
  3. Button Connection: If the encoder has a push-button switch, connect the SW pin to another digital input pin.

Important Considerations and Best Practices

  • Debouncing: Rotary encoders are mechanical devices and may require debouncing, either through hardware or software, to ensure accurate readings.
  • Pull-Up Resistors: Use pull-up resistors on the output lines to ensure a stable high signal when the contacts are open.
  • Interrupts: For more accurate reading, use interrupts on the microcontroller to detect changes in the encoder's output.

Example Code for Arduino UNO

// Define the pins for the rotary encoder
const int encoderPinA = 2; // Output A
const int encoderPinB = 3; // Output B
const int buttonPin = 4;   // Push button switch

volatile int lastEncoded = 0;
volatile long encoderValue = 0;

void setup() {
  pinMode(encoderPinA, INPUT_PULLUP);
  pinMode(encoderPinB, INPUT_PULLUP);
  pinMode(buttonPin, INPUT_PULLUP);
  
  // Set up interrupts for the encoder pins
  attachInterrupt(digitalPinToInterrupt(encoderPinA), updateEncoder, CHANGE);
  attachInterrupt(digitalPinToInterrupt(encoderPinB), updateEncoder, CHANGE);
}

void loop() {
  // Use encoderValue for your application
}

void updateEncoder() {
  int MSB = digitalRead(encoderPinA); // Most significant bit
  int LSB = digitalRead(encoderPinB); // Least significant bit

  int encoded = (MSB << 1) | LSB; // Converting the 2 pin value to single number
  int sum = (lastEncoded << 2) | encoded; // Adding it to the previous encoded value

  if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue++;
  if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue--;

  lastEncoded = encoded; // Store this value for next time
}

Troubleshooting and FAQs

Common Issues Users Might Face

  • Inaccurate Readings: This can be due to noise or debouncing issues. Implement software debouncing or add hardware debouncing circuits.
  • No Response: Ensure that the encoder is powered correctly and that the pins are connected to the correct microcontroller pins.
  • Erratic Behavior: Check for loose connections or damaged components. Also, ensure that pull-up resistors are in place if required.

Solutions and Tips for Troubleshooting

  • Debouncing: Implement a simple software debounce using delay functions or more advanced techniques like state machines.
  • Check Connections: Verify all connections are secure and correct. Use a multimeter to ensure continuity where expected.
  • Pull-Up Resistors: If not using internal pull-ups, add external pull-up resistors (typically 10kΩ) to the output lines.

FAQs

Q: Can I use a rotary encoder with an Arduino without external libraries? A: Yes, you can use interrupts as shown in the example code, or you can poll the encoder in the loop() function.

Q: How do I know if my rotary encoder is incremental or absolute? A: Incremental encoders provide relative position with no fixed start or end point, while absolute encoders provide a unique position for each angle of the shaft. Check the datasheet of your specific encoder to determine its type.

Q: What is the purpose of the push-button on some rotary encoders? A: The push-button can be used as a user input, often to select an option after scrolling through a menu with the encoder.