Rotary encoders work by converting the angular position or motion of a shaft into an electrical signal, typically a digital pulse train. They use a patterned disk or a magnetic ring that a sensor reads as the shaft turns, producing outputs that indicate direction, speed, and often absolute position. This makes them essential in motors, robotics, and user interfaces where precise feedback is needed.
What Is a Rotary Encoder?
A rotary encoder is an electromechanical device that measures rotation. Unlike a potentiometer, which has a limited range and wears out from wiper contact, an encoder can turn continuously and often provides digital outputs. Encoders come in two main types: incremental and absolute. Incremental encoders report relative movement—pulses as the shaft turns—while absolute encoders report a unique code for each shaft position, so they know exactly where they are even after power loss.
Common applications include motor speed control, robotics joint feedback, CNC machines, and the volume knob on car stereos or test equipment. The choice between types depends on whether you need to know position at power-up or just track movement.
How Incremental Encoders Work
Incremental encoders use a disk with alternating opaque and transparent slots (optical) or magnetic poles (magnetic) arranged in tracks. A light source and photodetector (or a magnetic sensor) read the pattern as the disk rotates, generating a square wave. A single track produces one pulse per revolution segment; a second track, offset by 90 degrees, provides quadrature signals A and B. The phase relationship between A and B tells the controller the direction of rotation: if A leads B, the shaft turns clockwise; if B leads A, counterclockwise.
The number of slots per revolution determines the resolution, often specified in pulses per revolution (PPR) or counts per revolution (CPR). A common incremental encoder might have 100 to 1000 PPR. Many also include an index or Z channel that outputs one pulse per revolution, providing a home reference position.
Quadrature decoding can multiply resolution: counting both edges of both channels yields four counts per pulse period, so a 100 PPR encoder can produce 400 counts per revolution.
How Absolute Encoders Work
Absolute encoders assign a unique binary code to each shaft position. The disk has multiple concentric tracks, each with a pattern of slots. For example, a 10-bit absolute encoder has 10 tracks, giving 2^10 = 1024 distinct positions per revolution. The sensor reads all tracks simultaneously and outputs a parallel or serial code.
Early absolute encoders used Gray code, where only one bit changes between adjacent positions, preventing false readings during transition. Modern absolute encoders often use serial protocols such as SSI, BiSS, or fieldbus interfaces. Because they retain position without power, absolute encoders are preferred for robotics and applications where homing on startup is impractical.
Optical, Magnetic, and Capacitive Sensing
Optical encoders use an LED and photodetector array; they offer high resolution and accuracy but are sensitive to dust, moisture, and shock. Magnetic encoders detect a magnetized ring with Hall-effect or magnetoresistive sensors; they are rugged and tolerant of contamination, though resolution may be lower. Capacitive encoders sense changes in capacitance between a rotor and stator pattern; they are compact and immune to magnetic interference but require careful shielding.
For harsh environments, magnetic or capacitive types are often chosen. For clean, high-precision settings like laboratory instruments, optical encoders dominate.
Key Specifications and How to Choose
Selecting an encoder involves matching several parameters to the application:
- Resolution: Pulses per revolution (incremental) or bits (absolute). Higher resolution gives finer control but may require faster electronics.
- Output type: Push-pull, open collector, line driver (RS-422), or serial. Line driver is preferred for long cables and noise immunity.
- Supply voltage: Common values are 5 V, 12–24 V. Ensure compatibility with the controller.
- Mechanical size: Shaft diameter, mounting flange, and housing diameter must fit the available space.
- Environmental rating: IP rating for dust and water; operating temperature range.
- Max speed: Exceeding the rated RPM can damage bearings or cause signal loss.
Also consider whether you need an index pulse, complementary outputs, or a specific connector. For human-interface knobs, a low-resolution incremental encoder with detents (mechanical clicks) is typical.
Common Problems and Misconceptions
A frequent misconception is that encoders measure absolute position like a potentiometer. Incremental encoders only report changes; without a reference, the controller cannot know the starting position. Another issue is signal noise: long unshielded cables can pick up interference, causing missed or extra counts. Using twisted-pair, shielded cable and line-driver outputs mitigates this.
Mechanical wear affects optical encoders with bearings or seals; magnetic encoders with no contact between sensor and magnet generally last longer. Contamination of the disk can block slots, causing dropouts—clean with care or specify sealed units. Also, ensure the encoder shaft is aligned with the driven shaft to avoid bearing load.
Frequently Asked Questions
What is the difference between an encoder and a potentiometer?
A potentiometer provides an analog voltage proportional to absolute angle over a limited range and wears from wiper contact. An encoder provides digital pulses or codes over unlimited rotation and generally has longer life, but incremental types need a reference to know absolute position.
Can a rotary encoder be used as a volume knob?
Yes. Many audio devices use incremental encoders with detents; the microcontroller reads quadrature pulses to increase or decrease volume. The lack of end stops allows continuous rotation.
How do I determine the resolution I need?
Resolution depends on the smallest angle you must detect. For a motor control loop, choose at least 4–10 counts per desired control increment. For manual knobs, 20–30 detents per revolution is common. Higher resolution increases cost and processing load.
What causes missed counts in an incremental encoder?
Common causes include electrical noise on signal lines, excessive cable length without proper termination, supply voltage droop, and mechanical misalignment causing disk wobble. Shielding, twisted pairs, and line drivers reduce noise; check alignment and cable routing.
Do absolute encoders need homing?
No. Absolute encoders report a unique position code at power-up, so homing is unnecessary. This is a key advantage in robotics and multi-axis machines.
Are rotary encoders affected by magnetic fields?
Magnetic encoders can be affected by strong external magnetic fields, which may cause errors. Optical and capacitive encoders are immune to magnetic interference but may be sensitive to other factors like dust or humidity.