Planning to make a pen-like device which has a roller rolling on a surface and measured its linear distance travelled

encodermicrocontroller

I am planning to use a microcontroller to do the brain works of receiving pulses from the encoder and compute it to output linear distance and at the same time indicating the measured distance as short, medium or long (of course that means I'll write a simple program for classifications/ranges of distances).

The encoder I chose is of reflective type.

My idea is similar to the case of a digital vernier caliper where the distance measured are constantly displayed on the lcd screen.

I suppose the way to do it will be something like to count the number of pulses over the entire length of signal? How to make the microcontroller to do that? will the microcontroller reads a binary number of 10101010… as the signal? if so, all I have to do is to translate these binary number to decimal then subsequently extract the angular displacement?

please tell me whether am i right lol

Best Answer

The encoder will give you a pulse (the digital pin will read a 1) after the ball has rotated a specified amount in degrees, so you will have to mathematically calculate exactly how much linear distance the ball has travelled per pulse. It would probably be best to use an interrupt to increment a counter each time a pulse is detected, then just multiply the number of pulses seen by the linear distance travelled per pulse and you will have the total distance travelled.

You will need to setup one of the pins on the microcontroller to use an interrupt and program an interrupt service routine which is the code that will execute each time a pulse is detected, you wont really be reading in 10101010... There is a lot of info online on how to use interrupts, counters, etc.