Login or create an accountClose
I am a returning customer
Login or create an accountClose
Your Account Has Been Created!
Thank you for registering with TechMaze!
You will be notified by e-mail once your account has been activated by the store owner.
If you have ANY questions about the operation of this online shop, please contact the store owner.
You have been logged off your account. It is now safe to leave the computer.
Your shopping cart has been saved, the items inside it will be restored whenever you log back into your account.
Rotary Encoder Module for Arduino Projects
- 360 degree rotation.
- Rotation of the rotary encoder may be counted by the positive rotation direction and a reverse direction pulse frequency output during rotation potentiometer not count this rotation count is not limited.
- With buttons on the rotary encoder can be reset to the initial state, that starts counting from 0.
- Operating voltage is 5V with one circle number of pulse 20.
- It would be a great part for many electronic DIY projects.
This tutorial will help you learn How Rotary Encoder Works and How To Use It with Arduino:
There are many different types of rotary encoders which are classified by either Output Signal or Sensing Technology. The particular rotary encoder that we will use in this tutorial is an incremental rotary encoder and it’s the simplest position sensor to measure rotation.
This rotary encoder is also known as quadrature encoder or relative rotary encoder and its output is a series of square wave pulses.
How Rotary Encoder Works
Let’s take a closer look at the encoder and see its working principle. Here’s how the square wave pulses are generated: The encoder has a disk with evenly spaced contact zones that are connected to the common pin C and two other separate contact pins A and B, as illustrated below.
When the disk will start rotating step by step, the pins A and B will start making contact with the common pin and the two square wave output signals will be generated accordingly.
Any of the two outputs can be used for determining the rotated position if we just count the pulses of the signal. However, if we want to determine the rotation direction as well, we need to consider both signals at the same time.
We can notice that the two output signals are displaced at 90 degrees out of phase from each other. If the encoder is rotating clockwise the output A will be ahead of output B.
So if we count the steps each time the signal changes, from High to Low or from Low to High, we can notice at that time the two output signals have opposite values. Vice versa, if the encoder is rotating counter clockwise, the output signals have equal values. So considering this, we can easily program our controller to read the encoder position and the rotation direction.
Rotary Encoder Arduino Example
Let’s make a practical example of it using the Arduino. The particular module that I will use for this example comes on a breakout board and it has five pins. The first pin is the output A, the second pin is the output B, the third pin is the Button pin and of course the other two pins are the VCC and the GND pin.
We can connect the output pins to any digital pin of the Arduino Board.
Here’s the Arduino code:
Description of the code:
So first we need to define the pins to which our encoder is connected and define some variables needed for the program. In the setup section we need to define the two pins as inputs, start the serial communication for printing the results on the serial monitor, as well as read the initial value of the output A and put the value into the variable aLastState.
Then in the loop section we read the output A again but now we put the value into the aState variable. So if we rotate the encoder and a pulse is generated, these two values will differ and the first “if” statement will become true. Right after that using the second “if” statement we determine the rotation direction. If the output B state differ from the output A state the counter will be increased by one, else it will be decreased. At the end, after printing the results on the serial monitor, we need to update the aLastState variable with aState variable.
That’s all we need for this example. If upload the code, start the Serial Monitor and start rotating the encoder we will start getting the values in the serial monitor. The particular module that I have makes 30 counts each full cycle.
this Video will gives you a very good info about Rotary Encoder Module