ESP32 C3 Super Mini - Touch Sensor - LED

This tutorial shows you how to use the ESP32 C3 Super Mini to control an LED with a touch sensor. The LED stays on while your finger is on the pad, and it turns off when you let go. It is a simple first project for beginners.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Touch Sensor LED

WARNING

The ESP32 C3 chip does NOT have built-in capacitive touch pins, so touchRead() does NOT work on the ESP32 C3 Super Mini. This tutorial uses an external touch sensor module and reads it with digitalRead().

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Touch Sensor
1×LED Kit
1×LED (red)
1×LED Module
1×Alternatively, Button and LED Kit
1×220Ω Resistor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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

A touch sensor is a small module that gives a digital signal when your finger touches its pad, and an LED is a small light you can turn on and off.

Key Features:

  • Touch Sensor: It has no moving part and reads like a button with digitalRead().
  • LED: It turns on and off with a digital signal from the board.
  • Together: The sensor reports the touch, and the board turns that report into light.

Technical Specifications:

  • Touch sensor power: 3.3V from the ESP32 C3 Super Mini
  • Touch sensor output: digital, HIGH when touched and LOW when not touched
  • LED resistor: 220 ohm

Each part has its own tutorial with the pinout, how it works, wiring and code:

Pinout

Here are the pins you will connect in this project.

  • Touch Sensor VCC: connect to 3.3V
  • Touch Sensor GND: connect to GND (0V)
  • Touch Sensor SIGNAL: sends the HIGH or LOW signal to the digital input pin (the code comment calls it the OUTPUT pin)
  • LED Anode (+): the longer leg, controlled by the output pin through the resistor
  • LED Cathode (-): the shorter leg, connects to GND

Wiring Diagram

The touch sensor uses three wires, and the LED uses two wires plus a resistor.

  • Note: Power the touch sensor from the 3.3V pin, never from 5V. A 5V supply makes the SIGNAL pin output 5V, which can damage a GPIO pin.
  • Note: Always use the 220 ohm resistor with the LED, or the LED can burn out.
  • Note: Keep the sensor wires short. Long wires near the pad can make the sensor trigger by itself.
Component Pin ESP32 C3 Super Mini Pin
Touch Sensor VCC 3.3V
Touch Sensor GND GND
Touch Sensor SIGNAL GPIO7
LED Anode (+) GPIO3 (through 220 ohm resistor)
LED Cathode (-) GND

The wiring diagram with power supply from USB cable:

The wiring diagram between ESP32 C3 Super Mini Touch Sensor LED

This image is created using Fritzing. Click to enlarge image

The wiring diagram with power supply from 5V adapter:

The wiring diagram between ESP32 C3 Super Mini Touch Sensor LED  5V power adapter

This image is created using Fritzing. Click to enlarge image

ESP32 C3 Super Mini Code

The code below lets the touch sensor on GPIO7 control the LED on GPIO3.

What This Code Does:

  • Starts Serial: opens the Serial Monitor at 115200 baud.
  • Sets the pins: GPIO7 is an input for the sensor, and GPIO3 is an output for the LED.
  • Reads the sensor: digitalRead() checks the sensor state again and again.
  • Touched: when the state is HIGH, the LED turns on.
  • Not touched: when the state is LOW, the LED turns off.
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-touch-sensor-led */ #define TOUCH_SENSOR_PIN 7 // The ESP32 C3 SuperMini pin connected to the OUTPUT pin of touch sensor #define LED_PIN 3 // The ESP32 C3 SuperMini pin connected to LED's pin void setup() { Serial.begin(115200); // initialize serial pinMode(TOUCH_SENSOR_PIN, INPUT); // set ESP32 C3 SuperMini pin to input mode pinMode(LED_PIN, OUTPUT); // set ESP32 C3 SuperMini pin to output mode } void loop() { int touchState = digitalRead(TOUCH_SENSOR_PIN); // read new state if (touchState == HIGH) { Serial.println("The sensor is being touched");; digitalWrite(LED_PIN, HIGH); // turn on } else if (touchState == LOW) { Serial.println("The sensor is untouched"); digitalWrite(LED_PIN, LOW); // turn off } }

Detailed Instructions

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Wire it up: Connect the touch sensor and the LED as shown above.
  • Connect the board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open the IDE: Open Arduino IDE on your computer.
  • Select the board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Select the port: Pick the COM port of your board in Tools > Port.
  • Copy the code: Copy the code above and paste it into Arduino IDE.
  • Upload: Click the Upload button on Arduino IDE.
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • Open Serial Monitor: Open it on Arduino IDE and set the baud rate to 115200.
How to open serial monitor on Arduino IDE
  • Test it: Touch and keep touching the touch sensor for several seconds.
  • Watch the LED: See the LED turn on, then turn off when you let go.
  • Check the result: See the touch state on the Serial Monitor. It looks like the below:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
The sensor is untouched The sensor is untouched The sensor is being touched The sensor is being touched The sensor is untouched
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: If the LED stays on by itself, move your hand and the wires away from the pad and reset the board, so the sensor can calibrate again.

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Project Ideas

This touch sensor LED idea can control many real things.

  • Touch Lamp: Keep a small light on while your hand rests on the pad.
  • Hidden Switch: Put the sensor behind a thin panel and light a sign when touched.
  • Touch Indicator: Show with an LED that a touch panel is working.
  • Night Light: Touch the pad to see your way in a dark room.
  • Game Input: Use the pad as a game button with an LED as feedback.

Challenge Yourself

Try these small upgrades to learn more about the ESP32 C3 Super Mini and the touch sensor.

  • Easy: Reverse the logic, so the LED is on when the sensor is NOT touched.
  • Easy: Print the text only when the state changes, not in every loop.
  • Medium: Toggle the LED between ON and OFF each time the sensor is touched.
  • Medium: Count the touches and print the total on the Serial Monitor.
  • Advanced: Add a second LED on GPIO5 that turns on only after a long touch.
  • Advanced: Add a second touch sensor on GPIO6, so one pad turns the LED on and the other turns it off.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!