# Detect rotation direction of a rotary switch

But I want to be more precise about what I'm trying to do. I have a 1 pole 8 position rotary switch with continuous rotation, and I need an interface (a micro?) to send pulse A for each click clockwise, pulse B for each click counterclockwise. Cannot use a rotary encoder as they have a low activation torque, and I need a strong "click" feeling. Any way to achieve this?

• Have you considered getting an encoder with larger detents? Jan 14, 2016 at 11:53
• Yes I tried like a few different encoders but they all have a low activation torque. The best one is this: alps.com/prod/info/E/HTML/Encoder/Incremental/EC20A/… but the torque is still too low...
– Mssc
Jan 14, 2016 at 12:05

Two possible solutions both using micros. Currently you can get a PIC or ARM for under \$2 so that is a good way to go.

a) Analog solution.

Wire a ring of resistors in series round the rotary switch.

Sense the voltage either using onboard ADC or time to charge a small cap past the schmidt trigger level of one of the inputs.

Compare 'ADC' value to previos to work out direction

b) Digital solution

Wire 8 lines to 8 inputs (even on a 20 pin TSSOP you have enough IO)

Wire the wiper to ground.

Wire pull ups from each of the 8 poles to Vcc (preferably use internal pull ups)

Set an IRQ on low to high change for any of the input pins, debounce

You can invert the sense of this wiring.

I have recently implemented a design where an ARM MCU is used as an I2C to parallel port. The solution was simpler, cheaper per pin and more flexible than any discreet logic I could find - including 74 series shift registers.

As raised by the commentators below, the switch can be coded with just sufficient states to differentiate the sense of rotation.

In the case of a switch with end stops, or with a number of states exactly divisible by three, only 3 states are required. These states are wired cyclically around the rotational switch.

In the case of a switch with continuous rotation capability, an additional state is required to avoid having two adjacent same-states or two same states separated by a different state.

The base requirement is that whatever the position and whatever the direction a new state is reached that is different from the previous state and different from the state for the alternate direction.

Coding the input increases complexity and introduces more chance for error.

• You don't even need 8 pins. Since you only care about direction and not position you can connect throws on opposite sides of the switch and reduce the requirement to 4 pins. Jan 14, 2016 at 12:24
• 3 is enough, see my answer on his previous post. Jan 14, 2016 at 12:28
• Quite unrelated, but here goes: in the design you mention in the last paragraph, using an MCU to replace a multiplexer, how would you go about programming the MCU in production? Assuming a reasonably cheap product, wouldn't connecting a programmer and flashing the MCU in each unit easily become a significant portion of the assembly time?
– Timo
Jan 14, 2016 at 13:00
• @WoutervanOoijen: Three is enough if the number of positions is a multiple of 3. Otherwise, you need to pick a number greater than three that divides evenly into the number of positions. Or else you can just use 4 and have some special-case code that handles the "illegal" transition at the point where pattern is broken. Jan 14, 2016 at 13:00
• @Timo Two easy solutions: a few suitable copper pads and a programmer connected by a 'bed of mails', or buy pre-programmed chips (or, for lower volumes, program them yourself before assembly). Jan 14, 2016 at 13:15