Capacitivesensor Library: how to activate sensor more than 1 individually?

I wanted to make two capacitive sensors that work individually, in one board.
The problem is that the sensors don't work individually, but commutatively!

Here's the codes and the diagram for understanding.

#include <CapacitiveSensor.h>
CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);
CapacitiveSensor   cs_12_13 = CapacitiveSensor(6,2);


void setup() {

  cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); 
  cs_12_13.set_CS_AutocaL_Millis(0xFFFFFFFF); 
   Serial.begin(9600);
    
}

void loop() {
  long start = millis();
  long total1 =  cs_4_2.capacitiveSensor(30);
  long total2 =  cs_12_13.capacitiveSensor(30);
 Serial.println(millis() - start);        
    Serial.print("\t");                   

    Serial.println(total1); 
    Serial.print("\t");  
     Serial.println(total2); 
    delay(20);
}

(The pushbutton part is the sensor I connected.)
If I touch sensor 1(D13,D12), the sensors don't work, it seems that the sensors don't work, and always '-2' is checked on sensor 1. Both numbers get lower.
If I touch sensor 2(D4,D2), the sensors work too actively, compared to when I only connected one sensor.

I don't know whether it's a matter of the circuit or the codes...

Your topic does not indicate a problem with IDE 2.x and hence has been moved to a more suitable location on the forum.

OK, I moved it to general guidance!

Well in my book it is the hardware, but then I have not examined the software in any detail.

You need to extend the ground to surround the sensors in order for it to work. Self adhesive copper foil is something I use a lot for this. Yes there will be cross talk as it is called using this technique anyway.

I just solved the problem! I wrote the wrong PIN number in Sensor 1. As I upload new code, the sensor worked well. Btw thanks for advice, since the sensor still is too sensitive... I guess I have to try what you commented.,

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.