Arduino Nano ESP32 - Touch Sensor
This tutorial provides instructions on how to use Arduino Nano ESP32 with the touch sensor (also known as touch switch, or touch button).
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Touch Sensor
Touch Sensor Pinout
Touch sensor has 3 pins:
- GND pin: connect this pin to GND (0V)
- VCC pin: connect this pin to VCC (5V or 3.3v)
- SIGNAL pin: is an output pin: LOW when NOT touched, HIGH when touched. This pin needs to be connected to ESP32's input pin.

How Touch Sensor Works
- The state of the SIGNAL pin is LOW when the touch sensor is NOT touched
- The state of the SIGNAL pin is HIGH when the touch sensor is touched
Arduino Nano ESP32 - Touch Sensor
We can connect the touch sensor's SIGNAL pin to an ESP32's input pin and use the Arduino Nano ESP32 code to read the state of touch sensor.
Wiring Diagram between Touch Sensor and Arduino Nano ESP32

This image is created using Fritzing. Click to enlarge image
Here is the same wiring without a breadboard:

This image is created using Fritzing. Click to enlarge image
Pushing jumper wires into the headers is quick, but the wires can slip out. You can plug the Arduino Nano ESP32 into a Screw Terminal Expansion Board for Arduino Nano and connect the wires to its screw terminals. This is how it looks with the screw terminal board:

This image is created using Fritzing. Click to enlarge image
How To Program Touch Sensor
- Initializes the Arduino Nano ESP32 pin to the digital input mode by using pinMode() function. For example, pin D2
- Reads the state of the Arduino Nano ESP32 pin by using digitalRead() function.
Touch Sensor - Arduino Nano ESP32 Code
The below code reads the state of the touch sensor and print it to the Serial Monitor.
Detailed Instructions
- If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE.
- Copy the above code and paste it to Arduino IDE.
- Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
- Touch your finger to the sensor and release.
- Check out the result on the Serial Monitor. It looks like the below: