Can rotary encoders share pins?

Hi all,

I'm building a midi controller that requires many rotary encoders(18 to be exact) and was wondering if it is possible to have them share arduino pins(e.g., enc1 uses pins 2,3 and enc2 pins 3,4). Encoders will never be used together, only one at a time. I played a bit with 2 encoders and there was no problem at all, but once I connected more(4-6 on 4 pins) I get various results, from all working nicely for a while, to none, to some. Any idea if this is doable in some other configuration? I'm using a Yun, can also connect a pro micro and divide the encoders-though still the inputs are not enough if I go the 2 pins per encoder way.


If channel on one encoder was held low from the position it landed at once it stopped turning and you turned the other encoded it would never go high. I don't think it will work.

You could read the encoders in a matrix. This would require two diodes per encoder. You won't get interrupts or the regular Encoder.h library to work with this, but for knobs turned by hand I think it will be easy.

Another way is to use a pair of analog multiplexers to route the A and B signals - with a pair of 16 to 1
multiplexers you could read upto 16 encoders using 4 pins to select address and 2 (with pull-ups enabled)
to read the A and B. No diodes needed.

Using analog multiplexers allows the internal pull-ups to be shared by all the encoders.