Concept explainer · Intermediate · 3 min read
Motor Encoders and Speed Feedback
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
A motor encoder reports how far and how fast a shaft has turned. Most DC gear motors with encoders use a magnetic disc and two Hall sensors giving quadrature A and B pulses, so you get both speed and direction. Counts per output revolution equal pulses per motor turn times the gear ratio, times four if you count every edge. With these counts, a PID loop can hold a robot's wheel speed steady.
Key specs at a glance
- Types
- Magnetic (Hall) incremental, optical incremental, absolute (e.g. AS5600)
- Signals
- A and B quadrature, sometimes an index pulse
- Typical resolution
- 7 to 11 pulses per motor turn (Hall), hundreds to thousands (optical)
- Counts per output rev
- PPR × gear ratio × 4 (all edges)
- Wiring
- Motor +, motor −, encoder VCC, GND, A, B
- Reading
- Interrupt pins, or hardware counters (ESP32 PCNT, STM32 timers)
Working out counts per revolution
Example: an encoder with 11 pulses per motor revolution on a motor with a 30:1 gearbox. Counting every rising and falling edge of A and B (4x decoding) gives 11 × 30 × 4 = 1320 counts per wheel revolution. With a 65 mm wheel (about 204 mm circumference), each count is about 0.15 mm of travel.
Speed: count the pulses in a fixed time, such as 50 ms, then RPM = counts ÷ counts per rev ÷ time in minutes.
Wiring and reading
Encoder motors usually have a 6-wire cable: two thick wires to the motor driver, and VCC (3.3 or 5 V), GND, A and B for the encoder. The Hall outputs are often open-collector; add pull-ups if the board does not have them.
On an Arduino Uno, put A on an interrupt pin and read B inside the interrupt to get direction. With two motors, use pins 2 and 3 for the A channels. Above a few thousand counts per second, an Uno starts missing pulses; an ESP32's PCNT hardware or an STM32 timer in encoder mode counts with no CPU load. The same quadrature idea is explained for knobs in rotary encoders.
Closing the loop with PID
Without feedback, two 'identical' motors run at different speeds and a robot curves. With encoders, a PID loop compares measured speed to the target every 20 to 50 ms and adjusts the PWM duty. Start with only P, increase until it oscillates, back off, then add a little I to remove steady error. The same counts give odometry: distance and heading for a robot that drives a set path. For absolute angle on a joint, use a magnetic absolute encoder such as the AS5600.
Try it: Wheel speed calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Forgetting the gear ratio in counts per revolution.
- Reading encoder pins by polling in a busy loop and missing pulses.
- No pull-ups on open-collector encoder outputs.
- Running encoder wires next to motor wires without twisting.
- Tuning PID with too-large gains first.
Frequently asked questions
What is a quadrature encoder?
An encoder with two outputs a quarter-cycle apart; which changes first shows direction, and the count shows distance.
How do I calculate encoder counts per revolution?
Multiply the encoder's pulses per motor turn by the gear ratio, then by 4 if you count all edges of both channels.
Can Arduino Uno read two motor encoders?
Yes at modest speeds, using interrupt pins 2 and 3. For high-speed motors use an ESP32 or STM32 hardware counter.
What is the difference between incremental and absolute encoders?
Incremental encoders count changes from where they started; absolute encoders report the actual angle even after power-up.
Why use encoders on a robot?
To drive straight, control speed under load and measure distance travelled.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 9 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
- Motor encoder manufacturer data for Hall quadrature encoders
- ams-OSRAM AS5600 datasheet
- Espressif ESP32 PCNT documentation
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



