Rotary encoders are useful as rotation sensors or selectors and look similar to potentiometers. However, they are not like potentiometers at all, so it's important to realize the difference! Rotary encoders are typically found on the volume knobs of stereos.
These rotary encoders rotate all the way around continuously and are divided up into 'segments'. These encoders have 30 segments. Each segment has a clicky feeling to it, and each movement clockwise or counter-clockwise causes the two switches to open and close. There is no way to know what the current 'position' is - instead you would use a microcontroller to count how many 'clicks' left or right it has been turned. If you need to detect rotational 'position' a potentiometer would be a better choice.
Pinout
On the encoder itself, there are three pins. They are normally referred to as A, B and C. Inside the encoder, there are two switches. Once switch connects pin A to pin C and the other switch connects pin B to C. In each encoder position, both switches are either opened or closed. Each click causes these switches to change states as follows:
The illustration below is representative of how the switch is constructed:
As you can see, the angular position of the A terminal and the B terminal is such that:
If we were to represent the opening and closing of the switches as wave forms, it would look something like this:
Essentially, determining which switch changed states first is how the direction of rotation is determined. If A changed states first, the switch is rotating in a clockwise direction. If B changed states first, the switch is rotating in a counter-clockwise direction.
The code for this is pretty complex, so I will give you a skeleton of the code to implement an encoder project. It requires using interrupts, which we have not gone through yet. To learn more about interrupt, you can go here: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/.
https://create.arduino.cc/editor/mjdargen_ncsu/a33deffe-a1c5-4eb6-a201-d6459a0f6d4c/preview