Out of curiosity (which btw is one of my main driving factors in life), I bought a couple of rotary encoders. A rotary encoder is a knob that turns in small steps. It has no minimum or maximum turning angle – you can turn it as many turns you want. They are often used in radios or stereos or in any device where you use a knob to select items in a menu, for instance.
The ones I bought, have four connections: ground, +5 volt, two output connections. By reading the output signals, it’s possible to distinguish between clock-wise and counter-clockwise rotations. To understand how these output signals really work, I had to use my oscilloscope.
So I hooked up power to the rotary encoder, and connected the output pins to my oscilloscope. On the oscillators output screen I’ve moved the signals vertically a bit to make it easier to distinguish between the signals. Really they are both at exactly zero volts or exactly five volts. First, a clockwise turn:
So, when turning clockwise, both outputs go from low to high at exactly the same time. After a short pause (about 20ms), output signal number two goes from high to low, and after another short pause (another 20ms or so), output signal number one goes from high to low. Now we know a clockwise turn has been performed.
Next up, counter-clockwise! (what a great surprise, right?)
When turning counter-clockwise, output signal number one goes from low to high, followed by a pause before signal number two goes from low to high too. After a pause both signals drop to low at the exact same time, and we know a counter-clockwise turn as been performed.
Exciting, isn’t it!
It seems other rotary encoders might behave differently. Some may have a push-button functionality as well. But they are kind of cool, don’t you think?!?