Using Wheel Encoders

Hi there,

Would it be possible for someone to help a newbie out please?

I’m building an obstacle avoiding robot and I’ve connected two pololu wheel encoders ( one for each micro metal gearmotor + the pololu wheels) up to my arduino uno using the code below:

#include <PololuWheelEncoders.h>

PololuWheelEncoders encoders;

void setup() { 

  encoders.init(2,12,3,13);
  
  Serial.begin(19200);
  delay(1000);
  Serial.print("Start");
  Serial.println();
}
void loop()
    {
      Serial.print(encoders.getCountsM1());
      Serial.print(" ");
      Serial.print(encoders.getCountsM2());
      Serial.print(" ");
      Serial.println();
      
    }

I’m getting 0’s and 1’s or -1’s as an output in my serial monitor when I manually turn the motors and I’m not sure how to use this information to calculate distance. Should I be getting an incremental output? How can I tell how many times the wheels have rotated?

I know this stuff may be pretty basic but I’ve done quite a thorough search and have just ended up more confused.

Any help will be appreciated!

Hello.

The behavior you are seeing makes me suspect that something is connected incorrectly. Can you tell me how you have everything connected? A picture of your setup would be very helpful.

- Grant

Hi Grant,

Thank you for your reply.

I’ve just this minute discovered that I had made a bit of a schoolboy error. I’m using the Sparkfun Xbee shield and I forgot to move the switch from DLINE to UART before reading from the serial monitor! :blush:

The serial readings are now incrementing as I would have expected.

Sorry about that, although hopefully this will serve as a reminder for anyone else who does a search with a similar problem :slight_smile:

Thanks again,

Lee