ESP32 S3 - Touch Sensor - LED
This tutorial shows you how to use the ESP32 S3 together with a capacitive touch sensor to control an LED based on the state of a finger touch. By wiring a touch sensor module to a GPIO input and an LED to a GPIO output, you will gain a practical understanding of how to respond to human touch events with a visual indicator on the ESP32 S3.
What you'll build:
- A circuit connecting a capacitive touch sensor and an LED to the ESP32 S3
- A sketch that continuously reads the touch sensor output pin on the ESP32 S3
- A system that automatically turns the LED on when the sensor is touched and turns it off when the touch is released
- A foundation for building touch-activated lights, touchpad interfaces, and human-input-driven projects
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables ESP32 S3 Starter Kit (ESP32 S3 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.
Overview of LED and Touch Sensor
The capacitive touch sensor and an LED are a simple yet effective pairing for building touch-responsive projects on the ESP32 S3. The touch sensor detects the capacitance change caused by a finger touching its pad, outputs a HIGH signal on its data pin, and the ESP32 S3 reads that signal to switch the LED on or off via a digital GPIO output.
Key Specifications
We have dedicated tutorials covering each component in depth. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to the ESP32 S3, and Arduino code. Learn more about them at the following links:
Wiring Diagram
Connect the touch sensor and LED to your ESP32 S3 by following the diagram below. Double-check all connections before applying power, paying particular attention to the LED polarity and the 220 ohm current-limiting resistor placement.

This image is created using Fritzing. Click to enlarge image
If you plan to keep this circuit, think about screw terminals. Simply plug the ESP32 S3 into a Screw Terminal Block for ESP32 S3. The diagram below shows the same wiring with the screw terminal board.

This image is created using Fritzing. Click to enlarge image
You can also use a GPIO Breakout Board for ESP32 S3. It gives each GPIO its own S, 3.3V and GND pins, so module wires plug straight in:

This image is created using Fritzing. Click to enlarge image
Safety Notes
Always include the 220 ohm current-limiting resistor in series with the LED to avoid drawing excessive current through the ESP32 S3 GPIO pin, which can permanently damage the microcontroller. Most capacitive touch sensor modules operate at 3.3V and are fully compatible with the ESP32 S3's GPIO logic levels, so connect the sensor's VCC pin to the 3.3V output on the ESP32 S3 board to ensure reliable operation.
ESP32 S3 Code
The following code reads the output pin of the touch sensor on the ESP32 S3 and turns the LED on immediately when a touch is detected, then turns it off once the touch is released. The sensor output goes HIGH when touched and LOW when not touched, allowing the ESP32 S3 to mirror the touch state directly to the LED without any debounce logic for this simple on/off use case.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Wire the components following the wiring diagram shown above.
- Connect the ESP32 S3 board to your PC using a USB Type-C cable.
- Open Arduino IDE on your PC.
- Select the correct ESP32 S3 board and COM port from the Tools menu.
- Copy the above code and paste it into Arduino IDE.
- Click the Upload button to compile and upload the code to the ESP32 S3.

- Touch and hold the touch sensor pad with your finger.
- Observe the LED turn on while the sensor is being touched.
- Release your finger and observe the LED turn off immediately.
- Check the Serial Monitor to see the live touch state printed in real time.
- Pro Tip: If the touch sensor feels overly sensitive or intermittently triggers without contact, try placing the sensor away from high-frequency noise sources and keep its connecting wires as short as possible, since longer wires can act as antennas and introduce false touch events on the ESP32 S3.
Serial Monitor Output
The following Serial Monitor output shows the ESP32 S3 reading touch data from the capacitive touch sensor in real time. Each line displays the current touch state and the corresponding LED state triggered by the sensor output.
Application and Project Ideas
Once you can trigger an LED from a touch sensor on the ESP32 S3, you can extend this pattern to a wide range of touch-activated and human-interface projects.
- Touch-activated lamp: Replace the LED with a relay-controlled mains lamp that switches on whenever the sensor pad is touched, creating a simple bedside touch lamp.
- Touch security keypad: Combine multiple touch sensor pads to form a simple PIN-entry keypad that unlocks a relay, solenoid, or electromagnetic lock when the correct sequence is entered.
- Interactive display: Use a touch sensor to wake an OLED or LCD screen from sleep mode only when the user makes contact, conserving power in battery-operated devices.
- Touch-based counter: Count the number of touch events and display the running total on a 7-segment display or serial monitor, useful for tallying items or people.
- Smart appliance controller: Use the touch sensor as a soft power button for a relay-switched appliance, providing a modern capacitive interface in place of a mechanical switch.
- Alert system: Trigger a piezo buzzer or send an email notification via the ESP32 S3 Wi-Fi connection whenever the touch sensor is activated, useful for access control or tamper detection.
Video Tutorial
Watch the step-by-step video walkthrough for this ESP32 S3 project below.
Challenge Yourself
Now that you can control an LED with a touch sensor on the ESP32 S3, try these progressively challenging extensions to deepen your understanding and build more capable touch-activated systems.
- Beginner: Add a Serial Monitor message that prints a running count of how many times the sensor has been touched since the ESP32 S3 was powered on, so you can track interaction events over a session.
- Beginner: Add a second LED wired to a different GPIO pin and make it blink at a fixed interval while the primary LED stays solid on when touched, creating a dual-output visual indicator.
- Intermediate: Add a push button that allows the user to invert the touch logic at runtime — so the LED is on by default and turns off only when the sensor is touched — and indicate the current mode via the Serial Monitor.
- Intermediate: Connect an I2C OLED display to the ESP32 S3 and show a live count of touch events alongside the current touch state, updating the display each time the sensor is touched or released.
- Advanced: Use the ESP32 S3 Wi-Fi connection to send an MQTT message or HTTP request to a home automation platform each time the touch sensor is activated, enabling remote touch-event monitoring.
- Advanced: Build a multi-pad touch interface using two or three touch sensor modules on separate GPIO pins and create a simple gesture or sequence recognition routine that triggers different LED patterns depending on which pads are touched and in what order.