The rotary encoder module is an incremental rotary encoder, where the primary goal is to measure the rotation. It is a position sensor in which it is used for determining the angular position of a rotating encoder. It generates an electric signal according to the rotational movement. the rotary encoder can be rotated clockwise or counter-clockwise direction. Unlike an ordinary potentiometer, the rotary encoder can be rotated continuously. The switch on the rotary encoder can be reset to the initial state which starts the counting from 0 using the "SW" pin.
Note: The incremental rotary encoder is also known as quadrature encoder or relative encoder and its output is a series of square wave pulses.
This module has five pins. The pin with label "CLK" is a the output A pin, the pin with label "OT" is the output B pin, the pin with label "SW" is a switch pin, "+" is a VCC pin and the "GND" is a ground pin.
The switch pin, the outputA pin and the outputB pin of the module can be connected to any digital pin of Arduino. The GND pin should be connected to the GND pin of Arduino and the + pin should be connected to 5V pin to the Arduino.
Code Example for Rotary Encoder Module
In the code above, the value of the counter variable can be incremented or decremented based on the rotation of the rotary encoder.
Upload and test the rotary encoder. Open the serail monitor of the Arduino IDE and check the display output.