About Touch sensitivy values

I written a code for esp32s3 for reading touch values i am unable to fix one threshold value for all the touch pins i am getting a touch values like 19587,25534,38654 how can i set one threshould for all the values

int touchpin = 1; // Replace with the desired touch pin
int touchpin1=2;
int touchpin2=3;
int touchpin3=4;
int touchpin4=5;
int touchpin5=6;
int touchpin6=7;
int touchpin7=8;
int touchpin8=9;
int touchpin9=10;
int touchpin10=11;

int ledPin = 42;
int ledPin1 = 41;
int ledPin2 = 40;
int ledPin3= 39;
int ledPin4= 38;
int ledPin5= 37;
int ledPin6= 36;
int ledPin7= 35;
int ledPin8= 34;
int ledPin9= 26;
int ledPin10= 33;

int threshold = 30000;

void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(ledPin1, OUTPUT);
digitalWrite(ledPin1, LOW);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin2, LOW);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin3, LOW);
pinMode(ledPin4, OUTPUT);
digitalWrite(ledPin4, LOW);
pinMode(ledPin5, OUTPUT);
digitalWrite(ledPin5, LOW);
pinMode(ledPin6, OUTPUT);
digitalWrite(ledPin6, LOW);
pinMode(ledPin7, OUTPUT);
digitalWrite(ledPin7, LOW);
pinMode(ledPin8, OUTPUT);
digitalWrite(ledPin8, LOW);
}

void loop() {
int touchValue = touchRead(touchpin);
int touchValue1 = touchRead(touchpin1);
int touchValue2 = touchRead(touchpin2);
int touchValue3 = touchRead(touchpin3);
int touchValue4 = touchRead(touchpin4);
int touchValue5 = touchRead(touchpin5);
int touchValue6 = touchRead(touchpin6);
int touchValue7 = touchRead(touchpin7);
int touchValue8 = touchRead(touchpin8);
Serial.println("TV:");
Serial.println(touchValue);
Serial.println("TV1:");
Serial.println(touchValue1);
Serial.println("TV2:");
Serial.println(touchValue2);
Serial.println("TV3:");
Serial.println(touchValue3);
Serial.println("TV4:");
Serial.println(touchValue4);
Serial.println("TV5:");
Serial.println(touchValue5);
Serial.println("TV6:");
Serial.println(touchValue6);
Serial.println("TV7:");
Serial.println(touchValue7);
Serial.println("TV8:");
Serial.println(touchValue8);
if (touchValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off

}
 if (touchValue1 < threshold) {
  digitalWrite(ledPin1, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin1, LOW);  // Turn LED off
}
 if (touchValue2 < threshold) {
  digitalWrite(ledPin2, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin2, LOW);  // Turn LED off
}
if (touchValue3 < threshold) {
  digitalWrite(ledPin3, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin3, LOW);  // Turn LED off
}
 if (touchValue4 < threshold) {
  digitalWrite(ledPin4, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin4, LOW);  // Turn LED off
}
 if (touchValue5 < threshold) {
  digitalWrite(ledPin5, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin5, LOW);  // Turn LED off
}
if (touchValue6 < threshold) {
  digitalWrite(ledPin6, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin6, LOW);  // Turn LED off
}
if (touchValue < threshold) {
  digitalWrite(ledPin7, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin7, LOW);  // Turn LED off
}
if (touchValue8 < threshold) {
  digitalWrite(ledPin8, HIGH); // Turn LED on
} else {
    digitalWrite(ledPin8, LOW);  // Turn LED off
}
delay(100);

}

As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming category of the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post error messages in code tags as it makes it easier to scroll through them and copy them for examination

Once you’ve sorted that stuff out, look into an ‘array’ of sensors, it will make your code easier to read, maintain and logical…

@dhanalakshmi_4567

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

The usage of touch sensor is quite a complex task. The main reasons are as follows: human touch can be described as a "knock" and is completely different from touch detected by a sensor. Human does it in parts of a second, while ESp32 works with microseconds. This means that ESP32 might detect several touches during one human touch. The second reason - detected values are quite variable and might vary due to several factors. Touch pressure, duration, conductivity of finger etc. Third - ESP32 sensors do not support so-called hysteresis. Or, in other words, sensor does not provide any kind of delay after detection, might detect the opposite event directly after the first one. Fourth - your code is quite simple, but if the loop includes complex code, touch will not be detected in the time when the processor executes this code. But this is not what humans expecting. Expectation is - immediate reaction on touch. Better is to implement touch detection as an interrupt, ideally on second thread..
Regarding your code - it will not work as these factors are not taken into account. Following are my suggestions:

  1. As suggested here -Introduce an array of sensors and loops- it will simplify code;.
  2. Introduce delay after detection (like if you detect "on", wait 1/2 second or smth);
  3. Detect and process the peak, not the single sensor value;
  4. Implement code as an interrupt, ideally on the second thread

At some point, I had developed similar code for "knocks".Like: one knock- do this, two knocks- do that.. Recalling- it was no easy...