Connecting 28 "devices" to a single Arduino

Hi there!

I am starting a new project and it requires:

  • 8 leds
  • 8 push buttons
  • 8 relays
  • 3 digital (RX485) I/O
  • 1 on-board debug led

connected to a single Arduino (micro) board.

I've been thinking of connecting the 8 leds in a 3x3 matrix and save 2 pins.

Also I've been thinking of pairing a series resitor of different value with every push button, then i should be able to measure the resulting resistance using only one analog pin even when multiple buttons are pressed simultaneously.

I then should be down to 21 pins… still too many.

Is there a better/smarter way of doing this?

One analogue pin to read the push buttons as you have suggested, and a shift register each for the LEDs and relays would also cut the pin count

What's "RX485"? If you mean RS-485, a controller with multiple serial devices is almost inevitable. Get a Mega and be happy without any tricks.

options, lots of options

RS-485 relay board. move all relays off the micro onto the existing RS-485 bus.
SPI Shift register
I2C port expander - MCP23017 for 16 pins or PCF8574 for 8 pins

I2C relay board

DrDiettrich:
What's "RX485"? If you mean RS-485, a controller with multiple serial devices is almost inevitable. Get a Mega and be happy without any tricks.

Yep, it's RS-485, sorry. I do not need any serial to drive it. The Mega seems to be a bit of an overkill.

Thanks for all your suggestions!

So, in the end, i think i will connect the push buttons with resistors and use two 74HC595N shift registers one for the leds and one for the relays.

(I will also add one KSP2222 per led, since 74HC595N can't handle enough current (15mA each); the relay board has its own transistors/optocouplers).

DaRkBoDoM:
Yep, it's RS-485, sorry. I do not need any serial to drive it. The Mega seems to be a bit of an overkill.

I believe you do. So 3x software serial pairs if not a Mega's hardware serials.

DaRkBoDoM:
Thanks for all your suggestions!

So, in the end, i think i will connect the push buttons with resistors and use two 74HC595N shift registers one for the leds and one for the relays.

(I will also add one KSP2222 per led, since 74HC595N can't handle enough current (15mA each); the relay board has its own transistors/optocouplers).

most red/yellow/green LED's can be driven with 10-15mA
watch some youtube vids of the shift register.
there are also higher power shift registers. TPIC6B595

Seems strange but maybe the RS485 is used for its voltage outputs and not for serial? Very weird.

Or look at a Teensy3.2 board. Smaller than a Micro, 3 hardware Serial and more pins (if you don't mind soldering pins onto the pads on the bottom side.)

I like adressable LEDs. Only 1 pin (instead of 2 for a shift register), nearly unlimited number of LEDs and you can control the color in software. You might want to change your yellow LED to pink in the next version.

dave-in-nj:
most red/yellow/green LED's can be driven with 10-15mA
watch some youtube vids of the shift register.
there are also higher power shift registers. TPIC6B595

Yep, it's ~20mA * 8 ≈ 200mA but looks like TPIC6B595 can only drive 70mA. Thanks for the TPIC6B595: i'll go for it.

I do not need hardware serial: my RS485 code is working nicely without it.
Addressable leds are a very nice suggestion, but my leds are built inside the push buttons and i have to stick with them.