Wrong counts usually come from noise on the signal or from reading too slowly. Use both channels and interrupt-capable pins.
What the message means
A quadrature encoder gives two pulse trains, A and B, a quarter cycle apart. The order of the changes tells the direction. Missed or false edges add up as drift.
Fix it in this order
- Connect both channels A and B, plus power and ground at the right voltage.
- On an Uno use pins 2 and 3 for interrupts. On an ESP32 most pins can take interrupts.
- Keep ISR code short: update a counter and return.
- Mark the shared counter volatile, and copy it with interrupts off if it is more than 8 bits.
- Add pull-ups if the encoder has open-collector outputs, and a small capacitor on noisy lines.
- Run the encoder wires away from motor wires, and twist or shield them.
- Check the pulse rate against what the board can handle at full motor speed.
If you see this, do this
| You see | Do this |
|---|---|
| Counts go up at a standstill | Noise on the signal. |
| Counts too low at speed | Missed pulses. Use interrupts or a hardware counter. |
Related
encoder counts calculator, wheel speed calculator.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.