You need a user account to post in our forum or submit Did-it-Myself projects.

Don't have an account yet? Sign up today.

Login Error

Invaild User/Password combination

Close

How to Use a Rotary Encoder Switch


by DoItYourself Staff

what you'll need

  • Rotary encoder switch
  • Micro controller port

A rotary encoder switch is used to convert the angular position of a shaft to a code that is either analog or digital. Because of this, the rotary encoder can be used for many things including photography, robotics and even computer devices such as the mouse. Basically if you need something changed from analog to digital, a switch is what you will need. If you are confused as to how to use a rotary encoder switch, then following these steps can help you with this task.

Step 1 - Pick a Micro Controller Port

Select a port for the micro controller. This port is what will read the inputs from both A and B from the encoder output. You will then need to connect the encoder to the micro controller.

Step 2 - Assign a Register

Assign a register to be your digital potentiometer. Many times you will just need to use a single 8 bit register. If you want to go larger though you can extend it before you begin. You do want to know that when you have an 8 bit register you will already need 8 complete rotations to fill it so if you are considering going further then you will want to allow for extra rotations because every bit that you end up filling is going to double the final number. Basically, you want to just use as few bits as you need to use to get the job done without going over and causing yourself more work.

Step 3 - Routine Interruptions

Now you are going to want to begin with a predetermined algorithm. You will want to begin rotating the knob clockwise so that the pulses that are coming from A move to be pulses from B. If you go counter clockwise then the pulses from B start out and end with A pulses. Basically you won't have to use separate pins for each direction, instead when you turn the knob it will rotate the direction of the pulse for you in the direction hat you set it to go. When you begin the direction of the offset you can see what the direction of the rotation is going to look like and therefore you know which way the pulse will be going. In this case, from analog to digital to be read. You will want to keep track of the changes that you are making and the number of rotations as you go along as you are using an 8 bit register so you will only need 8 full rotations to be complete.

Basically, in the end you are controlling your system to make it easier for you to use. While there are many variations of the encoder switch, most of them mirror this model and can be followed similar to these steps.

 forum activity