Multiple capacitive sensors with Arduino MEGA with Capsense Library

Hey guys,

I am not very experienced with arduinio. Currently working on a project that requires me to hook up 35 capacitive sensors. The idea is there are 35 hanging metal tubes, each of them is hooked up to an arduino MEGA 2560 as a capacitive sensor. When a trigger is detected, the arduino MEGA will send a signal to the WAV trigger (Sparkfun) to make a sound.

Everything works great with 14 sensors. I touch the tube, a sound is made practically immediately. However, the moment I hook up the 15th sensor, things stop to work. I’ve observed that with 15 sensors, I would have to keep my hand on the copper tube for 1-2 for a delayed sound response as opposed to a practically instant response.

If I hook up the 16th tube, nothing works anymore. I suspect it has something to do with the delay I’ve added. I tried taking it out but it stops the whole system from working.

Could this be a problem with a number of sensors I have? If this is the case, I am thinking of getting 2 more arduino MEGA boards so that I have 3 sets of arduinos and sensors to achieve the goal of having 35 sensors that trigger sound.

Much thanks

#include <CapacitiveSensor.h>
#include <AltSoftSerial.h>
#include <wavTrigger.h>

wavTrigger wTrig;                    // Our WAV Trigger object


const int resolution = 30;          // Settings
const long sensitivity = 300;         // Settings
const int debounce = 100;            // Settings


CapacitiveSensor cs[] = {
  CapacitiveSensor(23, 2),
  CapacitiveSensor(23, 3),
  CapacitiveSensor(23, 4),
  CapacitiveSensor(23, 5), 
  CapacitiveSensor(23, 7),
  CapacitiveSensor(23, 8),
  CapacitiveSensor(23, 9),
  CapacitiveSensor(23, 10),
  CapacitiveSensor(23, 11),
  CapacitiveSensor(23, 12),
  CapacitiveSensor(23, 13),
  CapacitiveSensor(23, 24),
  CapacitiveSensor(23, 25),
  CapacitiveSensor(23, 26)

const int NUMBER_OF_SENSORS = 14;
long timeArr[NUMBER_OF_SENSORS];

void setup(){ 

  for (int i = 0; i++; i < NUMBER_OF_SENSORS) {
    timeArr[i] = 0;                                               // Set all sensor timers to 0
    cs[i].set_CS_AutocaL_Millis(0xFFFFFFFF);         // Calibrate Capsense sensors

  wTrig.start();       // start WAV trigger

void loop(){
  for(int i = 0; i < NUMBER_OF_SENSORS; i++){
    long reading = cs[i].capacitiveSensor(resolution);
    if (reading > sensitivity) {

//Sends command to WAV trigger to play a track after checking debounce

void activateSensor(int x){
  if (millis() - timeArr[x] > debounce) {
  timeArr[x] = millis();

Hi tuna,

Reading a capacitive sensor do takes time and you might be running into timing issues within the loop() context due to the number of sensors you have.

Should you have an oscilloscope around and an spare I/O pin, use the I/O pin to flip high and low at the beginning and the end of the cs readout part so you can see if this is the problem.

Should yes, consider reducing the resolution so you can solve it. Alternativelly, consider using an extra arduino for the other sensors so you can balance the processing load and make them communicate to each other so the tunes are sent out.

Seems like it is a trade-off situation.