The EC11 Rotary Encoder is a compact and versatile electromechanical device that converts the angular position or rotational movement of a shaft into an electrical signal. It is widely used in applications requiring precise user input, such as volume controls, menu navigation, and position sensing in industrial and consumer electronics. Unlike potentiometers, rotary encoders can provide infinite rotation and are capable of detecting both direction and speed of rotation.
The EC11 Rotary Encoder typically has 5 pins: three for the encoder and two for the push-button switch. Below is the pinout:
Pin Name | Description | Connection |
---|---|---|
GND | Ground | Connect to circuit ground |
VCC | Power supply (5V DC) | Connect to 5V source |
CLK (A) | Channel A output signal | Connect to microcontroller input pin |
DT (B) | Channel B output signal | Connect to microcontroller input pin |
SW | Push-button switch output | Connect to microcontroller input pin (with pull-up resistor) |
Wiring the Encoder:
Reading the Encoder:
Debouncing:
Below is an example of how to use the EC11 Rotary Encoder with an Arduino UNO:
// EC11 Rotary Encoder Example Code for Arduino UNO
// Connect CLK to pin 2, DT to pin 3, and SW to pin 4
#define CLK 2 // Channel A (CLK) connected to digital pin 2
#define DT 3 // Channel B (DT) connected to digital pin 3
#define SW 4 // Push-button (SW) connected to digital pin 4
int lastStateCLK; // To store the previous state of CLK
int currentStateCLK; // To store the current state of CLK
int counter = 0; // Counter to track rotation
bool buttonPressed = false; // To track button press state
void setup() {
pinMode(CLK, INPUT);
pinMode(DT, INPUT);
pinMode(SW, INPUT_PULLUP); // Use internal pull-up resistor for SW
Serial.begin(9600);
// Initialize lastStateCLK with the initial state of CLK
lastStateCLK = digitalRead(CLK);
}
void loop() {
// Read the current state of CLK
currentStateCLK = digitalRead(CLK);
// Check if the state of CLK has changed
if (currentStateCLK != lastStateCLK) {
// Read the state of DT to determine rotation direction
if (digitalRead(DT) != currentStateCLK) {
counter++; // Clockwise rotation
} else {
counter--; // Counterclockwise rotation
}
// Print the counter value to the Serial Monitor
Serial.print("Counter: ");
Serial.println(counter);
}
// Update lastStateCLK to the current state
lastStateCLK = currentStateCLK;
// Check if the push-button is pressed
if (digitalRead(SW) == LOW) {
if (!buttonPressed) {
Serial.println("Button Pressed!");
buttonPressed = true;
}
} else {
buttonPressed = false;
}
}
No Response from the Encoder:
Erratic or Noisy Signals:
Push-Button Not Working:
Incorrect Direction Detection:
Q: Can the EC11 Rotary Encoder detect absolute position?
A: No, the EC11 is an incremental encoder and only detects relative position changes. It does not provide absolute position information.
Q: How do I increase the resolution of the encoder?
A: The resolution is fixed at 20 pulses per revolution (PPR). However, you can use software to detect both rising and falling edges of the signals to effectively double the resolution.
Q: Can I use the EC11 with a 3.3V microcontroller?
A: Yes, but ensure the encoder operates reliably at 3.3V. If not, consider using a level shifter or a 5V power source.
Q: Is the EC11 suitable for high-speed applications?
A: The EC11 is designed for low-speed, manual input applications. For high-speed applications, consider using an optical or magnetic encoder.