Sold Out

Rotary Ecoder

MOD-089
Out of stock
R 17.00
A rotary encoder is an electromechanical device that converts the angular position or motion of a shaft or axle to an analog or digital code. Rotary encoders are usually placed at the side which is perpendicular to the shaft. Rotary encoders act as sensors for detecting angle, speed, length, position...
Terms & conditions

A rotary encoder is an electromechanical device that converts the angular position or motion of a shaft or axle to an analog or digital code. Rotary encoders are usually placed at the side which is perpendicular to the shaft. Rotary encoders act as sensors for detecting angle, speed, length, position and acceleration in the automation field.

The module can count by rotation the pulses output both clockwise and counterclockwise. Different from the potentiometer, the counting is unrestricted. It can be restored to the original state by the button on the module, i.e. counting from 0.

Application

It is widely applied in fields such as steel, harbor machinery, hoisting machinery, pressure machinery, glass machinery, packaging machinery, etc

Example Sketch & Diagram

19_419_1

 

#define clkPin 2
#define dtPin 3
#define swPin 4
int encoderVal = 0;

void setup(){
pinMode(clkPin, INPUT);
pinMode(dtPin, INPUT);
pinMode(swPin, INPUT);
digitalWrite(swPin, HIGH);
Serial.begin(9600);
}

void loop(){
int change = getEncoderTurn();
encoderVal = encoderVal + change;
if(digitalRead(swPin) == LOW)
{
encoderVal = 0;
}
Serial.println(encoderVal);
}
int getEncoderTurn(void)
{
static int oldA = HIGH;
static int oldB = HIGH;
int result = 0;
int newA = digitalRead(clkPin);
int newB = digitalRead(dtPin);
if (newA != oldA || newB != oldB)
{
if (oldA == HIGH && newA == LOW)
{
result = (oldB * 2 - 1);
}
}
oldA = newA;
oldB = newB;
return result;
}
Write a review
| Ask a question
Write a review
| Ask a question
The cookie settings on this website are set to 'allow all cookies' to give you the very best experience. Please click Accept Cookies to continue to use the site.
Rotary Ecoder
You have successfully subscribed!
This email has been registered