ESP32 - Capacitive Touch Sensor Pins
We are going to learn how to use the ESP32 touch pins with Arduino IDE. The ESP32 touch pins can sense variations in anything that holds an electrical charge. They are often used to wake up the ESP32 from deep sleep.
Video Tutorial
you can watch this video tutorial
Hardware Required
1 | × | ESP-WROOM-32 Dev Module | |
1 | × | Micro USB Cable | |
1 | × | Jumper Wires |
ESP32 Code
touchRead()
Reading the touch sensor is straightforward. In the Arduino IDE, you use the touchRead() function, that accepts as argument, the GPIO you want to read.
We’ll program the ESP32 using Arduino IDE, so make sure you have the ESP32 add-on installed before proceeding
Let’s see how that function works by using an example from the library. In the Arduino IDE, go to File > Examples > ESP32 > Touch and open the TouchRead sketch.
// ESP32 Touch Test // Just test touch pin - Touch0 is T0 which is on GPIO 4. void setup() { Serial.begin(115200); 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); }
Code Explanation
-
This example reads the touch pin 0 and displays the results in the Serial Monitor.
-
The T0 pin (touch pin 0), corresponds to GPIO 4, as we’ve seen previously in the pinout.
-
In this code, in the setup(), you start by initializing the Serial Monitor to display the sensor readings.
Serial.begin(115200);
Serial.println(touchRead(4));
Book Tutorial
We are considering to make the book tutorials. If you think the book tutorials are essential, you can download it. download book
References
※ NOTE THAT:
Some components works on 3.3v and others works on 5v!