What is Rotary Encoder : Working & Its Applications

An Encoder is a device used to change one format of data to another. In other words, a device that is used to detect & change mechanical motion into an analog coded or digital coded o/p signal. Encoders are available in two configurations like linear & rotary, but the most frequently used configuration is rotary. So, a rotary encoder is designed in two basic forms like the absolute encoder and the incremental encoder.


Most rotary encoders are designed with a plastic or glass slotted disk because radial lines within every track will disrupt the beam in between a photoemitter-detector pair to generate digital pulses. This article discusses an overview of a rotary encoder and its working with applications.

What is Rotary Encoder?

A rotary encoder (shaft encoder) is an electro-mechanical device, used to change the motion of a shaft, angular position of a rotary shaft. This encoder generates an electrical signal based on the rotating movement like either analog or digital.

These are used in a variety of applications where control or monitoring is required like robotics, industrial controls, photographic lenses, input devices of computers like trackballs, optomechanical mice, controlled stress rheometers, etc.

The rotary encoder construction can be done by using different parts like encoder shaft, code disc or rotary disc including labels, source of light including electronic board, receiving IR photosensor, Optical-mechanical block including gears, electronic board with digital interface converters & signal processors.

Pin Configuration

The pin configuration of the rotary encoder includes five pins where each pin and its function are discussed below.

Rotary Encoder Pin Configuration
Rotary Encoder Pin Configuration
  • Pin1 (GND): This is a ground pin
  • Pin2 (VCC): This is the positive voltage supply pin that works with 3.3 V or 5 V.
  • Pin3 (SW): This is the active low push-button switch. Once the knob is pressed, the voltage will be LOW.
  • DT (Output B): This is similar to the clock output; however it lags the clock with a 90° phase shift. So, this output can be utilized to decide the rotation’s direction.
  • CLK (Output-A): This is the main output signal, used to determine the rotation amount. Every time, the knob in the encoder will turn through a single detent in any direction. The output of the ‘CLK’ will go through a single HIGH cycle & after that LOW

Rotary Encoder Working

In the rotary encoder, we can observe that how the square wave signals are generated. Generally, this encoder includes a disk, spaced evenly with contact zones. The connection of these contact zones can be done to the common pin-C & other two separate contact pins like A & B shown below.

Rotary Encoder Working
Rotary Encoder Working

The disk in this encoder will start revolving slowly and both the pins like A & B will be in contact through the common pin. Thus, the generation of two square wave output signals can be done accordingly.
Here, the rotating position can be determined by using any of the two outputs. But, if we want to decide the direction of rotation, then we have to consider both signals simultaneously.

We can observe that the two o/p signals are moved at 90 degrees out of phase from each other. If this encoder is turning in a clockwise direction, then output A will be after output B.

Every time, if we count the steps, then the signal will be changed from Low to High or High to Low. At that time, we can observe the two output signals like A & B will have reverse values.

If this encoder is revolving counter-clockwise, then both the output signals will have identical values. By considering this, we can simply program the controller to study the position of the encoder & the direction of rotation.

Rotary Encoder Types

These encoders are classified into two types which include the following.

  • Incremental Type
  • Absolute Type

Incremental Rotary Encoder

The incremental rotary encoder is used to provide a sequence of low & high waves. These waves will specify the movement of position. These types of encoders will provide a sequence of periodic signals within the pulses form because of the shaft revolution motion.

An object’s speed can be measured through pulse counting for some time. These pulses can be simply counted from a reference point to determine the position otherwise distance covered.

The incremental rotary encoder generates two digital o/p signals where the phase relationships among these two sensors will decide whether the encoder’s shaft is revolving clockwise direction otherwise anti-clockwise. So by using this encoder, the position can be simply determined.

Once the light-emitting diode produces the light, then it will transmit through a crystal clear disk. Once this light signal receives by a photosensor then a sinusoidal signal can be generated, which is changed into a pulse train or square wave. The pulse wave can be transmitted toward the rotary counter which will transmit the signal to generate the preferred function.

Absolute Rotary Encoder

An absolute rotary encoder is used to maintain the positions information once power is detached from the rotary encoder. This encoder’s position is instantly available once power is provided.

This encoder includes different code rings through different binary weightings which provide a data word for signifying the rotary encoder’s absolute position in a single revolution. So this type of encoder is also called a parallel absolute encoder.

An absolute rotary encoder with multi-turn mainly comprises extra gears & code wheels. A wheel with high resolution can measure the fractional rotation lower-resolution and geared code wheels with lower resolution can record the shaft’s complete revolutions.

Rotary Encoder Connection Diagram

The rotary encoder wiring diagram with Arduino is shown below. A rotary encoder is with a shaft can change the angular position otherwise motion of a shaft. The output of this encoder provides information regarding the shaft’s motion which is typically processed within controllers or processors into information like distance, position, and speed. The rotation of the shaft is 360 degrees.

The required materials for this wiring diagram mainly include an Arduino Uno, rotary encoder, USB Cable3, Jumper wires from female to male, etc.

Rotary Encoder Interfacing with Arduino
Rotary Encoder Interfacing with Arduino

The Interfacing of the rotary encoder with an Arduino Uno can be done as mentioned below.

  • Connect the VCC pin of the encoder to the 5V pin of the Arduino
  • Connect the GND pin of the encoder to the GND pin of the Arduino
  • Connect the CLK pin of the encoder to the D3 pin of the Arduino
  • Connect the CLK pin of the encoder to the D4 pin of the Arduino

Once the connections are made then connect the Arduino Uno board to your PC. Upload the coder into your Arduino Uno board. Click on tools-> select serial monitor and you will find BEGIN on the serial monitor. So now you can begin to turn the shaft of the encoder and observe the printed output on the serial monitor.

Once you turn the shaft in a clockwise direction, then the serial monitor will print the encoder count.

Code to read a rotary encoder interfaced with an Arduino Uno 

Below is the Code

/**************
* VCC to 5V *
* GND to GND *
* CLK to D3 *
* CLK to D4 *
**************/
int pinA = 3;
int pinB = 4;
int encoderPosCount = 0;
int pinALast;
int aVal;
boolean bCW;
void setup()
{
//SET pinA and pinB and input
pinMode (pinA,INPUT);
pinMode (pinB,INPUT);
pinALast = digitalRead(pinA);//Read Pin A
Serial.begin (9600);
Serial.println(“BEGIN”);
Serial.println();
}
void loop()
{
aVal = digitalRead(pinA);
if (aVal != pinALast)
{
if (digitalRead(pinB) != aVal) //We’re Rotating Clockwise
{
encoderPosCount ++;
bCW = true;
}
else
{
bCW = false;
encoderPosCount–;
}
if (bCW)
{
Serial.println (“Rotate Clockwise”);
}
else
{
Serial.println(“Rotate Counterclockwise”);
}
Serial.print(“Encoder Count: “);
Serial.println(encoderPosCount);
Serial.println();
}
pinALast = aVal;

The code to Interface a Rotary Encoder with the microcontroller is the same as above except that microcontroller specific Api’s should be used.

Advantages

The advantages of a rotary encoder include the following.

  • These are reliable
  • Accurate
  • Resolution is high
  • Size is compact
  • Less cost feedback
  • Integrated electronics
  • Can be included in existing applications

The disadvantages of a rotary encoder include the following.

  • It is vulnerable to oil, dirt & contaminants of dust.
  • The interface of the direct light source.

Applications

The applications of rotary encoder include the following.

  • These are used where speed, direction, acceleration, and monitoring rotation rate are required.
  • These are used in different industries like material handling, packaging & conveyor.
  • In the automation field, these encoders are utilized as sensors for speed, angle, acceleration & position.
  • These are used to measure linear motion by using gear racks, spindles, cable pulls, or measuring wheels.
  • These encoders are used to change a mechanical input to electrical signals by using tachometers, counters, PLC systems & PCs in industries.
  • These are used in packaging, assembly machines, indication systems, printers, CNC machines, testing machines, robotics, textiles, motor feedback, medical equipment, drilling, and labeling machines.

How accurate is a rotary encoder?

The accuracy of rotary encoders can be expressed usually in degrees or arcseconds.

What is the most accurate encoder?

An absolute optical shaft encoder is the most accurate because its typical accuracy is 0.18 degrees (10.8 arcminutes) & its maximum accuracy is 0.25 degrees.

Can an encoder be a transducer?

Yes, a transducer has the capacity to emit & accept the data.

What is the use of a rotary encoder?

Rotary encoders are mainly used to control the conveyer belt speed & its movement direction.

How does an angular encoder work?

An angular encoder is a type of position sensor used to measure the rotating shaft’s angular position.

Thus, this is all about an overview of a rotary encoder and its working. These encoders will fail in some harsh conditions. In such situations, there are mainly three common causes of encoder failure like contamination of liquid, mechanical bearing overload & output failure of the signal. So, the rotary encoder will stop functioning or the system will function randomly. Here is a question for you, what is the function of a decoder?