Unintuitive terminal connection to ground
Figure 1. The encoder has two outputs, A and B, which have pull-up resistors giving 5 V - logic '1' - on the output when the associated encoder contact is open. When closed the contacts pull the line to 0 V giving a logic '0'. The additional 10k resistors and 0.01 &mu;F capacitors form a low-pass filter to remove any rapid switching due to contact bounce.



Figure 1. Encoder signals and resultant count.

Most encoders are used to monitor movement or position so an up-down counter is required and this is driven by a quadrature encoder.

Pseudo code
// Triggered by encoder output A
interrupt {
  if(B) {
    encoder--    // Encoder is running anti-clockwise.
  } else {
    encoder++    // Encoder is running clockwise.
  }
}


You make the encoder variable as many bits long as required for the accuracy you need.