IDUINO DEBO ENCODER Datasheet

IDUINO for Maker’s life
www.openplatform.cc
Rotary Encode Module (SE055)
1 Introduction
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 in.It’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:32*20*30mm Weight: 8g
2 Pinout
Pin
Description
CLK
Encoder A
DT
Encoder B
SW
Switch button
+
Power(5V DC)
Gnd
Ground
3.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.
IDUINO for Maker’s life
www.openplatform.cc
******Code Begin******
int pinA = 3; // Connected to CLK int pinB = 4; // Connected to DT 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); Serial.begin (9600); }
void loop() { aVal = digitalRead(pinA); if (aVal != pinALast){ // Means the knob is rotating // if the knob is rotating, we need to determine direction // We do that by reading pin B. if (digitalRead(pinB) != aVal) { // Means pin A Changed first ­We're Rotating Clockwise encoderPosCount ++;
IDUINO for Maker’s life
www.openplatform.cc
bCW = true; } else {// Otherwise B changed first and we're moving CCW bCW = false; encoderPosCount--; } Serial.print ("Rotated: "); if (bCW){ Serial.println ("clockwise"); }else{ Serial.println("counterclockwise"); } Serial.print("Encoder Position: "); Serial.println(encoderPosCount);
} pinALast = aVal; }
******Code End******
Loading...