"drawing" panel with leds, assistance requested.

Hi... I'm a student, pretty new to Arduino. Trying to work on a project and was wondering about feasibility/best route to take.

I'm trying to build two grids, lets say 20x20, one of momentary buttons and one of LEDs, which correspond to each other (button at 0,0 on panel 1 lights up LED at 0,0 on panel 2). I'd like the two panels to be able to communicate wirelessly, and for the leds to remain on for a few seconds after the button is pressed and then turn off, so it's possible to write with your hand on the buttons and have it be readable on the other panel. I'm not sure what the best avenue is as far as getting all the buttons into one arduino and all the leds into another one, and have them able to communicate wirelessly (through Xbee or something). If anyone has any input, that would be great. If I'm missing information, please let me know. Thanks a lot.


Sure, very feasible. With regular arduino you get 20 IO, and you'd 2 for the wireless part. Easy way around that is to multiplex/demuliplex. Use multiplexing to read the state of 8 buttons on one input pin. Use demultiplexing to control the state of 8 LEDs from one output pin. (or use bigger chip like ATMega324/644/1284 (40 pin DIP, different memory sizes). Can wire up standalone circuit very easily, use part like FTDI Basic to download sketches into it. Have 32 IO to use then. Still need two for RF Rx/Tx. Use 434 MHz RF Tx & Rx module to send button state from one arduino to the other.

Great! thanks for responding. So for the multiplexer chips, would one like this work? http://search.digikey.com/us/en/products/74HC4051N,652/568-1455-5-ND/763059

I assume I'm going to need to hook a bunch up in sequence. My teacher implied that each one would have four of its inputs hooked up to the next chip in the sequence, leaving only 4 pins per chip to control the buttons. But he said he hadn't done it in a long time, so he wasn't sure. Is that the case? Anyone sequenced a bunch of multiplexers/demultiplexers together? Would it be advantageous for me to use 16 channel multiplexers, or would I need to hook up extra pins to the next one in the sequence, thus canceling out the extra pins? Thanks in advance for any response.


"hook a bunch up in sequence" "four of its inputs hooked up to the next chip in the sequence"

The 4051 is not really set up for that. Since you are dealing with all digital signals, I would suggest parts that are made for TTL levels. On the input side, use a Parallel to Serial shift register; the 8 inputs will have a 10K pullup resistor to +5, the button when pressed will connect the input to ground. You will send out a Parallel Load signal (the data latch in line) to sample the state of the buttons at a high rate, and then use 3 SPI transfers to bring those three bytes in to send to the other processor. The output of 1 goes to the input of 2, the output of 2 goes to the input of 3, the output of 3 goes to the Arduino's MISO line. All will have the SCK and Load Signal in parallel. The transmit side can be made smart and only send out the three bytes when something changes. The rate at which you sample will determine the responsiveness of the system. Reading the state of the buttons every 50 mS (20 times a second) would probably be sufficient.

On the output side, receive the data. The receiver will do whatever processing is needed for the delayed turn off. Keep track of the state of each LED for delayed-of status. Use 3 SPI transfers to send the data out to Serial to Parallel shift registers from the Arduino's MOSI line. The output of 1 goes to the input of 2, the output of 2 goes to the input of 3. All will have the SCK and Output register Load Signal in parallel (74HC595 type part here).

Does this make sense? I can post a schematic when I get home. Really is just 3 shift registers, and the 3 control lines for each end.

It's definitely beginning to make sense, although there are new concepts. Thank you for all your help so far. And yes, I would love the schematic if you have time.

Your advice, in conjunction with http://bildr.org/2011/02/74hc595/ is simplifying this a lot for me. So using the 74HC595, it's as simple as controlling 8 buttons/LEDs per chip and continuously hooking them up to each other, QH' to SER, until I've reached my desired number? You said it would be three shift registers for either end. I'm not sure if that's just an example number, or if three is the maximum allowed, or if three is sufficient to control a 20x20 grid. Currently I am under the impression that it would take 50 shift registers to control 400 buttons, and 50 more for 400 LEDs. Am I missing something?

Thanks again! Geoff

Okay, the 74HC595 is output only, you need a different part for the shift it. I wasn't thinking 20x20 array, but that's doable too.

For the LED array, I just posted an 8x8 matrix last night, search for "simple 8x8 matrix" you will arrange 3 shift registers to drive anodes, and 3 shift registers & high current drivers for the cathodes, and multiplex them. With all cathode drivers off, set up the anodes for row 1, turn the row 1 cathode driver on, then off. Set up anodes for row 2, turn row 2 cathode drive on, off. Since 20 LEDs can need up to 400mA per row if you max brightness, a part like ULN2803 http://www.ti.com/product/uln2803a is needed to sink all the current from the anodes. Or a combination shift register/current driver like tcip6595 http://www.ti.com/lit/ds/symlink/tpic6595.pdf or 20 discrete transistors.

For the buttons, You need to make a similar array. I have to think on this one a little to make sure I get the isolation between rows correct, so this might change. Along one edge you will have 74HC595 with their outputs going thru a diode to one side of a button, button connected to the anode. All buttons in a row will have one side connected to the diode. Down the column, the other side of the button will feed into a shift in register. Each column has a pullup resistor. All rows will start high, with no buttons pressed the shift in register will read all 1s. Take Row 1 diode cathode low, read the shift register. Any pressed buttons will read as 0. Do SPI transfer to read the 3 bytes in. (might need ULN2803 as the current sink, depends on what you use for pullup resistors - 20K pullups should be okay with 74HC595) Take Row 1 back, take the next row low, read again.

I'll draw this also, or a part of it anyway.

As discussed, expand out to 20x20 using shift registers.

thank you so much for the pictures. these are really helpful. So what you are saying is that I need two different types of shift registers for the two panels? is that the parallel-in, serial out for the buttons, and serial in, parallel out (like the 74HC59) for the LEDs? and then, for the LED side, I need to run all the anodes through the uln2803, which is just a chip containing 8 transistors. For the buttons, I need diodes between each pin of the 74HC59 and the switches, all of them have 20k resistors going to 5v. Dumb question: The X1, X2, X3, etc and the Y1, Y2, Y3 etc in the diagram are corresponding to the pins of different shift register chips? I'm a bit confused as to where the 3 shift registers for each side (anode/cathode) are used. The diagram makes it seem like only two chips are needed for each 8x8 matrix. Sorry just trying to make absolutely certain before I begin to order parts.

Again, thank you so much.

I think you are getting the idea. I only drew up 8x8 because it is hard to see more on a screen. To go to 20 x 20 you just more of the same in each direction. The X1, X2, ... Y1, Y2, ... are the inputs & output of the shift registers/ULN2803s, etc.

Yes, two chips for an 8x8. For a 20x20 (24x24) then three are needed on each side.

That switch matrix will work as long as only one or two buttons are pressed at a time. If you press 3 buttons such that two of them are in the same column and two are in the same row, then you will get a phantom fourth button press to complete the square.

I generally use one diode per push button, so that it works however many buttons are pressed. But that's a lot of diodes for a 20x20 matrix.

So you think a diode per button going to the X pins then? Already have 40 buttons, wouldn't seem that big a deal to have 40 matching diodes. Especially if a PCB is made.