Rotory Encoder counting only one direction

Hi there,

I've been testing my circuit (Arduino UNO) with a typical rotary encoder module for a week now.

and all of a sudden it started counting up and no matter I turn it clockwise or counter clockwise, it always counts up.
I checked my code, loaded some sample codes in the library i use, nothing changed.
Luckily I bough two of them, so I plugged the other module and it started to work.
So is my encoder gone bad? Are those so fragile to fail so soon? Just a week use. I'm pretty sure I did not abuse it that much for it to break so fast.
Anyone had this sort of a similar case?
Can anyone recommend me a good reliable encoder to use?

This is the test example I was trying.

/* Encoder Library - Basic Example
 * This example code is in the public domain.

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(2, 3);
//   avoid using pins with LEDs attached

void setup() {
  Serial.println("Basic Encoder Test:");

long oldPosition  = -999;

void loop() {
  long newPosition =;
  if (newPosition != oldPosition) {
    oldPosition = newPosition;

How do you think that the encoder will work with pulldown resistors and no Vcc connection? For details please post linka to the data sheet and Encoder library.

Using interrupts will call for trouble.

Mechanical wear can cause metal chips and other failure.

Take a view here:

Thank You

@DrDiettrich I've corrected my post.
Link to the Encoder Library

@paulpaulson thank you. But still my encoder module is counting continuously. I guess as @DrDiettrich said this might be a mechanical issue with the encoder.

Try swapping CLK and DT, see if the direction changes.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

@TomGeorge thanks did that too and didnt help.
I managed to work it out after removing the pull-up resistors from CLK and DT lines on the module.

Your schematic shows CLK & DT connected to pins 0 & 1, code says 2 & 3, do you have internal pullups enabled?

@JCA34F my apologizes it should be on pin 2 and 3. Corrected it in the original post.
Not in my code, but may be inside the library? didn't check.
Thank you.