problem with arduino

Hello there,
I've a problem with my Arduino UNO project: how can I use a dip-switch 8 position with only 4 pin of arduino.
my idea is use a encoder but the problem of encoder is the priority so for example if give to input 10001100, the encoder read only the first bit.
the way is use a encoder, decoder, multiplexer or demultiplexer.
thanks so much

if u create a binary stack of resistors weighted each dip-switch, u can use the adc(0-1023) to determine the status of all 8 bits..and only using ONE PIN.. use 1% resistors..

example

dip sw 1 100 ohm MSB
2 200 ohm
3 400
4 800
5 1,600
6 3,200
7 6,400
8 12,800 LSB

WillyBestSM:
my idea is use a encoder but the problem of encoder is the priority so for example if give to input 10001100, the encoder read only the first bit.

I don't understand that.

Can you explain what you want to achieve rather than how you think it might be done?

...R

You can use 1 analog pin to read the 8 dip switch using voltage divider.

Or 3 digital pins using a shift register connected to the switch.

Hi,
What is your application, if you only have 4 pins available, we may be able to help rationalize your input and outputs.
Do you now you can use the analog input pins as digital pins?

Tom.... :slight_smile:

You use a shift register such as a 74HC165.

You read it serially using three Arduino pins, two of which can also be used for something else.

You need pull-up resistors (10k) on the register inputs, with the switches going to ground.

The analog ladder trick is clever, but not entirely reliable, frequent cause of failure in video monitors and TVs, MP3 players, GPS and so on. May not be a problem if it is all on a dry, warm PCB inside a case.

if two analog pins are used, the ladder trick becomes much more stable..

1 1
2 2
4 4
8 8

instead of

1
.
.
.
.
.
.
.
256

creating 2 4bit nibbles that can be concated..

Also, depending on the usage of the dipswitches, if for example the dipswitches are only needed to be read one time, the same analog pin can then be re-used as a digital out to a hi-impedance load..or an AC coupled load..

much depends on what is ur specific application