The Rotary Encoder Module For Arduino measures turning and features a built in SPST pushbutton. The KY-040 rotary encoder is a relative rotary encoder and tells the change from the previous position. For example: Turned 23 degrees from previous position.
A rotary encoder produces two signals as it is turned. Both signals alternate between HIGH and LOW as the shaft is turned. When you turn the knob, the encoder sends clock pulses on the clock pin. On the rising edge the clock goes from LOW to HIGH, one data pulse comes on the data pin; another comes on the falling edge with a HIGH to LOW transition.
If the data pulse is HIGH, the encoder knob is turning right a clockwise, negative direction. Alternately, If the data pulse is LOW, the encoder knob is turning left.