I have purchased some Jopto ‎JY-3DP-234 rotary encoders but have no idea what resistors to use to connect with the raspberry PI zero, if any.

I am using three of the encoder pins, one to ground and the other to two GPIO pins, in order to measure the encoder state when it moves. The rated voltage of each encoder is DC 5V, the Contact resistance: ≤100mΩ and the insulation resistance: above 100MΩ. Do I need to attach resistors in-between each GPIO connection and if so, why? I am quite confused by this.

  • they are just two switches ... there are many examples on the internet about connecting switches to the RPi
    – jsotola
    Feb 27 at 16:35

1 Answer 1


Here's an useful link to understand the working principle of rotary encoders

The resistances mentioned are the typical values for the product, and will vary by construction, design and materials used and not are ones that need to be added in your circuit.

Contact resistance is the series resistance encountered when the pin "A" or "B" metal contact connects to the "Common" (GND). Ideally, we would want this to be zero (ideal closed circuit) but in the real world it is typically in the milli-ohms range.

Insulation resistance is the series resistance encountered when the pin "A" or "B" metal contact connects to the insulator (that alternates between conductive surfaces connected to the "Common"). Ideally, we would want this to be infinity (ideal open circuit) but in the real world it is typically in the mega-ohms range.

You might need to add some external support components though:

There are off the shelf modules like the KY-040 KY-040

that include "pull up" resistors that connect the pins A and B to VCC (R2, R3 are pull ups, unpopulated R1 is for the push button) that appear as a logic "1" when the metal contact is touching the insulation and get pulled down to GND (logic "0") when it touches the "Common".

While internal pull-up/down are available on the RPI GPIO pins as mentioned here, they are considered rather "weak" and susceptible to external electrical noise.

Since you mention having only the rotary encoder, you'd need to add the external pull up resistors (10k should be fine) on your solderless breadboard (or PCB) you intend to use.

Ideally, turning the knob would produce perfect waveforms in the expected sequence. However due to the manufacturing imperfections/limitations there will be "noise" (showing up as spurious very short 0 -> 1 or 1 -> 0 transitions) that need to be handled ("de-bouncing") either in hardware (like using a Resistor-Capacitor filter + optional Schmitt trigger) or in software (there are many approaches based in polling, GPIO or timer interrupts).

  • Thanks for your reply. So I've enabled pull up resistors for every pin via software but when I have python script read interrupt values for a clockwise or anticlockwise rotation, I get problems. I always get a successful reading that a rotation has been made, but 50% of the time it gives nonsense values, indicating a move in the wrong direction. It’s seemingly random. What am I doing wrong? Mar 9 at 15:50
  • The problems you describe are very typical of the noise I referred to in my answer. This is caused by the mechanical movement not being perfect resulting in momentary (typically a few hundred nsec, but slow enough for the micro controller/processor to detect them as legal transitions of 0-1/1-0. One way to visualize and confirm this is to use an inexpensive logical analyzer (typically available for a few dollars on Amazon in the US). Here is an answer that discusses contact de-bouncing. Mar 11 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.