There are many different types of encoders.
An encoder is a device, circuit, transducer, software program, algorithm or person that converts information from one format or code to another, for the purpose of standardization, speed or compression.
All closed loop systems require an output and a feedback.
Here were are going to show how to use rotary encoders.
Most rotary encoders can be defined as a Speed or Quadrature Encoders.
A speed sensor simply detects a block/no block single to count. NO position change is verified.
A quadrature encoder uses 2 sensors out of phase by 90 degrees to both detect a position change with a verifiable direction.
Both will work with the same program.
For the speed just connect one signal to pin3 ( UNO ).
For the quadrature connect the A/B to pins 2 & 3.
Reversing the connections will just change the direction as count up or down.
An additional GND reset button to Pin 0 is added.
Both the speed sensor and HS Rotary encoder work fine directly connected to the Arduino.
Operating voltage: DC5-24V
green=A phase, pin 2
white=B phase , pin 3
red=Vcc positive supply,
The cheap rotary quad encoder has internal resistors, but needs additional de-bounce circuitry :
DT - Encoder Pin B #3
CLK - Encoder Pin A #2
SW – PB Switch NOT USED