Can I have your opinion please!

Hi I'm starting a project, It will be using 2 rotary selectors, each with 18 positions. giving a total of 324 possible options (I think). Obviously I can't use 36 I/O pins ( 18 pins for each terminal on the rotary selectors).
I have 2 ideas for a solution.
1 wire them up as if making a button array.
2 Add resistors to the rotary selectors pins, making them into a form of variable resistor, and reading it as you would a potentiometer.
For option 1 I'm thinking there are a total of 36 positions, witch would equate to a 6x6 array. 6 columns and 6 rows, this would still need 12 IO pins to read them.
For option 2 I would just need 1 analogue in pin, and a single analogue read statement in the code.

Any ideas / comments? How would you approach this?
please include pro's con's.
Thanks.

Do you already have and do you need to use real 18 position rotary switches?

This seems like a place where a rotary encoder and some kind of feedback for knowing which position you twirled to would be easier and maybe even nicer.

a7

Need specs on you devices. Some encoders put out binary, so 16 positions uses 4 io lines.
18 positions is an oddball number, what are you trying to make?
A mega 2560 has 54 digitals and 16 analogs for 70 IO's total

Assuming you have two physical rotary 18 position wafer switches which you wish or have to use, regardless of whether it's the optimum solution.
A 17-resistor chain for each 5V at one end, 0V at the other would provide an 18-value AI. Use well matched resistors (an ohmmeter for selection will do) to make sure the divider network is 'clean'.
Do that twice, you'll have two AI that represent your two switch settings.

Hello fenceup

Use two Rotary Encoders KY-040 and save the last positie in the EEPROM.

With 5 pins, you could implement Charlieplexing to control and monitor 18 inputs (max of 20 inputs with 5 mcu pins). However, please note that Charlieplexing becomes more complex as the number of pins increases, and it has limitations in terms of response time and reliability which could be tuned in code or hardware. Charlieplexing is usually used for output to leds, but I have done a 20-button keypad using the technique.

Dedicated multiplexing chips would be another way, especially to get logic state reliability.

Knowing the type of switches you have would allow for better advice, i.e. are they break-before-make type which means state 1 is broken before making state 2, repeated up to state 18. Are they 18-position rotary switches with a single input to the selected 1-of-18 outputs?

Or do something with a display where you can scroll though the “ positions ” with one button and turn on/off with another You could even do that with a two line display .
I wouldn’t do the resistor chain bit as if you end up with a worn/dirty contact it will read wrong.
A keypad is another good solution

Needing all those combinations seems a bit odd - what’s the project ?

I would go for option 1.

I'm not sure option 2 would be possible, most rotary switches have a "wiper" pin and a number of normally-open pins for each position. You will probably be able to read both switches with 20 pins.

Another option would be to use lots of small diodes (like 1n4148 or similar) to binary-encode each position. 5 pins per rotary switch. Or 7 pins for both switches.

Hi,
What is the application?
What do the combinations represent?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Thanks everyone for jumping on this so quick.
Ok so I'm putting a project in an old AvoMeter



I love the feel of the original selectors. So I'm working with what I have.

So thanks for the suggestions, for alternatives like rotary encoders, but on this occasion I only need solutions for the rotary selectors.

The centre selector arms are connected together.

At the moment I'm trying a chain of 22ohm resistors on the first selector and a chain of 100 ohm resistors on the other, and taking a lead from the busbar that connects the two selectors. forming a Voltage Divider, reading the value as a single analogue read.
I'm not sure if this will give enough separation between values yet but first tests look good.

Should I be going for a high or low overall resistance, as it will be consuming power all the time, I guess its no different to using a potentiometer. so I'm not sure how important this is.

I think I'm doing something on those lines.

Thanks Tom I'm thinking internet radio, but now I have this I'd like to see if I can read every input it has, with an Arduino or ESP32. There's another 2 potentiometers and a button I'll probably use as well.

Break it into several resistor chains. Say 3x6 x2 for a total of six states on six AI's. Better voltage spacing means looser tols on the R's and easier/more reliable readings.
Put in a graphics display and program it to look like the original analog meter. Have it do different displays, time, temp, rh %, baro etc.

No you won't, a rotary encoder is not what you have. It helps to use the right words.

You have an 18 pole switch which can be read in many different ways. The simplest is using some port expander chips to get more inputs. You can get the MCP23017 I2C interface ones, or the MCP23S17 SPI ones. each chip gives you 16 inputs so using three will cover your need for 36 I/O pins. This also gives you the advantage of having a pin that will go high if any input changes. So you only need to monitor one pin to see if you need to take any further action.

All other options, like a matrix, require you to scan the switch inputs constantly to see if anything as changed.

It's kind of late and maybe I'm missing something, but why not use a Mega?

Those are good switches, and therefore I don't see a problem to use resistor ladders.
18 1k resistors in series per 18-pole switch. That takes up two analogue inputs.
Add a very high value resistor (10Megohm) from pin to ground, so you can also detect if the switch is between two positions.
A simple map() statement could be used to convert 0-1023 to 18 positions (plus zero).
position = map(analogRead(A0), -28, 995, 0, 18); // 0-18 with equal spacing
Leo..

Edit: Please check my map() calculations.
Calculations are made with the first contact connected between the first and second resistor from ground, and the last contact to VCC.

Yes I will! If I was to buy one today from RS online. it's called a "Rotary selector switch".
I've seen it called a "rotary selector" or rotary switch" Never called it an encoder.

I'll for sure look into your suggestion. Thanks

Do I have to worry about the power consumption adding such a high resistance or is it better to be high than low?

More the resistance lesser will be the power consumption. Although even using 1k resistor won't draw much current.

I think you misunderstood it's function.
The resistor is there to ground the pin when the rotary switch is between two positions.
Without it the pin would be floating, and give a random number.

A better option is a 100n capacitor between pin (rotary common) and ground, to hold voltage between switch position. That also reduces the ladder to 17 resistors. map() numbers change a bit.
position = map(analogRead(A0), -30, 994, 0, 18); // 0-18 with equal spacing

Just solder 17 equal resistors (about 1 to 10k) between the 18 contacts of the rotary switch.
Connect the first one to ground, and the last one to VCC (5volt).
Add a 100n cap between rotary common and ground, and connect rotary common to an analogue pin.
Leo..