Rotary Encoder Module

Continuously variable position sensor with pushbutton Description The Rotary Encoder Module is a continuously variable position sensor...
Vendor: Keszoox
$1.25
$2.25
$1.25

Shipping

The shipping fee depends on your address

Standard: 9-15 business days,fee is down to $3.99

Express: 4-7 business days,fee is down to $5.99

Support Customization

WE'RE READY TO BUILD A CUSTOM PRODUCT FOR YOU.

If you're looking for a custom product, we can help. Kindly contact us via email support@keszoox.com and send us the details for your need, then we'll let you know how we can deliver the right solution.

Built And process your order

We make into production usually Within 1 - 3 Bussiness Days.

Expect customization orders.
Rotary Encoder Module

Rotary Encoder Module

$2.25 $1.25

Rotary Encoder Module

$2.25 $1.25

Continuously variable position sensor with pushbutton

Description

The Rotary Encoder Module is a continuously variable position sensor that reports the relative position of the shaft, the direction of rotation and if the shaft is depressed.

PACKAGE INCLUDES:

  • Rotary Encoder Module

KEY FEATURES OF ROTARY ENCODER MODULE:

  • Reports relative position of the shaft
  • Reports the direction of rotation of the shaft
  • Reports if the shaft is depressed like a pushbutton
  • 3.3 and 5V compatible

Rotary encoders can be used for a number of different useful applications.  One of the most common applications is to use it to scroll through information like a menu on an LCD display such as a 16 x 2 line LCD display and then select that item on the display when the shaft is pushed.  It could be used for interacting with a stepper motor or something similar where rotation the rotary encoder results in a similar rotation of the stepper motor.  Another application could be to attach a wheel of a known diameter to the shaft and as the wheel is rotated along the ground, the distance covered can be calculated.

The rotary encoder is an incremental encoder which means that it outputs a pulse each time that the shaft is rotated one detent (click).  The position is kept track of relative to the position that the shaft was in when the controller is first powered on, so it does not have a sense of a specific physical position, but from the software perspective it knows it has gone 5 detents from where it started.

It is continuously variable which means you can continue to spin the shaft around in one direction for as long as you want.  It has not mechanical stop.

In addition, the encoder can also detect whether the shaft is being turned in the clockwise (CW) or counterclockwise (CCW) direction. In the LCD menu example, that lets the software know if it needs to be scrolling the menu up or down.  Direction of rotation is determined by providing 2 separate pulse outputs that are 90 degrees out of phase with each other.  Comparing the 2 outputs to see if they are equal or not when the CLK changes state tells you if the shaft was rotated CW or CCW as shown in the drawing below.

Module Theory of Operation

The ‘SW‘ pin (active LOW) is used to detect when the shaft is pushed to cause a pushbutton switch closure.  Some rotary encoders appear to have a built-in pull-up on the switch output and some do not, so a pull-up may be required on this pin.  Usually this can be done just by enabling the built-in pull-up resistor on the digital input pin of the uC.

The ‘CLK‘ output is the primary output pulse for determining the amount of rotation.  Each time the shaft is rotated by one detent in either direction, the ‘CLK’ output goes through one cycle of going HIGH and then LOW.  There are 20 detents in a full rotation of the shaft so there would be 20 complete clock cycles.

The ‘DT‘ output is the same as the CLK output, but it lags the CLK by a 90 degree phase shift.  This output can be used to determine if the shaft is being rotated in a CW or CCW direction by the state of DT when the CLK changes state.  Simply put, if when the CLK changes state DT = CLK, then the shaft was turned CCW.   On the other hand if CLK changes state and DT != CLK then the shaft was turned CW.  Graphic below may help to clarify the logic.

Module Connections

There is a 5-pin header on the module for making connections.

1 x 5 Header 

  • GND= Ground
  • ‘+’ = Vcc (3.3 – 5V)
  • SW = Switch Output – Active LOW
  • DT = DT (B) Output Pulse.  Connects to digital input on MCU to determine direction of shaft rotation
  • CLK = Clock (A) Output Pulse.  Connects to digital input on MCU to determine amount of shaft rotation

OUR EVALUATION RESULTS:

Rotary Encoder Module - In UseThese are a very useful module for a number of different types of control applications.  While it does not provide the absolute position of the shaft, it does provide the ability to track how far and which direction the shaft has moved with the pushbutton providing a degree of interactivity.

While it takes a little software to use, it is fairly easy to implement and it deserves a spot in most hobbyists parts drawer.

The example program below detects when the encoder is being rotated, determines which direction it is being rotated and whether or not the button is being pushed to illustrate it’s operation.

If the rotation being reported is the opposite of what you expect (CW decreases the count), try swapping the CLK and DT lines.

Make the following connection:

  • Gnd Connect to MCU ground
  • + Connect to 3.3V or 5V to match MCU power
  • SW Connect to D7
  • CLK Connect to D6
  • DT Connect to D5

The program uses pins 5,6 and 7, but any 3 digital pins can be used if they are redefined in the program.

Rotary Encoder Module Test Program.

/*
Exercise Rotary Encoder

Basic code for rotary encoder to detect rotation, direction of rotation and button push
*/
 int outputB = 5;   // Pin assignments outputB = DT 
 int outputA = 6;   // Pin assignments  outputA = CLK
 int button = 7;
 
 int counter = 0;       // Keeps track of the rotary position relative to its starting location. 
 int btnCurrentState;   // Variables used to track changes in state of the rotary encoder and button
 int btnLastState;
 int aCurrentState;
 int aLastState;  
 void setup() { 
   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);
   pinMode (button, INPUT_PULLUP);
   
   Serial.begin (9600);
  
   aLastState = digitalRead(outputA);      // Reads the initial state of the outputA and button
   btnLastState = digitalRead(button);
 } 
 void loop() { 
   btnCurrentState = digitalRead(button);
   if (btnCurrentState != btnLastState) {  // Check to see if button has been pushed or released
     Serial.print("Button: ");
     Serial.println(btnCurrentState);
     }
   aCurrentState = digitalRead(outputA); // Read current state of the outputA

   // If last and current state of outputA are different, then pulse occurred
   // React to only 1 state change to avoid double count
   if ((aCurrentState != aLastState) && aCurrentState == 1){                                                          
     if (digitalRead(outputB) != aCurrentState) // If outputB state is different than outputA state
       counter --;                              // Encoder rotating CCW so decrement
     else 
       counter ++;                              // Encoder rotating CW so increment
     
     Serial.print("Position: ");
     Serial.println(counter);
   } 
   btnLastState = btnCurrentState;  // Remember last button state
   aLastState = aCurrentState;      // Remember last outputA state
   delay(1);                        // Put in a slight delay to help debounce the reading
 }

BEFORE THEY ARE SHIPPED, THESE MODULES ARE:

  • Inspected
  • Basic operation verified
  • Packaged in a resealable ESD bag for protection and easy storage.

Notes: 

  1. None

Technical Specifications

Maximum Ratings
          Vcc Range 3.3 to 5V
Dimensions L x W (PCB) 26 x 20mm  (1 x 0.78″)
Height including shaft 30mm  (1.2″)

WE'RE READY TO BUILD A CUSTOM PRODUCT FOR YOU.

Contact us:
Support@keszoox.com
What we can help:
If you're looking for a wire or cable assembly, we can help.
What we need your help next:
Kindly contact us via email support@keszoox.com and send us the details fo your need, then we'll let you know how we can deliver the right solution.

Shipping Policy

All orders are dispatched from our warehouse. The shipments are fully tracked—from our door to yours. Please allow 3-5 business days for your order to be processed in addition to the shipping times below.

Shipping Times

Standard: 9-15 business days. Express: 4-7 business days.

Please note that shipping providers are extremely busy during this time, and some orders might experience a delay on top of usual delivery times. If your order is late, please allow 5-10 days more than indicated in standard shipping times before contacting our customer service. Thank you for your understanding.

Tracking

All orders are 100% tracked. You’ll receive an email with a tracking number and a link to track your parcel once your order leaves our warehouse. Please allow 24-48 hours for the tracking link to start showing shipping information.

Related Products

Recently Viewed Products