Help- 2 digit combo lock

Hey guys, this is my first post ever.

I acquired some neat rotary thumbwheel switches, made by the digitran company. I want to use them to make a lock box with a combination lock. The switch has two rotary dials with 12 positions each. I'd also like to be able to change the combination. What would be the best way to handle to build this circuit without requiring 24 input pins into my arduino?

I've read a little bit about shift registers, and it seems like that could be a useful solution, but as a total novice I'm not exactly clear on how to implement them. Anyone know of a simple beginner level guide for this?

any model numbers or other info to ID the switches?

A bitwise switch (or call them as you will) would have fewer pins than positions, and serves data as a binary. I forget the other type of switch's name, but it's like a potentiometer, but has one pin per position, plus a common. IE, it's an analog switch.

Bitwise/digital:

position1 = 0001 position2 = 0010 position3 = 0011 position4 = 0100 position5 = 0101 position6 = 0110 position7 = 0111 position8 = 1000 position9 = 1001 position10 = 1010 position11 = 1011 position12 = 1100

analog:

position1 = pin1 position2 = pin2 position3 = pin3 position4 = pin4 position5 = pin5 position6 = pin6 position7 = pin7 position8 = pin8 position9 = pin9 position10 = pin10 position11 = pin11 position12 = pin12

If they say 24 pins, then it sounds like there is no binary encoding going on.

This is what I did for a 12 position rotary switch for my Arduino radion, if its any help.

http://srmonk.blogspot.com/2011/09/arduino-solar-radio.html

Scroll down for the schematic. Basically a resistor between each pin making a kind of linear pot, as KeitaruSM says.

Scroll down a bit further for the sketch to convert the analog reading into a number between 1 and 12.

magnethead794: any model numbers or other info to ID the switches?

I believe the type of switches I have are 300 series Digiswitches by digitran: http://www.digitran-switches.com/specsheets/thumbwheel.pdf

Plus a couple low res photos of my actual switch:

I want to use these for aesthetic purposes. Wiring a bunch of resistors in series to this switch is not out of the question, I was just hoping there was a more compact/organized solution.

I had a lot of free time today so I decided to just wire up my switch in the same way Si did for his channel select switch in his radio project. This was pretty straight forward and in theory works quite well. In practice however I have found that the analog values tend to jump around quite a bit. I wrote a simple sketch that just checks to see wether or not the switch position has changed and then outputs it. Anyone have any ideas for some more consistent results?

int val = 0;
int old_val = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  val = (analogRead(0) / 90);

 if ((old_val != val)) {
   old_val = val;
   Serial.println(val);
 }
 delay(100);
}

Particularly position 1 on my switch bounces back and forth between 0 and 1. If I just output the results without the if statement the output appears consistent.

I have found that the analog values tend to jump around quite a bit

Ah, your switches may be 'break-before-make' so as you turn the knob, there is a moment when the analog in is floating. You can solve this in software by making sure that the analog value has jumped by the amount you would expect from turning the switch one position (within some tolerance), and ignoring all other false changes.

Si: You can solve this in software by making sure that the analog value has jumped by the amount you would expect from turning the switch one position (within some tolerance), and ignoring all other false changes.

Sorry I'm bit new to arduino and programming, I'm not sure exactly how to pull that off. Any hints?

Put a high resistance pull-up so that the floating condition returns an obviously-out-of-range value?

Also add some debounce logic.

Does your ‘analogRead(0) / 90’ return consecutive integer values for all your switch positions? I think it would need to, for your algorithm to work reliably.

PeterH: Does your 'analogRead(0) / 90' return consecutive integer values for all your switch positions? I think it would need to, for your algorithm to work reliably.

Yes it does.

Sorry I'm bit new to arduino and programming, I'm not sure exactly how to pull that off. Any hints?

Keep the old switch position in a variable called oldPosition (1 to 12). Then work out the new position (1 to 12) from analogRead. If the new position isn't either the old position + 1 or the old position -1 then ignore it.

Finally if it was a valid change of position, set the value if oldPosition to be the new position and off you go round the loop again.