connect multiple input/output arduino

Hello, I hope i can get some guidence for my project, I've done some ardruino projects before but still learning.

I am working on "response time board game" for my school, It is basicaly a board with multiple LED switches that are turned on randomly and the students have to quicly turn the Led lamp off, by clicking the button, as soon as it is on, the response time is measured every time.

I have in total 52 Push button LED ( 5V ) , that would make it 104 inputs. I am not sure what is the best way to control all these LED/Buttons together.

I already have some HC595 and HC4051 and also TCA9548A.

I am not really sure, what components will work best, or how to combine them, also how to redress the the debouncing issue when multiplexing / daisychaning.

Please any suggestion how i can proceed. Thanks

The TCA9548A is a I2C switch so has nothing to do with reading inputs :wink:

You could use port expanders but shift registers will definitely work as well :slight_smile: And even multiplexing can work. 16 pins for a 8x8 matrix which would be able to do 64 buttons and switches even.

We humans are pretty slow anyway so I would say a resolution of 100ms is already more than sufficient which all solutions can do.

Don't think debounce is a real issue because you just act on the first change. After which you restart the "game" or if it automatically continues, just only start reading buttons after you turn on the next led.

Thank you, i see what do you mean, so as i understood, i could do it either :

1 - Multiplexing : 11x10 matrix, mixing LEDs and buttons in the samme matrix. And control the matrix by HC595 ? ( i thought that the 595 was not good for inputs only for outputs and the 4051 us used in sted ? )

2- shiftregister : using a daisychain of HC595 to control LED's and another daisychain of HC165 to control the Buttons and the conbining a shiftin with shiftout ?

is it somehow, the way you mean ?

  1. You could. To make a matrix with shift registers you need drivers (for example HC595) on both side for the leds, but in the button side you need a driver (eg hc595) on one side and an input (eg hc165) on the other side.

  2. That could work yeah. Thing is, there is more than one way to Rome. Some ware easier in hardware (connections) and some easier in software. Because I think you can even use a matrix of a button and a led parallel. But it will be harder in software (and a pressed button will blank the led).

Downside with buttons in a matrix, if you don't add diodes you will get ghosting if multiple buttons are pressed.

I think I would just go for a modulate design. Make a PCB with 1 hc595 an 1 hc165 which can control 8 button led pairs and just make them daisychain-able.

OK, first you need to cite what these buttons are. Are they in fact, a momentary button with a separately connected LED and does that LED have a current limit resistor incorporated for a specific voltage?

To drive a matrix of up to 64 basic LEDs, you use a MAX7219. The code will take care of the correspondence between LEDs and buttons, however you wire it.

Just buy two or three of these kits:

Or these ones

which used to be more expensive but are now actually cheaper and more useful if you wish to stack matrix arrays.

The point is that you do not install the matrix arrays from the kits themselves - or their socket pins, but just solder to the positions on the PCB and you have a durable and reliable assembly to drive your own matrix arrays.

Why did I say two or three? Well, you can fully assemble the first one as the matrix with which it comes and practice programming it. Then the second one for your current project and the third one - for the next! :grinning:


OK, LEDs should not be a problem.

Buttons? They are momentary then? OK, decide whether there is a possibility of more than two being pressed at once. If so, you need a diode in series with every button in the matrix.

You have HC595s? OK, one of those will drive eight outputs to scan the matrix (you will need diodes either one per output or one for every button, in case of multiple presses shorting two outputs). Seven Arduino inputs will read the matrix, using INPUT_PULLUP as the HC595s pull down to scan.

stregoi:
I have in total 52 Push button LED ( 5V ) , that would make it 104 inputs. I am not sure what is the best way to control all these LED/Buttons together.

Slight error in description there - 52 inputs and 52 outputs. But why actually 52? Upper and lower case?

In what arrangement? Interesting point - if they were in a neat matrix, using a MAX7219, you could use them to scroll text across for your results using the "Parola" library.

Debouncing code is easy, if you get the other matters sorted.

Thanks for the reply. This is my setup :

I have this board with 52 momentary LED switches, organized in a serie of 4-5 cirkles ( 8 + 8 + 16 + 16 + 4 LEDS ).
The led's will light randomly across the board, and the corresponding switch should be hit as quickly as possible ( only one click ).

i prefer to use the components laying around, rather than buying something new. so i do have some 74Hc595, and some 4051 and 74 HC165 and TLC5940 and i am using an arduino.

based on the responses, i am thinking to go with the hc595 for the LED's and HC165 for the Switches.

i am thinking that doing a matrix of 52 inputs and 52 outputs and shifting it though will make some delay ??

so may be it is better to do it in modules, so i can better control in which circle the LED is tuned on.
so :
1 circle : 8 inputs ( hc 165 ) + 8 outputs ( hc 595 )
2 circle : 8 inputs ( hc 165 ) + 8 outputs ( hc 595 )
3 circle : 16 inputs ( hc 165 ) + 16 ( outputs ( hc 595 ) .. 4x4 matrix each
4 circle : 16 inputs ( hc 165 ) + 16 ( outputs ( hc 595 ) .. 4x4 matrix each
5 circle : 2 inputs + 2 outputs

and then connect alle module together, multiplexing ? shifing ? i am not sure how to do it ?

that it sounds like a good setup ?

setup.jpg

stregoi:
i am thinking that doing a matrix of 52 inputs and 52 outputs and shifting it though will make some delay ??

Yes, it might take a measurable part of a millisecond. :astonished:

If you connect shift registers to SPI bus, you won't be able to notice any delay in processing the lot. SPI default rate is 512K bytes/sec. You can slow that down by 4 and still be faster than eyes.

More, SPI is bi-directional. If you chain input registers after outputs on the same chain you can read the inputs in the same cycles as you write outputs, the bits you send in one end push bits out the other. The byte put in the SPI register sends a bit out MOSI and replaces it with the bit on MISO, write and read 52 bytes does the whole chain.

A button matrix will need 1 diode for every switch if 2 or more switches might be pressed at the same time. Making the registers support matrix operations is going to complicate your code something wicked.

There will be a lot of wires and soldering for so many components.

GoForSmoke:
A button matrix will need 1 diode for every switch if 2 or more switches might be pressed at the same time. Making the registers support matrix operations is going to complicate your code something wicked.

There will be a lot of wires and soldering for so many components.

Not as bad as using individual connections for 52 of each!

Every switch and led has 2 wires. Every matrix switch needs a diode. Every led needs a resistor.

I'd go with 7 output regs and 7 input regs in a single chain. All of the output regs assemble the same, dit for input regs, easier to make. Switches would not need diodes and the code would be 1 step closer to beginner.

Ah okay i see The delay is almost no existant !

i' am going with shift registers, 74hc165 for the inputs, and 74hc595 for outputs. i will chain them all together and then connect them to Arduino.

My schematics is as you see uploaded here.

https://drive.google.com/file/d/1y4w2I128eRqDdTbMAplrzzIhPJudtV-5/view

I just ordered some hc165, as soon as i get them, i will start coding.

Hold on with ordering!

With 74hc595 you have chip total VCC-GND 70mA maximum total for 8 pins. If you limit the leds to 8 mA each (still bright) with resistors then the leds will light the same no matter how many get lit. If you want more, use transistors and an external power line as well as even more resistors -or- get led-driver shift register chips made to use with RBG displays. You got options.