# Simple rotary encoder disaster

**URL:** <https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959>\
**Category:** General Guidance\
**Created:** [September 11, 2025, 7:06am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959 "2025-09-11T07:06:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 7:06am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/1 "2025-09-11T07:06:18Z")

</div>

Hours I've spent on what seems to be a very basic project and it refuses to work.

Given:  
1 Arduino NANO  
1 simple mechanical rotary encoder (no switch function) with dents.

Goal:  
Turn CW = count up  
Turn CCW = count down

I've tried countless examples of code, libraries (Encoder, NewEncoder, RotEnc, ezButton,...), with or without (poll) interrupts, changing data rates, RC filtering, internal and external VDC board powering and swapping encoder with spare ones.

The result is always one of the following:

-It does not register movement.  
-Encoder only counts up or only counts down no matter the direction of turning.  
-Encoder counts +1 and -1 in one cycle so total count remains unchanged.

Any help is GREATLY appreciated.  
Cheers

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 11, 2025, 7:10am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/2 "2025-09-11T07:10:11Z")

</div>

have you tried [Encoder Library](https://www.pjrc.com/teensy/td_libs_Encoder.html)?

try running File\>Examples\>Encoder\>Basic

can you give a link or a photo to the encoder you are using?

---

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 7:26am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/3 "2025-09-11T07:26:22Z")

</div>

> [@horace](#):
>
> can you give a link or a photo to the encoder you are using?

 ![Screenshot 2025-09-11 092153](https://europe1.discourse-cdn.com/arduino/original/4X/3/b/a/3baf5bfd583ab34b8b1619b0e48fd07621f71d89.jpeg)  
 ![Screenshot 2025-09-11 092358](https://europe1.discourse-cdn.com/arduino/original/4X/9/4/d/94d2c9e0b24c74a0a6d82d2ea68ee91d8c6452b1.jpeg)

It's basically an old guitar pedal pcb with 3 encoders.

I did try the Encoder library with no luck.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [September 11, 2025, 7:29am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/4 "2025-09-11T07:29:55Z")

</div>

Seems there could be lots of things connected to those encoders… have you tried with a plain encoder not from that PCB (or remove it from the PCB) ??

---

<div class="post-metadata">

**Author:** ![Terrypin](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Terrypin](https://forum.arduino.cc/u/Terrypin)\
**Post date:** [September 11, 2025, 7:36am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/5 "2025-09-11T07:36:42Z")

</div>

> [@indecember](#):
>
> I've tried countless examples of code,

Please show just one failing example and its full circuit schematic. Otherwise we’ve nothing solid to discuss.

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 11, 2025, 7:41am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/6 "2025-09-11T07:41:28Z")

</div>

> [@indecember](#):
>
> simple mechanical rotary encoder

Is it really an encoder or a switch?

An encoder has 2 outputs for the A and B channel, while a switch has a common and more outputs for each detent.

A mechanical encoder needs software debouncing. Not easy to handle ☹

---

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 7:44am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/7 "2025-09-11T07:44:16Z")

</div>

I was thinking the same thing, but that would be a last resort, as I would like to use the leds and buttons etc on it and the current form factor of the pcb.. I did however for now connect the leads directly to the pins of the encoder to run all tests. All leads on the pcb go to a ribon cable connector which is not attached so no connections are made internally.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 11, 2025, 7:50am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/8 "2025-09-11T07:50:38Z")

</div>

> [@indecember](#):
>
> I did try the Encoder library with no luck

how did you connect the encoder to the nano?

if I run the following code (variation of example from encoder library referenced in post 2) on a Nano (pins 2 and 3 used) it works OK

```cpp
// Leonardo - File>Examples>Encoder>Basic
// also tested on a Nano

/* Encoder Library - Basic Example
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 *
 * 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(4, 5); // arduino uno pins 2 and 2
Encoder myEnc(2, 3); // Leonardo pins 2 and 3
// avoid using pins with LEDs attached
int switchPin=5; // switch is pin 5

void setup() {
  Serial.begin(115200);
  Serial.println("Basic Encoder Test:");
    pinMode(switchPin, INPUT_PULLUP);
}

long oldPosition = -999;

void loop() {
  static int sw=0, offset=0;
  // display switch on press and reset position to 0
  if(!digitalRead(switchPin) != sw) 
  {
    sw=!digitalRead(switchPin);
    if(!digitalRead(switchPin))Serial.println("switch");
    offset=oldPosition;
  }
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition-offset);
  }
}

```

serial monitor output as I rotate the encoded

```arduino
Basic Encoder Test:
0
1
2
3
4
5
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
switch
1
2
1
2
3
2
3
4
5
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
switch
1
2
3
4
5
6
7
8
7

```

photo

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/3/6/1/3618839a0e408dcd48b3682049309fafc28d032b.jpeg)

---

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 7:50am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/9 "2025-09-11T07:50:59Z")

</div>

> [@DrDiettrich](#):
>
> Is it really an encoder or a switch?

Not sure. On the guitar pedal (zoom g2) it was used to scroll through settings or change tone values. Output of the scrolling was reflected on the 2x 7 digit segment display.

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 11, 2025, 7:57am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/10 "2025-09-11T07:57:21Z")

</div>

> [@horace](#):
>
> on a Nano (pins 2 and 3 used)

An encoder should not have more than 3 pins:  
One common (GND)  
and 2 signals

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [September 11, 2025, 7:57am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/11 "2025-09-11T07:57:26Z")

</div>

Hi, @indecember  
Welcome to the forum.

> [@indecember](#):
>
> Hours I've spent on what seems to be a very basic project and it refuses to work.
> 
> Given:  
> 1 Arduino NANO  
> 1 simple mechanical rotary encoder (no switch function) with dents.

Have you removed the encoder from the PCB?  
Can you please show an image of the other side of the PCB?  
Do you have a DMM? Digital MultiMeter?

Tom.... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 8:02am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/12 "2025-09-11T08:02:43Z")

</div>

> [@horace](#):
>
> how did you connect the encoder to the nano?

Common ground of the encoder to Nano ground.  
Lead 1 to pin 2  
Lead 2 to pin 3

Result:

```arduino
Basic Encoder Test:
0
1
2
4
5
6
8
9
10
12
13
14
16
17
16
18
17
16
17
16
18
20
22
24
25
24
25
26
28
29
30
32
33
34
36
37

```

So it only counts up in this case.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 11, 2025, 8:04am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/13 "2025-09-11T08:04:32Z")

</div>

> [@indecember](#):
>
> So it only counts up in this case.

do you have an oscilloscope to look at the signals?

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 11, 2025, 8:08am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/14 "2025-09-11T08:08:31Z")

</div>

> [@horace](#):
>
> ```arduino
> if(!digitalRead(switchPin) != sw) 
> 
> ```

What's that mystery pin?  
Where does it connect to?

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 11, 2025, 8:13am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/15 "2025-09-11T08:13:35Z")

</div>

> [@DrDiettrich](#):
>
> What's that mystery pin?  
> Where does it connect to?

in addition to rotating the encoder has a press switch which is used to reset the count (connected in the code of post 8 to pin D5)  
when using such encoders with menus I use the rotation to scroll up/down the menu and the press to select the menu item

---

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 8:15am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/16 "2025-09-11T08:15:02Z")

</div>

> [@horace](#):
>
> do you have an oscilloscope to look at the signals?

 ![Screenshot 2025-09-11 101055](https://europe1.discourse-cdn.com/arduino/original/4X/7/a/4/7a4d2cc4e8742e64e1229ca32c6912823dbff963.jpeg)

I do have this ancient analog scope which I use to trace AC signals in guitar amps, no clue how I would need to set it up though to measure an encoder 😅

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 11, 2025, 8:20am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/17 "2025-09-11T08:20:19Z")

</div>

> [@indecember](#):
>
> ```arduino
> 9
> 10
> 12
> 13
> 
> ```

You see that it doesn't count properly. Debouncing does not work well.

---

<div class="post-metadata">

**Author:** ![indecember](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/indecember/32/1236403_2.png) [@indecember](https://forum.arduino.cc/u/indecember)\
**Post date:** [September 11, 2025, 8:22am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/18 "2025-09-11T08:22:22Z")

</div>

> [@TomGeorge](#):
>
> Tom.... 😃 👍 ☕ 🇦🇺

I've come across your name loads of times on here mate, I've noticed you have great knowledge! Thanks for the warm welcome!

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 11, 2025, 8:24am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/19 "2025-09-11T08:24:17Z")

</div>

> [@indecember](#):
>
> analog scope

It's almost useless for catching switch bounces.

A cheap **logic analyzer** is much more useful.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 11, 2025, 8:42am UTC](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959/20 "2025-09-11T08:42:48Z")

</div>

> [@indecember](#):
>
> how I would need to set it up though to measure an encoder

connect to the encoder signal pins - I used DC coupling, 10mSec/division and trigger on falling edge  
e.g. rotation clockwise

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/0/6/a/06a64ac73fdc460ddb6cdbb218e20d5cd071d9ec.png)

rotation anti-clockwise

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/8/0/280310e49b3b379547072a316f8613414bf8dd58.png)

the pulse widths etc depend on how fast the encoder is rotated

[Next page](https://forum.arduino.cc/t/simple-rotary-encoder-disaster/1405959.md?page=2)
