4-Bit Gray Code Rotary Encoder

Why Gray code prevents reading errors at position boundaries

Gray Code vs Binary
Pos Binary Gray Bits Changed
Current Position Reading
0000
Position: 0 of 16
Binary: Multi-Bit Transition Problem
Transition from position 7 → 8:
0 1 1 1
1 0 0 0
Possible misreads at boundary:
0000(0), 0001(1), 0110(6), 1111(15), etc.
When 4 bits change simultaneously, the sensor may read any combination if positioned at the exact boundary.
Gray Code: Single-Bit Guarantee
Transition from position 7 → 8:
0 1 0 0
1 1 0 0
At boundary, reads either:
0100 (pos 7) or 1100 (pos 8) — both valid!
Only one bit changes, so the worst case is reading the adjacent position — never an invalid or distant value.
Key Insight
Gray code ensures that at any transition boundary, the read head sees either the valid "before" or "after" value — never a spurious intermediate state.