Close

Visual spaghetti for circuit geeks, or...

A project log for 36 Touch Sensor Matrix

“These aren't the duinos you're looking for. You can go about your business. Move along.”

frankstripodfrankstripod 06/07/2014 at 10:100 Comments

Its a 4 x 5 matrix of nine pin inputs to make 20 touch sensor “keys” (see table). Each key on the breadboard (noted in red) is made up of two wires so close together that it is impossible to unconsciously touch only one. It could be inspiration for a project that requires many other input and outputs, has limited space, and also needs a protected touch pad; like a CNC machine for hamsters.

 Touch Sensor Matrix:

Pin# 1 2 3 4
5 A B C D
6 E F G H
7 I J K L
8 M N O P
9 Q R S T
Key Combo Key Combo
A 1 5 T 4 9
B 2 5 S 3 9
C 3 5 R 2 9
D 4 5 Q 1 9
E 1 6 P 4 8
F 2 6 O 3 8
G 3 6 N 2 8
H 4 6 M 1 8
I 1 7 L 4 7
J 2 7 K 3 7
Board Layout
Pinouts Matrix# Pinouts Matrix#
0 1
1 2
. . 23 9
. . 22 8
. . 21 .
. . 20 .
. . 19 7
. . 18 6
. . 17 5
. . 16 4
. . 15 3

Sorry the video is terrible; I'm still waiting to be rich so I can get better video equipment. I have been praying for my ship to come in, but just recently realized that I'm landlocked :(

Sketchy code:

I gave up on my original “easy to follow” code because it got frustrating. I started over out of anger to brute force it, and the main loop came out all at once as one line. If you squint hard and tilt your head to the right, (when spaced correctly in an editor) the shape of the main loop looks like the mountain skyline where I live and I wonder if this is a repressed Freudian sketch to some other problem.

Voids warranties:

/* Touch Sensor Matrix Test on Teensy 3.1
Top 9 touch sensor pins, no bottom solder pads.
4x5 matrix, 5 row 4 column = 20 touch key combinations.
*/
const int pins = 9, across = 4, down = 5;
int touchPin[pins] = {0, 1, 15, 16, 17, 18, 19, 22, 23};
int read1[pins], base[pins];
char touchKeyValue[20] =
   {'A', 'B', 'C', 'D',
   'E', 'F', 'G', 'H',
   'I', 'J', 'K', 'L',
   'M', 'N', 'O', 'P',
   'Q', 'R', 'S', 'T'};
boolean touched = false;
int sensitivity = 140;
int column, row, c;

void setup() {
   Serial.begin(38400);
   for (int c=0; c<pins; c++) {
     base[c]=touchRead(touchPin[c]); // Baseline calibration
   }
}

void loop() {
  touched = false;
  for (c=0; c<pins; c++) {
     read1[c] = touchRead(touchPin[c]);
       if (read1[c]-base[c] < sensitivity) {
         touched = true;
       }
  }
  if (touched) {
    for (column = 0; column < across; column++) {
      if (read1[column] - base[column] > sensitivity) {
      delay(40);
      for (row = 0; row < down; row++) {
        if (read1[row+across] - base[row+across] > sensitivity) {
          Serial.print(touchKeyValue[row * across + column]);
          Serial.println(" Pressed");
          while (touched) {
            read1[column] = touchRead(touchPin[column]);
            read1[row+across] = touchRead(touchPin[row+across]);
            if (read1[column] - base[column] < sensitivity && read1[row+across] -          base[row+across] < sensitivity) {
              Serial.print(touchKeyValue[row * across + column]);
              Serial.println(" Released");
              delay(40);
              touched = false;
            }
          }
        }
      }
    }
  }
}
}

Discussions