Schematic & pin reduction

arduinopinoutschematics

I am using arduino Uno for developing my project. There are totally 24 analog hall sensor out put,1 temprature ananlog output, 1 Rshunt voltgae measurement.
There are totally 26 Analog sensor.I am distributing 24 analog channel in 8:1 analog multiplxer usingAnalog Multiplexer; Where it used totally 3 analog ,1 temprature,1 voltage sesnor.

Now @ digital side i need

3 For selecting 8:1 Multiplexer
1 for error status
1 for Blink led
1 for SPD status
1 for disconnector status
2 for MODBUS communication
2 for serial communication
8 Pins for selecting Device ID using DIP Switch totally i need 19~20Pins.
SO i need Method of reducing it. Please look my schematic attached If any alternation i can do here let me Know.And my question here is this method correct , Switch i represented here is dip Switch followed by 1k resistor.

I wanted to How can i configure device ID 255 No,

schematic

simulate this circuit – Schematic created using CircuitLab

Best Answer

Use another multiplexer to read the 8 ID switches, selected by the same 3 bits as the others and with its output going to a single digital I/O pin. That should save 7 pins, leaving 3 spare for other things that you haven't thought of yet.

You could use a digital multiplexer such as MC74HC151 or 74HC251, but it might be cheaper and easier to just use another HCT4051, as then you only need a single pullup resistor on the digital I/O pin, rather than 8 (one per switch) on the multiplexer inputs.