ESP 32 Touch pin issue

With this code in built-in 0example below

// ESP32 Touch Test
// Just test touch pin - Touch0 is T0 which is on GPIO 4.

void setup() {
  Serial.begin(9600);
  delay(1000); // give me time to bring up serial monitor
  Serial.println("ESP32 Touch Test");
}

void loop() {
  Serial.println(touchRead(4));  // get value of Touch 0 pin = GPIO 4
  delay(1000);
}

A connected jumper wire is not giving a single response

Have to touch the point with a hard pressure directly with finger tips and then only it works

Bit injured :frowning:

Just one wire doesn't make an eletric circuit.

Be aware that the value returned by touchRead() does not vary by much

Here I get a value of about 55 when pin 4 is not touched and about 30 when it is touched. Other touch pins, such as pin 2, give a slightly different range of results but the change is relatively small

The ESP32 has 6 pins dedicated to sensing a touch by means of the capacitance changing

See ESP32 Capacitive Touch Sensor Pins with Arduino IDE | Random Nerd Tutorials

Oh . . then how to make it ??

Ya from this same link I am proceeding

I am getting 84 when it is untouched but not getting anything changed after the touch !!!

I have to touch the pin from top side of ESP 32 chip with fingers and the value then reduces

After applying pressure the value reduces more and more !!!

New stuff for me. When touching any single end connected wire any input reacts, when one doesn't want it......
I don't proceed when cookies are demanded..... Thank's anyway,

Don't know whats going on here

Situation is out of control !!

Exactly which ESP32 board do you have ?

ya actually I am using ESP 32 Wroom 38 pin model

and the one given in various link deals with standard 30 pin model

So a bit confusion was there with pin counts

Now its working properly

But this time I want to make the output stable or want to apply state change function

The purpose behind this is to trigger it once on touch
and to trigger it again we need to lift the finger and then have to touch again

Trying for that !!

ll post the code soon as it is not working presently :frowning:

int button = 23;

int counter = 0;
int buttonState = 0;
int lastButtonState = 0;

int currentButtonState = 0;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 10;

const int threshold = 20;
const int touchPin = 4;
int touchValue;

void setup()
{
  // Setup Serial Monitor
  Serial.begin(9600);

}

void loop()
{

  // currentButtonState = digitalRead(button);
  // currentButtonState = digitalRead(threshold);
  // currentButtonState = touchRead(touchPin);
  // currentButtonState = touchRead(touchValue);
  touchValue = touchRead(touchPin);

   if(touchValue < threshold)
   {
    // currentButtonState = digitalRead(touchPin);

  if (currentButtonState != lastButtonState) {
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (currentButtonState != buttonState) {
      buttonState = currentButtonState;

    //   if (buttonState == LOW) 

        if (buttonState == LOW)
        {
        // if (touchValue <= 10)
        // {
        Serial.println("hello");
        delay(5);
        Serial.println("bye");
        // }

        }

    }
  }
  lastButtonState = currentButtonState;

  }

}


Its the code I am working on
Please rectify !!

        if (currentButtonState != lastButtonState)

currentButtonState will never be anything except zero in your sketch because of this line

        // currentButtonState = digitalRead(touchPin);

You seem to have left debouncing code in your sketch but have ignored the fact that you are not using digitalRead()

Yeah I am unable to co relate these variable value inputs with state change functions

Would you please let me know that what should I write in that place ?

You cannot simply replace one line of code and fix your problem because currentButtonState is used in multiple places in your sketch

I would start by taking out all of the code that tries to debounce the input and get a simple version working. Something like this, perhaps

Read the touch input. If the value returned has become smaller than the lower threshold value then the input has become touched. If the value has become more than the upper threshold value then the input has become not touched.

Note that the upper and lower threshold values will not be the same as one another to allow some hysteresis in the system

Try this

const byte touchPin = 4;
const int lowerThreshold = 30;  //adjust these to suit your system
const int upperThreshold = 40;
boolean currentlyTouched = false;

void setup()
{
    Serial.begin(115200);
}

void loop()
{
    int touchValue = touchRead(touchPin);
    //    Serial.println(touchValue);
    if (touchValue < lowerThreshold && currentlyTouched == false)
    {
        Serial.println("pin became touched");
        currentlyTouched = true;
    }
    else if (touchValue > upperThreshold && currentlyTouched == true)
    {
        Serial.println("pin became not touched");
        currentlyTouched = false;
    }
}

O that is a kind of very crystal clear explanation about the basics !!!

Yes that is working !!

What it does when it sayd

currentlyTouched == false

and when it says

currentlyTouched == true

??????

currentlyTouched == false

This will return true if the value of currentlyTouched equals false. It makes sure that the test for the value being below the lower threshold only happens when a touch on the sensor is not currently happening

Note how the value is changed to true if the pin has been touched

Oh it means practically
the '==' applied here to tell that =>

Currently touch value is false or the terminal is untouched
And '=' tells that this above is the true condition of Currently touched

Is it the actual one what I got or some kind of mistake ???????

Please correct my gaining Sir !!