Reading the output from a motor

Quick question: I am trying to make a program where a user uses a remote controller to run a robot down a hallway, and then since the motor I am using contains a rotary encoder, I want the rotary encoder to show how far I get down the hall.
This is my program: int chA;
int chB;

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

chA = pulseIn(45, HIGH);
chB = pulseIn(43, HIGH);

Serial.print("chA: "); Serial.print(chA); Serial.print("chB: "); Serial.println(chB);

When I run this and I spin the motor, it only shows a repeating list of values. Is there a way I can program it so that when I stop spinning the motor, it gives a grand total for how far the motor has run for? Thanks!

Motors don't run distances. Are you asking about the number of turns or the number of what? You are measuring the length of time each of the encoder space is visible to the photosensor.


Please post a link to the datasheet for the motor with the encoder.

How many pulses per revolution are produced? And how many revolutions per second? So that we know how many pulses per second the Arduino needs to be able to count.