Using Gray code for rotary encoders

Gray code is well known and widely used in angular movement systems where angular positions have to be known. Gray code encoder can be constructed pretty easily by masked wheel where tracks are read with photocells. Did you look at the picture and thought for yourself that gray code is the same binary code. Well, no… the main problem with binary systems was using binary code in tracks; there are many positions where several tracks change state simultaneously. This may result in an error. Actually, in gray code, only one track can change at the same time during rotation. So then, if an error occurs, the resulting error will be only one bit. Gray code is easy to convert to binary this task can be done by any microcontroller using a lookup table: