Electrical Component - 8bit Switch

Hello,

I do not know if such a thing exists or even what it is called so looking for some help if possible. Thanks

Here is what I am looking for.

A device that can ouput a value depending on which multiple switches are set on or off where the combined output value can be between 0 and 256.

I have seen some small blue pcb mounted dip switches which have a 8 switches on but these are all individual 2 state (on-off) switches.

What I would like is to have something like that blue pcb dip switches (say 8 intoal) but all interconnected in some way so that you could use binary patterns for switch settings like and then I could get the Arduino to act upon the unique output valve.

Does an item like this exist?

PS, I know I could do all this with individual switches going to arduino pins but using 8 pins does not leave many pins left on an Uno

Thank you

Here is what I am looking for.

A device that can ouput a value....

Do you mean an analog or a digital value? Simples would be digital. You can read the state of all 8 switches using a shift register:

http://www.arduino.cc/en/Tutorial/ShiftIn

Also consider using a 74HC165 shift register instead of the CD4021 in the tutorial.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

A device that can ouput a value depending on which multiple switches are set on or off where the combined output value can be between 0 and 256.

Being congenitally pedantic, I'd have to say that would be a nine bit value. :wink:

AWOL:

A device that can ouput a value depending on which multiple switches are set on or off where the combined output value can be between 0 and 256.

Being congenitally pedantic, I'd have to say that would be a nine bit value. :wink:

Oh you software guys get me with your 'start counting stuff from zero' song and dance. When I count my $100 dollar bills in my wallet I don't go "zero bills, one bill, two bills... etc." :smiley:

When I count my $100 dollar bills in my wallet I don't go "zero bills, one bill, two bills... etc."

When I count the notes in my wallet, I rarely get past zero.

Think about it.
A baby is born zero years old, but we say they are in their first year of life.

256 is a nine bit number.

SniffTheGlove:
A device that can output a value depending on which multiple switches are set on or off where the combined output value can be between 0 and 256.... I know I could do all this with individual switches going to arduino pins but using 8 pins does not leave many pins left on an Uno

Even if such a device existed, how do you propose to read its output "between 0 and 256" (surely you mean "between 0 and 255") - i.e 256 distinct values - on a DIGITAL pin? Digital, by definition, has TWO states: on or off; low or high; true or false.

Convert the range of values you wish to detect to binary: for every bit (binary digit), you neeed a digital pin.

It is possible to get binary-coded switches that are graduated in hexadecimal (i.e. 0 through F) - in other words a sixteen position switch - so you would only physically need two of these to input your 256 values but you still need eight pins to read them.

If you can only afford one pin, the alternative is to use a potentiometer on an ANALOGUE input which will give you a value of 0 to 1023. Divide the value by four to bring it into the range you want.

SniffTheGlove:
A device that can ouput a value depending on which multiple switches are set on or off where the combined output value can be between 0 and 255.

PS, I know I could do all this with individual switches going to arduino pins but using 8 pins does not leave many pins left on an Uno

To read 8 switches with 3 data pins try an 8-bit parallel-in/serial-out shift register: one output pin to load the 8 bits, one output pin to shift the bits out, and one input pin to receive the output.

To read 8 switches with 4 data pins, try an 8-bit multiplexer: three output pins to select which bit and one input pin to receive that bit.

Thank you for pointing me towards an 8bit Shift register and the tutorial, your help is appreciated.

There is another way using analog input(s). You use the switches to control a set of resistors of values whose ratios are powers of two. Passing a constant current through them means a voltage is developed proportional to the resistance. You read this with analogRead and then pass the result through map to get the binary number back.

However this would be really tricky to do with one analog pin for 8 switches due to tight tolerances required - much easier with two analog pins treating the switches as two groups of four. The resistors don't have to be powers of two - so long as the ratios are 2 or more between neighbouring resistors you can reconstruct the switch configuration.

Finally the way you wire it up is to have four switches in series and a resistor in parallel with each switch. Instead of a constant current source you can have a resistor to Vcc - the output voltage is then not a linear function of switched resistances, but is roughly proportional. Say the switched resistances are 1k, 2k2, 4k7 and 10k, and the resistor to Vcc is 47k. With all switches closed the voltage is 0, with all open you have a potential divider with 47k on the high side and 17.9k on the low side - 1.38V or so. Do some calculation or measurement to work out the results from analogRead for each of the 16 switch states and then write code to discriminate.

The advantages are only 8 resistors and 2 pins used, disadvantages are that they have to be analog pins, you have to work out all the discrimination code.

I used a PAL (Programmable Array Logic) device to
generate memory chip enables for a project that I
worked on many years ago. Don't know if they are
still available but the were fairly inexpensive and
fast. If speed is not an option an EEProm would
also probably work. You could program the pattern
needed at the memory location specified by the
address lines to the EEProm chip.

RWW