How to monitor 50 inputs

Hi,
Im about to start a project that requires using an Arduino mega to monitor if 50 switches have been toggled. The project is to create a game that has a screen which will display if all 50 inputs have been pressed and the time taken. And if a switch is skipped the screen should display which switch wasn't pressed. Im wondering what sort of hardware would be required for each switch. The buttons will also light an led confirming its been toggled.

Hello

That hardware design reqiures more than the 50 IO-pins as mentioned.

Is there any way of doing it on an arduino board? The leds are connected to the switches to light.

Take a search engine of you choice and ask the WWW for 'portexpander +arduino'.

I2c port expander chips
Use a small little arduino with a nice form factor for your project unless you need something you haven’t specified

And would you recommend using multiplexers or shift registers

An I2C or SPI display uses 2 more pins. Where's the problem?

For shure.

There more than (n+1) possible solutions.

1 Like

Toggle switches or push-buttons. Which is it?

If it's push-buttons, a 7x8 matrix (15 pins) can handle 56 buttons. One pin for an addressable LED strip. Two pins for an I2C LCD (16x2 or 20x4 characters). That's 18 pins in total. Add two for debug output (Serial) and it can all be done on an UNO or Nano (Classic).

The idea is that a pin will be placed in a hole where the switch is to activate it. So the switch will be constantly on when the pin is inserted

The only way to read 50 switches at the same time is with 50 latches. This is much easier then it sounds. You need parallel in serial out shift registers. I use a 74HC165s without any problems using a nano. I did it with 16 74HC155s and 8 input pins. They were cascaded as 8 - 16 Bit registers. You can arrange any way you want possibl 32 - 4 etc. In your case you will not need as many. Nice part when you latch the data all of them latch at the same time. This is not perfect but the results will be within a few pico seconds.

There is no requirement for reading all the switches at the same time.

The choice of internal ports or port expanders has a big impact on the wiring. Detached registers reduce the wire count to the central processor, at the cost of additional PCB etc. Otherwise PCINT can be used immediately to react quickly on an activated switch, without lengthy polling of external registers.

if i was to use the port expander would i still be able to use a lcd to display results

Yes, why not? It would even use the same Arduino pins. It is just the port expander and the display would have to use a different I2C address.

okay thanks. So theoretically i can use 4 16 port expanders to read each switch. And each switch would have a different address?

No.
Each switch would have a unique way of accessing it, which is not the same thing. I said that the display and the port expenders would have to have different I2C addresses.

In order to have 4 port expanders each port expander needs to be assigned a different address, these are set by wiring the three address pins on each port expander. to a different combination of +5V and ground.

The display, assuming it is also on the I2C bus must have a different address to any one of your port expander.

I think the problem here is that you don't understand the I2C bus or port expanders.
Try reading this:-

Then wire it like this:-

1 Like

thank you so much.

Have you any guidance on when connecting 4 of them?

Should the switch be at the start of the circuit and the input signal after it? Wouldn't voltage potential go down when the switch is closed and the signal would be lost? Then you would be monitoring for the signal to have a positive signal and still have a ground path to prevent the input from floating.
switch circuit