Electronics

Rotary Encoder Module KY-040

AED 9.45

1

Description

A rotary encoder is a sort of position sensor that translates the angular position (rotation) of a handle into a voltage that may be used to identify which way the knob is moved. Rotary encoders can rotate a full 360 degrees without stopping, it comes with an operating voltage of 5V and a steps width of 20 positions/revolution.

Package Includes:

  • 1 x Rotary Encoder Module for Arduino

Features:

  • steps width of 20 positions/revolution
  • It has a switch included in the Encoder
  • Rotates a full 360 degrees
  • Operating voltage range of 5V

Description:

A rotary encoder is a sort of position sensor that translates the angular position (rotation) of a handle into a voltage that may be used to identify which way the knob is moved. Rotary encoders can rotate a full 360 degrees without stopping, They are utilized when you need to know the change in position rather than the exact location. it comes with an operating voltage of 5V and a steps width of 20 positions/revolution. Rotary encoders are found in a wide range of everyday gadgets. Rotary encoders are more common than we realize, appearing in everything from printers and photography lenses to CNC machines and robots. The volume control knob on a vehicle radio is the most common application of a rotary encoder in everyday life. 

Principle of Work:

A slotted disc inside the encoder is linked to the common ground pin C. It also has two contact pins (A and B).


When you move the knob, A and B make contact with the common ground pin C in a specific order depending on which way you turn the knob.
Signals are formed when they come into touch with common ground. These signals are 90° out of phase because one pin makes contact with the common ground before the other. This is known as quadrature encoding.

When the knob is turned clockwise, the A pin connects to the ground before the B pin. When the knob is turned counterclockwise, the B pin connects to the ground before the A pin.
We can identify the way the knob is being spun by tracking when each pin connects to or disconnects from the ground. You may accomplish this by simply watching the condition of B when A changes.
If B does not equal A, the knob is rotated clockwise.


Clockwise rotation of the rotary encoder output pulses


If B Equals A, crank the knob counterclockwise.

 

Pinout of the Module:

 

Pin Type

Description

CLK

Encoder Pin A

DT

Encoder Pin B

SW

push-button switch

VCC(+)

Voltage input(+5V)

GND

Ground(Encoder Pin C)

Applications:

  • Robotic arm controller
  • Servo and Stepper motor control
  • Precise motor movement

Circuit:

The module's Ground and + pins must be connected to the Arduino Board's Ground, and Vcc the clock and DT Out pins to 6,7 on the Arduino Board.

 

Library: 

no library is needed.

Code:

The first pin is output A, the second pin is output B, the third pin is the Button pin, and the other two pins are VCC and GND.

#define outputA 6
#define outputB 7

int counter = 0;
int aState;
int aLastState;

void setup() {
  pinMode (outputA, INPUT);
  pinMode (outputB, INPUT);

  Serial.begin (9600);
  // Reads the initial state of the outputA
  aLastState = digitalRead(outputA);
}

void loop() {
  aState = digitalRead(outputA); // Reads the "current" state of the outputA
  // If the previous and the current state of the outputA are different, that means a Pulse has occured
  if (aState != aLastState) {
    // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
    if (digitalRead(outputB) != aState) {
      counter ++;
    } else {
      counter --;
    }
    Serial.print("Position: ");
    Serial.println(counter);
  }
  aLastState = aState; // Updates the previous state of the outputA with the current state
}

We'll start obtaining data on the serial monitor when you upload the code, start the Serial Monitor, and start spinning the encoder. Each whole cycle, the module I have generates 30 counts.

 

 

Technical Details: 

  • Operating Voltage: 5V
  • Mechanical angle: 360 Degrees
  • Output: 2-bit gray code
  • Positions per revolution: 20

Resources:

Comparisons:
Rotary encoders are the digital version of potentiometers, although they are more adaptable. Potentiometers can only revolve 3/4 of the circle whereas they can rotate 360° without halting. Potentiometers are employed in circumstances when the exact position of the knob is required. Rotary encoders, on the other hand, are employed when you need to know the change in position rather than the exact location.