I'm more of a software guy but I'm working on a prototype of a game that will use a pressure sensitive 10 by 10 grid. This will require 100 switches just for the grid. The closest I've found to off the shelf is an Arduino Mega 2560 r3 but it still comes up short by 30 pins. What is the best approach to this? Should I look into getting more gpio pins or is there a better, more efficient way of accomplishing the task of receiviving positional data from a 10x10 grid (think a1,b2,c3 and so on)?

While Googling a bit I came across a method using resistors and analog pins to get input from multiple buttons. The tutorials always seem to use 5 buttons, Is this a limitation of the tutorials or the method? Could the same method be used to string together 10 switches? link to multi button example

  • 2
    \$\begingroup\$ Google 'multiplexing buttons'. The key is to realize that humans can't push buttons very quickly, so you don't need to look at all of them at the same time. \$\endgroup\$
    – Samuel
    Mar 20 '14 at 4:50
  • \$\begingroup\$ I second Samuel, but... this depends on how many simultaneous button presses you need to be able to register. But like he says, google multiplex with switches, or keyboard matrix, that sort of thing to see variations. There's probably code in the Arduino library to do this, see "CustomKeypad" and similar sketches. \$\endgroup\$
    – gwideman
    Mar 20 '14 at 6:55

You could arrange the buttons in an X-Y layout, like in the figure below (which I extracted from this source). That will allow you to use 20 pins (10 for the rows, 10 for the columns) instead of 100.

X-Y keypad arrangement

The polling algorithm is as follows (from the same source):

Continuous Polling Operations

In this mode of operation, the MicroConverter continuously polls the keypad for a key press. This operation is used where the MicroConverter has completed a task and is now waiting for input before proceeding. In this mode, the keypad is connected to one port of the MicroConverter, Port 2 in this example. Figure 3 shows the connectivity. The output from the MicroConverter, following a key press, is viewed using HyperTerminal running on a PC. The MicroConverter is connected to the PC via the COM1 port. This is the reason for showing the RS-232 connection.

As can be seen in Figure 3, the four columns (X1 to X4) are pulled up to VDD and are also connected to four of the MicroConverter port pins (P2.4 to P2.7). The four ADuC8xx rows (Y1 to Y2) are connected to the other four port pins (P2.0 to P2.3). The MicroConverter outputs 0 or drives low the keypad rows (P2.0 to P2.3) one at a time and checks the columns (P2.4 to P2.7) for a low condition.

For example, the following is the sequence of events up to a switch press detection (Switch 5 in this case). The MicroConverter outputs a low on P2.0 (Y1) and checks for a low on P2.4 to P2.7. In this case, no low is found and so it returns P2.0 (Y1) to high and moves on to P2.1 (Y2). The MicroConverter now drives P2.1 (Y2) low and again checks P2.4 to P2.7 for a low condition. This time it finds that P2.5 (X2) is low, due to Switch 5 being pressed. The MicroConverter now knows that the interconnect of Y2 and X2 has been shorted, therefore, this is 5.

But you don't need to implement the algorithm yourself. Instead you can use the Arduino Keypad lib. The links are below:

See this answer if you need to lay down the buttons yourself. It explains how to layout 4 pin buttons on a single-sided board in a way that you don't need to use jumpers. I'm copying the X-Y layout from that question below:

X-Y keypad layout

  • 1
    \$\begingroup\$ Awesome, This exactly what I was looking for! It is a very similar in concept to an LED cube. I'll be making the pad myself but the wiring looks easy enough. I'll test it in scale first. Thanks for the detailed reply! \$\endgroup\$
    – Bms85smb
    Mar 20 '14 at 14:31
  • \$\begingroup\$ Glad I could help. Now that you have enough reputation, please, consider voting my answer up by clicking on the up arrow next to the vote count and the accept button (the green checkmark you clicked) \$\endgroup\$
    – Ricardo
    Mar 20 '14 at 14:42
  • \$\begingroup\$ Incidentally, I'm making na Arduino 32-button remote control myself, so I had to go through this learning curve myself a few days ago. Good thing is that it's all fresh in my head. I'll etch the board tonight and will share the design here with you if it passes the tests. \$\endgroup\$
    – Ricardo
    Mar 20 '14 at 14:46
  • \$\begingroup\$ @Bms85smb - Just tested and I confirm that the Arduino Keypad lib Works perfectly with this setup. \$\endgroup\$
    – Ricardo
    Mar 21 '14 at 3:15
  • \$\begingroup\$ Great! I'm excited to get mine started! \$\endgroup\$
    – Bms85smb
    Mar 21 '14 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.