Help with connecting lots of stuff

My project requires:

18 pots
40 buttons
16 LEDs

I need to be able to control each of LED individually. Now, I thought of multiplexing 16 pots using 4067 mux, and then connecting other 2 to analog pins. Regarding buttons, can I link more than 2 CD4021BE? That would require me do link 5 of them but I'm feeling there's a simpler solution that that. Is it better to multiplex them aswell or use shift registers?

I don't really have an idea how to control those LEDs.

Help is appreciated.

You can use shiftregister for both the buttons and the LED's, if all you need is to turn the LED's on/off.

If you need to fade the LED's it's another story

So there is no limit on shift registers? If I connect 5 of them, they still use only 3 pins on Arduino? And yes, only on/off is required.

Clock line
Serial data out
Serial data in
output latch
input latch

So 5 lines total.
The latch can be shared, so 4.
The serial data line can be shared if you had an output enable on the shift-in registers - but that's another control line, so might as well just have seperate data in & data out lines.

If you need faster access, can use SPI for a hardware shift-in (MISO) and shift-out (MOSI). Use SS for the two shift registers the input latch signal and the output latch signal for parts like 74HC595.

For the pots, you of course need some analog mux or analog switch parts. TI and Maxim I think both make 8:1 parts, and I think 16:1 also.

CrossRoads:
Clock line
Serial data out
Serial data in
output latch
input latch

So 5 lines total.
The latch can be shared, so 4.

Thanks for help.

CrossRoads:
If you need faster access, can use SPI for a hardware shift-in (MISO) and shift-out (MOSI). Use SS for the two shift registers the input latch signal and the output latch signal for parts like 74HC595.

I'm still quite a newbie at electronics so I don't understand this part at all.

CrossRoads:
For the pots, you of course need some analog mux or analog switch parts. TI and Maxim I think both make 8:1 parts, and I think 16:1 also.

Yeah, 4067 has 16 channels. One more question, CD4021BE can be used as both input and output or I need different register for output (the LEDs)?

shiftin() and shiftout() commands do something ike this under software control:
set the state of the bit go out
toggle the output clock bit
repeat 7 more times for the next 7 bits
latch the data into the shift register's output latch (on 74HC595 for example)

SPI does the same but had dedicated hardware to do it.
So one just writes the data into the hardware shift register, and 8 clock cycles later it is all shifted out. Much quicker.
and then data into the shift register's output latch, that is the same.

Same for incoming. Dedicated hardware to shift the bits in, vs a string of software commands to control the clock 8 times to read the input bit 8 times, and put the bits back into a byte.

So it doesn't matter whether I use 74HC595 or CD4021BE? They can both do same thing?

And BTW, what's SPI?

If you don't want to use serial shifting, you could use parallel latching multiplex chips.

You might find an IO expander shield exists that can do a lot of this and save you some effort.

MarkT:
You might find an IO expander shield exists that can do a lot of this and save you some effort.

I was looking at Centipede Shield but toghether with shipping it would cost me more than Arduino board.

So can someone answer me, what's the main difference (if there is any) between 74HC595 or CD4021BE?

4000 series chips are slow (clock upto 2MHz or so) and can't source or sink even 1mA without sagging from a 5V supply. They will work from 3V to 18V though (and perform better at higher voltages)

74HC series work from 2V to 6V, are much faster (can clock at 20MHz or so), can source/sink several mA. They are the modern choice unless you need the higher supply voltage ability - also likely to be cheaper.

I haven't checked but the precise details of driving them are probably different too.

Read this for SPI, or see the ATMega data sheet.