Wiring the Encoders
You might have noticed by now that there is no separate encoder part in the LEGO Mindstorms NXT box. This is because LEGO was kind enough to package an encoder along with the LEGO Motor. This does not, however, mean that the encoder does not need to be wired into the Arduino. The full motor and encoder setup requires all six of the pins on the NXT breadboard connector to be in use. Like usual, the first two, AN IN and GRND, are in use by the motor itself. The remaining four, SDA, SCL, VBUS, and the second GRND are all necessary for wiring the Encoder. Like other sensors, VBUS and GRND go to the 5V power supply and the ground respectively. The other two go to the digital pins: for the left motor, SDA connects to dgtl 9 and SDL connects to dgtl 10; and for the right motor, SDA connects to dgtl 7 and SDL connects to dgtl 8. Each of these last wires connects to one of the light sensors on the quadrature encoder, and it is by reading their combined values that the Arduino knows whether to increase the encoder value, keep it neutral, or decrease it.
NOTE: Much like we had to reverse the motors to get the correct value to make the robot move "forwards" with a positive value, we have reversed which digital pin the encoders are wired to in order to "reverse" the values on the encoder and produce positive values for forward motion.