

An encoder is a device that converts information from one format or code to another. It is commonly used in control systems to provide feedback on position, speed, or direction. Encoders are essential in applications requiring precise motion control, such as robotics, CNC machines, and industrial automation. They are available in various types, including rotary and linear encoders, and can output digital or analog signals depending on the design.
The Arduino Энкодер is a versatile rotary encoder designed for use in microcontroller-based projects. It is ideal for applications such as user input devices (e.g., volume knobs or menu navigation), motor control systems, and position tracking.








Below are the key technical details for the Arduino Энкодер:
The Arduino Энкодер has 5 pins, as described in the table below:
| Pin Name | Type | Description |
|---|---|---|
| GND | Power | Ground connection for the encoder. |
| VCC | Power | Power supply input (3.3V to 5V DC). |
| A | Signal Output | Quadrature signal A, used to determine rotation direction and position. |
| B | Signal Output | Quadrature signal B, used in conjunction with signal A for position tracking. |
| SW | Signal Output | Push-button switch output, active LOW when the encoder knob is pressed. |
Connect the Power Pins:
VCC pin to a 3.3V or 5V power source. GND pin to the ground of your circuit.Connect the Signal Pins:
A and B pins to two digital input pins on your microcontroller. These pins will read the quadrature signals to determine the encoder's position and direction. SW pin to another digital input pin to detect button presses.Pull-Up Resistors:
A, B, and SW pins to ensure stable signal readings.Write Code:
Below is an example code snippet to interface the Энкодер with an Arduino UNO:
// Define encoder pins
const int pinA = 2; // Connect to encoder pin A
const int pinB = 3; // Connect to encoder pin B
const int pinSW = 4; // Connect to encoder pin SW (button)
// Variables to track encoder state
volatile int encoderPosition = 0; // Tracks the encoder's position
int lastEncoded = 0; // Stores the last encoder state
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Configure encoder pins as inputs
pinMode(pinA, INPUT);
pinMode(pinB, INPUT);
pinMode(pinSW, INPUT_PULLUP); // Enable internal pull-up for button
// Attach interrupts to encoder pins
attachInterrupt(digitalPinToInterrupt(pinA), updateEncoder, CHANGE);
attachInterrupt(digitalPinToInterrupt(pinB), updateEncoder, CHANGE);
}
void loop() {
// Print the encoder position to the serial monitor
Serial.print("Encoder Position: ");
Serial.println(encoderPosition);
// Check if the button is pressed
if (digitalRead(pinSW) == LOW) {
Serial.println("Button Pressed!");
delay(200); // Debounce delay
}
delay(100); // Small delay for readability
}
// Interrupt service routine to update encoder position
void updateEncoder() {
int MSB = digitalRead(pinA); // Most significant bit
int LSB = digitalRead(pinB); // Least significant bit
int encoded = (MSB << 1) | LSB; // Combine A and B signals
int sum = (lastEncoded << 2) | encoded; // Track state changes
// Update position based on state transitions
if (sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) {
encoderPosition++;
} else if (sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) {
encoderPosition--;
}
lastEncoded = encoded; // Update last state
}
Encoder Signals Are Unstable:
A, B, and SW pins. Use capacitors (e.g., 0.1µF) for noise filtering if necessary.Incorrect Position Tracking:
Button Not Detected:
SW pin or add an external pull-up resistor.No Output from Encoder:
Q: Can I use the Энкодер with a 3.3V microcontroller?
A: Yes, the Энкодер is compatible with both 3.3V and 5V systems.
Q: What is the maximum rotational speed the Энкодер can handle?
A: The Энкодер can handle speeds up to 1000 RPM.
Q: How do I increase the resolution of the Энкодер?
A: The resolution is fixed at 20 PPR, but you can use software to interpolate signals for higher precision.
Q: Can I use the Энкодер for motor speed control?
A: Yes, the Энкодер is suitable for motor speed and position control applications.
By following this documentation, you can effectively integrate the Arduino Энкодер into your projects for precise motion control and user input functionality.