Learning how using a pushbutton rotary
encoder can help you design and build better,
more user-friendly microcontroller projects.
I was bitten by the microcontroller bug a number of years ago and enjoyed building
a variety of gadgets that use them. One of the tedious aspects of gadget building
is the buttons and switches that make up the input controls. When I discovered
the pushbutton rotary encoder, I realized that one control could replace many,
simplifying the design, construction, and programming.
This article will introduce you to the Greyhill 62P22-L4
pushbutton rotary encoder1. I will describe what it is,
how it works, and how to integrate it into your project.
A demonstration will be presented using a PIC16F84A2,
along with the project code written in C.
The Greyhill 62P22-L4
I chose this device more or less at random, because
it was in stock from my favorite supplier. The shaft
rotates with soft detents, and can be pressed in as a
pushbutton. Each detent is
■ FIGURE 1. The encoder.
at 22° of rotation. There are no stops and no reason why
it cannot be rotated endlessly either clockwise or counter-clockwise. This model comes in two different rotational
torque and two different pushbutton forces; the L4 model
is the lower torque and lower force model. (Other types
with a variety of features such as integrated joystick are
This rotary encoder requires a + 5 VDC supply at
30 mA. It uses an internal LED and optical detector to
produce its output. The pushbutton is a mechanical
contact type and requires a few milliseconds to debounce
(four at make and 10 at break3).
The rotary encoder outputs a two bit
binary code on its Output A and Output
B pins. This gives four unique values,
after which the code repeats itself. Once
you know the previous and current output
values and the code sequence, you
can determine which way the shaft has
If you assume that Output A is the low
order bit and Output B is the high order
bit, when rotated clockwise the encoder
outputs 0, 1, 3, 2. When rotated counter-clockwise, the output is 0, 2, 3, 1. (There is,
■ FIGURE 2. Encoder logic states.