DIP switch for addressing

i'm trying to make Project communicate between 6 arduino simply as 1 server and many clients server should control and get information [sensors Values ] from other clients using [esp8266] modules

so i wanna make each client use DIP switch for addressing to let [Arduino UNO Server] communicate with each arduino client . wont use or wast many pins for just addressing and want addressing to be in decimal as many supported values as many clients can communicate. " somthing like that "


i think ShiftRegister is the best way but sadly i'm easy get confused and things not clear to me also easy to get confuse in code and misunderstand it.

Please if something not clear to you may ask me for more information waiting your replays...

thanks in Advanced ...

If you can spare 3 pins, you can address 8 devices 0-7. Leave the addressing in binary, make yourself a cheat sheet to convert between binary to decimal.

LarryD , thanks for your replay but still need more details [Code and Wiring ] if you can ! Link to the right direction ..

Google is your friend. Here is an example of reading a 4 position dip swich, you can modify it easily to 3 positions. https://gist.github.com/hsiboy/b87b5cde33514a16bc96

One side of the 3 switches goes to 0 volts.

you can easyly use a Shift register. just search on google for "arduino 74hc165 spi" and you can find more then enough examples here like this one

for the code

#define clockPin 13   // For uno it MUST BE! pin 13 SCK
#define dataPin  12   // For uno it MUST BE! pin 12 MISO
#define latchPin  10  // this can be any pin you like

//var so store adress
//use byte to get  binary
//or use int to get decimel

byte or int Adress;

void setup(){
   pinMode(clockPin, OUTPUT);
   pinMode(dataPin, INPUT);
   pinMode(latchPin, OUTPUT);
void loop(){
   digitalWrite(latchPin, HIGH);
   Adress = shiftIn(dataPin, clockPin, LSBFIRST or MSBFIRST);
   digitalWrite(latchPin, LOW;

something like this should work. not tested!

IMO, this addressing should be handled in the EEPROM, not with DIP-switches. DIP-switches are PITA to use unless you have tons of unused pins.

Another approach is to use an analog pin, and have the switches connect one end of a voltage divider through resistors of varying values. There's a lot of information on these forums about doing this for buttons - which is the same thing as dip switches, electrically.

many thanks for everyone replayed !!

something founded here http://playground.arduino.cc/Code/ShiftRegSN74HC165N

and tested was great but still need works to change values to "Decimal" specially its gives the values for each pin high or low with pin # .

still working on it so if someone have idea about what i missed and need , i thanks him in advanced for hes future help

DrAzzy: IMO, this addressing should be handled in the EEPROM, not with DIP-switches. DIP-switches are PITA to use unless you have tons of unused pins.

I second that. Finally each master has to know not only about the addresses, but also what's the purpose and use of every specific client (commands to send, data to retrieve). Thus the bus master program can include both addresses and communication code, while the client programs include their own addresses and function code.

DIP switches are fine for mass production devices, when multiple modules of the same type shall be used in a network, or when other features have to be selectable without reprogramming the module.