30rpm d.c geared motor encoder error

Recently, I brought a N20 6V 30rpm pololu dc geared motor from here-

And to test the encoder I used the code from this link of the same website.

The issue is, the encoder value just keeps oscillating between 0 & 1 . It neither decreases or increases in response to manually rotating the encoder wheel or programatically rotating the motor.

I have warped around this issue for days now. Am I missing any detail here?

Don’t make us go look for your code. Post it here. Use code tags.

How do you have the encoder wired up? Can you draw a picture of your wiring and post it here?
When the encoder is turned, you should be getting changes on 2 of the wires. It sounds like you only receive changes on one wire.
I would want to confirm that you have both data wires from the encoder connected properly to 2 pins on the arduino.

I would want to confirm that you have both data wires from the encoder connected properly to 2 pins on the arduino.

Run this simple test code while slowly turning the encoder to check your wiring. You should see a repeating sequence like;

11
10
00
01
11

Or the reverse, depending which direction the encoder is turned. You are likely to see repeats of the same value, but the pattern should be clear.

#define encoderPinA 2
#define encoderPinB 3

void setup() {
 Serial.begin (115200);

 pinMode(encoderPinA, INPUT_PULLUP);
 pinMode(encoderPinB, INPUT_PULLUP);

}

void loop() {
 byte a = digitalRead(encoderPinA);
 byte b = digitalRead(encoderPinB);
 if (a == 1)
   Serial.print("1");
 else
   Serial.print("0");
 if (b == 1)
   Serial.print("1");
 else
   Serial.print("0");
 Serial.println();
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: