Print Friendly, PDF & Email


A Rotary Encoder is an Electromechanical device which detects the Angular movement of shaft and convert it to provide Analog or Digital output. The encoder has a disk with evenly spaced contact zones that are connected to the common pin and two other separate contact pins.

When the disc starts to rotate step by step, both pins start making contact with the common pin and thus produce a sqaure wave in the output.

Unlike a variable resistor/potentiometer rotary encoder has infinite direction of movement. As they produce digital Gray Code, so we get an advantage of scaling their readings to whatever range we like.                                                   The dual direction movement makes them useful to increase and decrease the value within the same variable.
It has inbuilt switch which makes it compatible to use wherever toggling is required.


Rotary Encoders have wide variety of applications, such as:

Rotating servo motors, Linear Measurement, Backstop Gauging and various industries like: Material Handling, Packaging, Mobile Equipment, Textile etc.


Project for Reference:


#include <RotaryEncoder.h>

// Setup a RoraryEncoder for pins A2 and A3:
RotaryEncoder encoder(A2, A3);

void setup()
  Serial.println("SimplePollRotator example for the RotaryEncoder library.");
} // setup()

// Read the current position of the encoder and print out when changed.
void loop()
  static int pos = 0;

  int newPos = encoder.getPosition();
  if (pos != newPos) {
    pos = newPos;
  } // if