Rotary's encoder switch pin triggering with knob rotation

Hello. I've hooked to a rotary encoder to my Arduino Pro micro. (Basically a mini unofficial duemilanove).

The weird thing is that the SW pin (which is connected to the push button of the rotary encoder) changes state whenever I rotate the encoder knob! More precisely it goes to 0 in the mid position between two detents of the knob (I know this because I printed the digitalRead value of the switch pin to the serial port)

I couldn't find any lose connection or shorts. The board is powered via USB. There are no capacitors used for damping. The wires if the encoder are connected directly to the Arduino

Why is this happening?

Hello
Check the wiring again and make cross checks.
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс

Try a different switch1

Hi,
Can you please post a circuit diagram and a link to the encoder please?

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

The encoder is something like the one shown here.
https://www.conrad.com/p/iduino-rotary-encoder-1-pcs-se055-1485328

Did you post a schematic, did´nt you?

Probably because your input is floating. All encoder outputs need to be connected to pins with pinMode INPUT_PULLUP so they don't float.

So I found the problem.
I was using a digital out pin to power the encoder. (Because my board has only one V out which is already used). I simply made that pin out put a HIGH voltage in the hopes that I would act as a V out .

However, this caused the Problem that I have described above.

But the problem settled when I set that pin to OUTPUT pin mode.
Maybe I should have tried this earlier.

Oops! That makes no sense at all! :astonished:

That is because without setting the pin to OUTPUT mode, you were powering the encoder through the internal pullup resistor, creating a voltage divider with the pullup resistors of the encoder. Likely when both encoder contacts were closed the voltage was low enough to read as a LOW on the open switch contact.

1 Like

Thanks so much for taking the time to explain what was happening! Really appreciate it. :slight_smile:

Hi,
It sounds like you need one of these?


Prototyping board.

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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.