Hello!
Recently I began to become very interested in creating my own projects using Arduinos. I decided that I would build a small pressure pad as one of my first projects. I have seen some examples and thought I would give it a try.
I build a 3x3 matrix of brass sheet strips. Between the horizontal and vertical strips I placed two small pieces of Velostat.
I used two 74HC4051 multiplexers to iterate through the horizontal and vertical positions of the matrix. This seems to be a common approach from what I have seen from other tutorials. I plan on expanding this matrix later but a 3x3 seemed to be a good test case.
I wired the breadboard accordingly. The setup is available within the first 2 pictures.
The source code for the Arduino controller is as follows. Understandably it is not yet optimized. At this stage I am looking to get a functioning solution first.
/ Define binary control output pins
#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define S4 6
#define S5 7
int V;
void setup()
{
Serial.begin(9600);
// Set multiplexer controller pins to output
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(S4, OUTPUT);
pinMode(S5, OUTPUT);
}
void loop()
{
// Loop through the 8 possible channels in the multiplexer
for (int i = 0; i <= 2; i++) {
setMultiplexer1(i);
for (int j = 0; j <= 2; j++) {
setMultiplexer2(j);
V = analogRead(A0);
Serial.println(V);
delay(100);
}
}
}
void setMultiplexer1( int i ) {
int s0Value = i & 0x01; // get value of first bit
int s1Value = (i >> 1) & 0x01; // get value of second bit
int s2Value = (i >> 2) & 0x01; // get value of third bit
digitalWrite(S0, s0Value); // turn first pin on or off
digitalWrite(S1, s1Value); // turn second pin on or off
digitalWrite(S2, s2Value); // turn third pin on or off
}
void setMultiplexer2( int i ) {
int s3Value = i & 0x01; // get value of first bit
int s4Value = (i >> 1) & 0x01; // get value of second bit
int s5Value = (i >> 2) & 0x01; // get value of third bit
digitalWrite(S3, s3Value); // turn first pin on or off
digitalWrite(S4, s4Value); // turn second pin on or off
digitalWrite(S5, s5Value); // turn third pin on or off
}
The results I am getting seem to be counter intuitive to me. I seem to receive small, random dips in my measurements but nothing substantial as I press down on the different number positions.
Any clue what I may have missed? Again, I am very new to this so any insights the community can provide are very welcome!
Happy tinkering!