esp32 capacitive touch sensing pins with arduino ide


Learn how to use ESP32 capacitive touch pins using Arduino IDE. We will explain the working of touch-sensing pins with an example.

ESP32 has 10 capacitive-sensing GPIOs, which detect variations induced by touching or approaching the GPIOs with a finger or other objects. The low-noise nature of the design and the high sensitivity of the circuit allows relatively small pads to be used.

Capacitive signal namePin number
T0GPIO4
T1GPIO0
T2GPIO2
T3MTDO
T4MTCK
T5MTDI
T6MTMS
T7GPIO27
T832K-XN
T932K-XP

Applications of Capacitive Touch Sensors

  • Low-power IoT device that wakes up on touch.
  • Touch-activated light control.
  • Low-power remote.
  • Smart switches in home automation.
  • Interactive art installation.
  • gesture control systems.

the touchread() function in Arduino IDe accepts the GPIO pin as an argument and returns a value. The higher value indicates no touch whereas the lower value suggests a touch.

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

void loop()
{
Serial.println(touchRead(T0));
delay(100);
}
const int ledPin = 2;
const int touchPin = T0;
const int touchThresold = 40;

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  delay(1000);
}

void loop()
{
  int touchVal = touchRead(T0));
  if (touchValue < touchThresold ){
    digitalWrite(ledPin, HIGH); // Turn LED on
  }
  else{
    digitalWrite(ledPin, LOW); // Turn LED off
  }
  delay(100);
}

The code reads the input from the touch-pin T0 (GPIO4) and turns on the Led if the touch is detected.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *