Encoding 16 x 4 position rotary switches

Hi there I am brand new to the Arduino ecosystem and have very little knowledge of electronics so far (working on it). I am building a suduko style puzzle for an escape room using a 4x4 grid of 4 position rotary switches. To solve the puzzle no switch can be set to the same value as any in the row or column or in the 4 2x2 grids. I could hard wire a single solution but would like to make the puzzle general purpose and have the solution determined by a micro controller.

My question is, what is the most efficient way of interfacing the switches to the Arduino to determine the position of each switch in the grid? It seems as though some form of encoder would be necessary. I am thinking if I can make the reading of each switch addressable and the value of each switch binary encoded to use 2 bits.

Any thoughts please?

It's quite common to read a 4x4 keypad by driving one row at a time and scanning columns, needing 8 lines. You might generalise that by arranging resistors on your switches such that each position gives a different resistance, which you could sense by applying a suitable bias current and looking at the voltage developed with the analogue inputs. Some steering diodes might be needed, I haven't thought this through completely.

1 Like

What type of Arduino did you plan to use?

If you already plan to use a Mega, then you have plenty of pins. But for most other types of arduino, some extra chip might be needed. If we know what you plan to use, we can advise what extra chip to use.

I also thought along the lines of a matrix.

I also realised that you can ignore one of the terminals on each rotary switch: If you can detect that the switch is not in one of positions 1, 2 or 3, it must be in that 4th position.

1 Like

Yes looks like I could combine pins on the switches to have 2 lines per switch (2 bits) and then use either 4 x 8-to-1 or 2 x 16-to-1 multiplexers like the HEF4067BP.

Does this sound like a reasonable approach?

Many thanks in advance.

There are many ways to approach it. Your idea could work, but this is an interesting optimization problem: how to achieve a solution with minimum extra components/pins. I'm pretty sure your idea can be beaten! I'm giving it some thought...

1 Like

My best idea so far is to use 16 digital pins and, I think, 16 diodes (just small signal diodes like 1n4148).

If you don't have 16 digital pins available, then you could use 1x pcf8575.

Another possibility - sixteen good old analog potentiometers with the values gotten through a multiplexer:

After you've got the sixteen values you could 'digitize' them with the map() function as below:

Position feedback could be via a legend on the panel indicating which number is selected.

You could still hardwire the switches, but use spade connectors to allow the escape room proprietor rewire them. This looks like an easy problem looking for a hard solution. :wink:

Using rotary encoders in a matrix is not a very good idea, because it will be easy to miss pulses from them because of the time it takes to scan the matrix. Normally a single encoder would need to generate oat least one and preferable two interrupts so they could be read fast enough so as to not miss pulses and get a false number from them.

This is not so bad if the encoders have a knob on them with no pointer on it, and you have some feedback elsewhere that displays the number you have reached with each encoder.

But really I would use a pot to replace each encoder, like others have suggested.

I missed that. I thought the OP was using SP4T switches. Rotary encoders would increase the complexity exponentially.

Pots would work too, but I favor the straightforward mechanical solution- No Arduino even needed.

Who missed what?

That sounds like 16 rotary switches with four positions each.

A 16 to 1 multiplexer would allow a scanning algorithm on <you do the maths> pins.

Or all real pins on a Mega. Scanning.

a7

Agree. Someone inserted “rotary encoders” in the thread and I assumed I misread the original post.

My recommendation remains unchanged.

It sounds like if you're reading a 4 position mechanical rotor switch, in each of the 4x4 matrix, then youve got 444 total pins to read. So 64 pins.

You could use 4, 16 channel multiplexers with a simple loop to read all 4x4x4 positions continually.

Off the top of my head, this would need 16 pins to read.
(A 5th multiplexor could reduce the pin count further, but not needed with a Mega)

When the user rotates the switch into a position youll know which position is "high"

So your arrary would be
[SwitchPosition, column, row] with either a high or low reading

The person in charge would select the appropriate winning array combo. You would need to be careful with the logic of switch position cannot equal itself if the column or row equals itself

Something along these lines, id think?

Hope it helps!

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