Using an Arduino Nano to read a 20-step rotary encoder switch.

By Julian

Youtuber, shed dweller, solar charge controller aficionado

17 thoughts on “Project: 20-position rotary switch #2 – polling missed pulses”
  1. Avataaar/Circle Created with python_avatars fizzy Vlogs says:

    needs caps at the rotary switch buddy

  2. Avataaar/Circle Created with python_avatars Phasor Systems says:

    Resistance is futile! Be susceptive to trying out this simulator! Stumble Upon androidcircuitsolver on google

  3. Avataaar/Circle Created with python_avatars Miles Finch says:

    I'm after a rotary switch, 10 position, with push switch built in. Any ideas??

  4. Avataaar/Circle Created with python_avatars OM says:

    Very nice videos . Ive been constantly waching them all but that microphone of yours is hissing way too much. The high piched tone is cutting thru my brain.Where is the base? No where to be heard I suppose. Please change the microphone or do something about it. It sounds terribly annoying. Thank you.

  5. Avataaar/Circle Created with python_avatars Loc Vu says:

    where can i buy 20-Position
    Rotary Switch ???

  6. Avataaar/Circle Created with python_avatars Tshegofatso Kungoane says:

    Thank you, kind sir

  7. Avataaar/Circle Created with python_avatars Brian Oldford says:

    Hi Jullian. Did you ever resolve all the problems with using manually operated mechanical REs. I'm getting close to sorting them without the use of interrupts although I've resorted to HW debounce. (RC + 74HC14).

  8. Avataaar/Circle Created with python_avatars Martin Kanatschnig says:

    which video is the follow up where you implement the rotary encoder with interrupts?

  9. Avataaar/Circle Created with python_avatars MrMarvW says:

    Thank you so far but part 3 would be the one, I really need.

  10. Avataaar/Circle Created with python_avatars M D says:

    It is not necessary to debounce encoder buttons as long as you use the correct software algorithm to interpret the pulses. Basically, combine the PHA and PHB signals into one state variable, and track the direction you are moving as you go through the sequence. Bounce will just cause a back-and-forth movement between adjacent states, so as long as you only register a count when you move to the rest state with the right direction setting, bounce won't cause double pulses.

    I made a project once that had 3 encoders connected directly to the Arduino, and 7 pushbuttons connected to an I2C port expander. I didn't do extensive tests to make sure I never missed a pulse, but I never noticed any problems when I was testing it.

  11. Avataaar/Circle Created with python_avatars Roy Riederer says:

    I think this is an inherent problem with encoder switches in general. My car radio uses one for volume. If I turn it slowly, the volume responds smoothly. If I spin it fast, the volume responds very little if at all. Also, you would not use a knob with a pointer on it. It's not a matter of the knob position being back where you started from. You would just turn the knob until you got the desired result.

    I want to use this type of switch in some of my projects so this tutorial has been really helpful. It has given me a better understanding of how the switch works in the first place. Thanks again, Julian.

  12. Avataaar/Circle Created with python_avatars Blocco A Spirale says:

    I found it impossible to get reliable operation by taking this switch directly into the Arduino even with an RC filter on the input partly because, as you said, the problem is not bounce but noise which is very difficult to deal with in software.

    One solution is to add a SN74AC14N hex schmitt inverter between the encoder and arduino.

    I used a 10k pull-up followed by a 100R series resistor and a 470n capacitor between input and 0V of the schmitt inverter.

    This hardware removes the noise so effectively that this minimal, interrupt-driven code triggered by a rising edge on the clock input is all that is required for perfect glitch-free operation:

    void rotaryEnc()
    {
    if (!digitalRead(datPin))
    {counter++;}
    else
    {counter–;}
    }

    I also used exactly the same hardware for the push switch input and it completely removes the need for software de-bouncing.

  13. Avataaar/Circle Created with python_avatars AquaLars FishNShrimps says:

    Old video but my suggestion to you is to use interrupts on both a and b. That's the way I'm using rotary encoders and it almost never misses a pulse even in a big menu system.

  14. Avataaar/Circle Created with python_avatars Gorazd Rosbach says:

    The only proper way to use any quadrature encoders is to generate on both channels (A & B) an interrupt on any flange (falling or rising) and at the given interrupt check the AB channel state and compare them with the state before the interrupt occured. It gives you 16 possible states, some of them are errors (you can skip them) some of them are an increment and some of them a decrement.

  15. Avataaar/Circle Created with python_avatars Harry O'Brien says:

    Try using a couple of decoupling capacitor whilst looking for the rising edge with an interupt if using the whole flashing led thing (i presume thats your way of showing standard use)

  16. Avataaar/Circle Created with python_avatars Ronen Shemesh says:

    to my opinion: u should decode the switch Gray code position after debouncing

  17. Avataaar/Circle Created with python_avatars Richard Motsch says:

    I really enjoyed parts 1 and 2 of the rotary encoder series, where is part 3?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.