Pressure sensitive floor

I'm gonna go a bit over my head with this project but it has to be done, so any help would be appreciated. I'm planning to make a project based on this one. I need to make a 8x5 array of 40 squares of velostat sensors. The player needs to go from the bottom to the top of the array in a predetermined path 18 steps + surrounding squares reset the progress which amount to about 30 sensors. Whats the easiest way of accomplishing this? Arduino mega and a digital pin for each of the sensors? They don't need to sensor pressure levels just on/off.

This kind of looks like a 8x5 keyboard matrix. So you could use 8 pins for columns and 5 for rows = 13 pins. Might reduce the number of pins further with shift registers (SPI) or I2C expanders.

Hmmm - sounds like that scene from "Raiders of the Lost Ark" :slight_smile:

gpsmikey:
Hmmm - sounds like that scene from "Raiders of the Lost Ark" :slight_smile:

Something similar but less dangerous as there are no chasms in the plan; yet.

groundfungus:
This kind of looks like a 8x5 keyboard matrix. So you could use 8 pins for columns and 5 for rows = 13 pins. Might reduce the number of pins further with shift registers (SPI) or I2C expanders.

I already have a mega i thought of using for this, so number of pins are not a major problem unless this simplifies the project. The author of that project used nanos and 8 analog pins for 8 sensor pads for detecting pressure levels which i don't need. There is a fritzing breadboard schematic at the bottom of that page i'm trying to figure out.

Where do I start with coding this?

So, I found instructable for O-Mat which is basically the thing I am making but much smaller in size. Instead of making many individual sensors they have a 15x15 matrix grid for a promini and multiplexers. There is a code for this project. Could I use it as a starting point for my thing?

//Mux control pins for analog signal (SIG_pin) default for arduino mini pro
const byte s0 = 13;
const byte s1 = 12;
const byte s2 = 11;
const byte s3 = 10;

//Mux control pins for Output signal (OUT_pin) default for arduino mini pro
const byte w0 = 9; 
const byte w1 = 8;
const byte w2 = 7;
const byte w3 = 6;

//Mux in "SIG" pin default for arduino mini pro 
const byte SIG_pin = 0; 

//Mux out "SIG" pin default for arduino mini pro
const byte OUT_pin = 5;

//Row and Column pins default for arduino mini pro
const byte STATUS_pin = 3;
const byte COL_pin = 2;

const boolean muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };


//incoming serial byte
int inByte = 0;

int valor = 0;               //variable for sending bytes to processing
int calibra[15][15];         //Calibration array for the min values of each od the 225 sensors.
int minsensor=254;          //Variable for staring the min array
int multiplier = 254;
int pastmatrix[15][15];

void setup(){
    
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  
  pinMode(w0, OUTPUT); 
  pinMode(w1, OUTPUT); 
  pinMode(w2, OUTPUT); 
  pinMode(w3, OUTPUT); 
  
  pinMode(OUT_pin, OUTPUT); 
  
  pinMode(STATUS_pin, OUTPUT);
  pinMode(COL_pin, OUTPUT);

  
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  
  digitalWrite(w0, LOW);
  digitalWrite(w1, LOW);
  digitalWrite(w2, LOW);
  digitalWrite(w3, LOW);
  
  digitalWrite(OUT_pin, HIGH);
  digitalWrite(STATUS_pin, HIGH);
  digitalWrite(COL_pin, HIGH);
  
 
  
  Serial.begin(115200);
  
  Serial.println("\n\Calibrating...\n");
  
  // Full of 0's of initial matrix
  for(byte j = 0; j < 15; j ++){ 
    writeMux(j);
    for(byte i = 0; i < 15; i ++)
      calibra[j][i] = 0;
  }
  
  // Calibration
  for(byte k = 0; k < 50; k++){  
    for(byte j = 0; j < 15; j ++){ 
      writeMux(j);
      for(byte i = 0; i < 15; i ++)
        calibra[j][i] = calibra[j][i] + readMux(i);
    }
  }
  
  //Print averages
  for(byte j = 0; j < 15; j ++){ 
    writeMux(j);
    for(byte i = 0; i < 15; i ++){
      calibra[j][i] = calibra[j][i]/50;
      if(calibra[j][i] < minsensor)
        minsensor = calibra[j][i];
      Serial.print(calibra[j][i]);
      Serial.print("\t");
    }
  Serial.println(); 
  }
  
  Serial.println();
  Serial.print("Minimum Value: ");
  Serial.println(minsensor);
  Serial.println();
  
  establishContact();
 
  digitalWrite(COL_pin, LOW);
}


void loop(){
  //Loop through and read all 16 values
  //Reports back Value at channel 6 is: 346
  if (Serial.available() > 0){
    inByte = Serial.read();
    
    if(inByte == 'A'){
    
      for(int j = 14; j >= 0; j--){ 
        writeMux(j);
        
        for(int i = 0; i < 15; i++){
            
          valor = readMux(i);
          
          //Saturation sensors
          int limsup = 450;
          if(valor > limsup)
            valor = limsup;
            
          if(valor < calibra[j][i])
            valor = calibra[j][i];  
          
          valor = map(valor,minsensor, limsup,1,254); 
          
          if(valor < 150)
            valor = 0;
          if(valor > 254)
            valor = 254;
          
          Serial.write(valor);
          digitalWrite(COL_pin,!digitalRead(COL_pin));
        } 
      }
    }
        
  }
}


int readMux(byte channel){
  byte controlPin[] = {s0, s1, s2, s3};

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}

void writeMux(byte channel){
  byte controlPin[] = {w0, w1, w2, w3};

  //loop through the 4 sig
  for(byte i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A');   // send a capital A
    delay(300);
  }
}