মূল বিষয়বস্তুতে যান
Learn/ESP32 essentials/Touch pins and the DAC
ESP32 essentials · Lesson
8 min read

Touch pins and the DAC

Capacitive touch sensing and true analog output on GPIO25/26.

What You Will Learn

  • Read touch pins
  • Write a voltage with dacWrite()

Ten ESP32 pins (T0–T9) can sense touch: touchRead(T0) returns a number that drops when a finger is near a wire or pad connected to the pin.

Arduino C++
void loop() {
  int v = touchRead(T0);   // T0 = GPIO4
  if (v < 30) Serial.println("touched");
  delay(100);
}

The ESP32 also has two 8-bit DACs on GPIO25 and GPIO26: dacWrite(25, 128) outputs about 1.65 V — a real analog voltage, unlike PWM.

In the simulator, touch pins report 'not touched'. The ESP32-C3 has no touch pins or DAC, and the S3 has touch but no DAC — check the board profile.

Check Your Understanding

Test what you learned in this lesson

1Which pins have the DAC on the classic ESP32?