Capacitive touch sensors, wave shield and relays

Hello. I am somewhat new to electronics, coding and microcontrollers so forgive me if I say something out of the way.

My project is I’m trying to set up a puzzle for an escape room. Players would have to touch four different wall sconces, each producing a different sound via the wave shield from adafruit that I have stacked on my arduino uno. They do this through a capacitive touch sensor connected to each sconce. There is also a relay connected that will, after all four are touched, open a doorway elsewhere.

I have seperated the wall sconce frames from grounding so as not to cause issues. The wires connected to each sconce then travels up into the drop ceiling and to the center of the room where the arduino/wave shield are located in the ceiling. The coding that I have below works well when the jumper wires are a few inches long each. When I ran the longer wires I started have intermittent successful touches and sometimes touching one sconce would play a sound designated for a different sconce. Any ideas or help would be greatly appreciated.

Bruce

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#define motor 9

SdReader card; 
FatVolume vol;   
FatReader root;   
FatReader f;     
WaveHC wave;      
short int testpin=8;
short int b,c,d,e;

int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  byte i;
  pinMode(testpin,OUTPUT);
  digitalWrite(testpin,LOW);
  Serial.begin(9600);
  Serial.println(freeRam());      
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(motor, OUTPUT);
  digitalWrite(motor,LOW);
  if (!card.init()) {          
    sdErrorCheck();
    while(1);                            
  }
  
  card.partialBlockRead(true);
 
  uint8_t part;
  for (part = 0; part < 5; part++) {    
    if (vol.init(card, part)) 
      break;                          
  }
  if (part == 5) {                      
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();     
    while(1);                      
  }
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);    
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!");
    while(1);                         
  }
  putstring_nl("Ready!");
  
 /* TCCR2A = 0;
  TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;

  //Timer2 Overflow Interrupt Enable
  TIMSK2 |= 1<<TOIE2;


}

SIGNAL(TIMER2_OVF_vect) {
  check_switches();
}

void check_switches()
{
 */
}


void loop() {

  byte i;

 
  if (readcap(2)==1) {
    playfile("SOUND1.WAV");
    while (wave.isplaying) {}
    wave.stop(); 
    digitalWrite(9,HIGH);
    delay(2500); 
    digitalWrite(9,LOW);
    delay(2500);
  }
 
  if (readcap(3)==1) {
    playfile("SOUND2.WAV");
    while (wave.isplaying) {}
    wave.stop();    
    digitalWrite(9,HIGH);
    delay(2500);
        digitalWrite(9,LOW);
    delay(2500);
  }

  
  if (readcap(4)==1) {
    playfile("SOUND3.WAV");
    while (wave.isplaying) {}
    wave.stop();    
    digitalWrite(9,HIGH);
  delay(2500);
      digitalWrite(9,LOW);
    delay(2500);
    }

  
  if (readcap(5)==1) {
    playfile("SOUND4.WAV");
    while (wave.isplaying) {}
    wave.stop();    
    digitalWrite(9,HIGH);
  delay(2500);
      digitalWrite(9,LOW);
    delay(2500);
    }

  
  }

short int readcap(short int selec)
{
  digitalWrite(testpin,HIGH);
  for(short int a=0;a<10;a++)
  {
    digitalWrite(testpin,HIGH);
    b =analogRead(selec);
    digitalWrite(testpin,LOW);
    delay(10);
  
  }
  if (b<60)
  return 1;
  else
  return 0;
}



void playfile(char *name) {
  if (wave.isplaying) {
    wave.stop(); 
  }
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  wave.play();
}

Basically you can't do capacitive touch sensing on the end of long wires. The wires introduce too much stray capacitance and pick up too much noise.

You could try with shielded cables, but if it were me I would use the stand alone touch sensors that Adafruit sell and communicate back to the Arduino just the digital data from the sensor.