0% found this document useful (0 votes)
6 views4 pages

Rotary Encode Module

The Rotary Encoder Module is a device that indicates the rotation amount and direction of a knob, ideal for controlling stepper and servo motors. It operates at 5V with a 5-pin configuration, including pins for power, ground, and encoder signals. An example code is provided to demonstrate how to count encoder position and determine rotation direction without switch debounce or interrupts.

Uploaded by

juanludoto1967
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Rotary Encode Module

The Rotary Encoder Module is a device that indicates the rotation amount and direction of a knob, ideal for controlling stepper and servo motors. It operates at 5V with a 5-pin configuration, including pins for power, ground, and encoder signals. An example code is provided to demonstrate how to count encoder position and determine rotation direction without switch debounce or interrupts.

Uploaded by

juanludoto1967
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Rotary Encode Module

DESCRIPTION:
Rotary encoder is a rotary input device (as in knob) that provides an indication of how
much the knob has been rotated AND what direction it is rotating [Link]’s a great device
for stepper and servo motor control. You could also use it to control devices like digital
potentiometers.

Specification:
● Operation voltage: 5V
● 5Pinout
● Size:28.35*18.55*26.19mm
● Weight: 6.301g

1/4
PIN CONFIGURATION:
1、 “CLK”: Encoder A
2、 “DT” : Encoder B
3、 “SW”:Switch button
4、 “+” : Power(+5V DC)
5、 “Gnd”: Ground

Example:
This is a simple sketch that shows how to count the encoder position and how to
determine direction of rotation. It has no switch debounce, nor does it use interrupts.
A fully developed application might need to incorporate these in order to make it
robust.

Code:
int pinA = 3; // Connected to CLK
int pinB = 4; // Connected to DT

2/4
int encoderPosCount = 0;

int pinALast;
int aVal;
boolean bCW;
void setup()
{
pinMode (pinA,INPUT);
pinMode (pinB,INPUT);
/* Read Pin A
Whatever state it's in will reflect the last position
*/
pinALast = digitalRead(pinA);
[Link] (9600);
}
void loop() {
aVal = digitalRead(pinA);
if (aVal != pinALast)
{ // Means the knob is rotating
if (digitalRead(pinB) != aVal)
{ // Means pin A Changed first - We're
Rotating Clockwise
encoderPosCount ++;
bCW = true;
}
else { // Otherwise B changed first and we're
moving CCW bCW = false;
encoderPosCount--;
}

3/4
[Link] ("Rotated: ");
if (bCW)
{
[Link] ("clockwise");
}else
{
[Link]("counterclockwise");
}
[Link]("Encoder Position: ");
[Link](encoderPosCount);
}
pinALast = aVal;
}

Result:

4/4

You might also like