Quadrature encoders: I am so sorry for asking this question

I am embarrassed that I’m asking this, but I’m kinda at wits end. I’ve had these magnetic encoders work before in a different project. I thought I knew what I was doing. I’ve stripped this down to its bare minimum, which suggests that I’m doing something obviously dumb.

I have the encoders on a micrometal gear motor. They’re wired up:

ground to ground
VCC to 5v
A to an Uno Pin 2
B to Uno Pin 3

I need to take things apart to make sure I haven’t soldered something weird but… it should be super simple, right? As I manually spin the motor, it should increase rightCount. But it’s not changing.

To make sure things are working on the Uno and with the interrupt, I rigged up a button instead of the encoders and it works fine.

I’ve tried the pins as both input and input_pullup — when it’s input, it runs wild even when the wheel doesn’t move.

I’ve tried it with two different encoders with the same issue — it’s not changing so.

Thanks in advance,

-Thom


volatile unsigned long rightCount;

void setup() {

  Serial.begin(9600);
  Serial.print("Hello World.");

  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2),right,CHANGE);
  attachInterrupt(digitalPinToInterrupt(3),right,CHANGE);

}

void loop() {

  Serial.print("Count Right:\t"); Serial.println(rightCount);
  
}

void right() {

      rightCount++;
}

The latter is the normal behavior of an open-circuit input, due to random voltage fluctuations. It sounds like there is no electrical connection between the MCU input(s) and the encoder. Use your multimeter to check continuity, and redo any solder joints.