Encoder on pin 10 and 13 not reading properly

I'm attempting to use pins 10 and 13 to read a rotary encoder using the Encoder library by Paul Stroffhagen. Instead of a proper reading, the encoder value just fluctuates up and down a few clicks. I know there are issues with pin 13 being used as input due to it being connected to an onboard LED, but I have also tried Arduino's official advice on this and attached an external pulldown resistor. This still has not worked. Any Ideas?

Welcome to the forum!
Have you been able to make it work with other pins? Say, 10 and 11? That would narrow it down to a problem with pin 13, as opposed to any other issue(like the code you didn't post).
For future reference:

That's only true for some Arduinos. Mainly the small-boards, not the Uno R3.

We need a lot more information to help you.
Diagram/code/hardware used.
Read the posting guidelines.
Leo..

It works with pin 9 and 2. However. Pin 2, 9, 10, and 13 are the only available pins and I need to run 2 encoders.

Heres the code:

#include <AFMotor.h>
#include <Encoder.h>

Encoder leftEncoder(9, 2);
Encoder rightEncoder(10, 13);

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);


float motorDmd;
void setup() {
  Serial.begin(9600);
  pinMode(9, INPUT);
  pinMode(2, INPUT);
  pinMode(10, INPUT);
  pinMode(13, INPUT);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  setMotorSpd(1, 100);
  setMotorSpd(2, 100);
}

void loop() {
  Serial.print("left encoder: ");
  Serial.println(leftEncoder.read());
  Serial.print("right encoder: ");
  Serial.println(rightEncoder.read());
  

}
void setMotorSpd(int i, float spd){
  int d;
  if(spd < 0){
     d = 2;
     spd = spd * -1.00;
  }else{
    d = 1;
  }
  if(i == 1){
    motor1.run(d);
    motor1.setSpeed(spd);
  }else if(i == 2){
    motor2.run(d);
    motor2.setSpeed(spd);
  }
}
void updateMotors(){

}

Which Arduino.

Do you know that the analogue pins can also be used.
They are just digital pins, with the added functionality of analogue-in.
Encoder rightEncoder(A0, A1);
Or, on an Uno R3, (14, 15).
Leo..

I'm using a Uno R3. Do the analog pins have interrupt capability though? I need to use interrupts for my readings since I have these encoders spinning at relatively high speeds.

On an Uno R3, only pin 2 and 3 have external interrupt.
Leo..

Ok, that would explain my issues. I had thought that pins marked with a squiggly line had interrupt capability. And the ones marked on the Arduino are 3, 5, 6, 9, and 19. Thank you for your help.

The tilda on pins 3, 5, 6, 9, 10 and 11 signifies PWM capability.

Meaningless without numbers.

The Encoder.h library you're using seems to allow one interrupt pin and one normal pin per encoder.
Leo..

Just for anyone ever having a similar issue. I ended up using pins 9 and 2 to read the encoder via 2's external interrupt, and then used pins A0 and A1 for the other encoder and read it via pin change interrupt C, since I wasn't using the analog pins for anything else. I also got rid of the library and just wrote my own interrupt-based encoder reading.

All pins on the Uno R3 have interrupt capability via the pin change interrupts, but they are more involved to use as each port shares one ISR.