06: Sensors & electronic input
This week I built a capacitive touch sensor using the XIAO ESP32C3 that sends a spacebar press to my laptop over Bluetooth. The goal was to turn touch into a usable computer input.
Concept
I wanted something simple but real: touch a pad, and the computer reacts. Instead of just printing values to Serial, I used Bluetooth HID so the board behaves like a wireless keyboard.
Hardware
- XIAO ESP32C3
- D1 as TX (voltage step)
- D0 as analog RX (measurement)
- Conductive touch pad
The sensing works by toggling one pin high and low and measuring the voltage response on another. When I touch the pad, the result goes past a threshold.
Libraries
- NimBLE-Arduino
https://github.com/h2zero/NimBLE-Arduino - ESP32_NIMBLE_Keyboard
https://github.com/Berg0162/ESP32-NIMBLE-Keyboard
Distance Calibration

Issues I Ran Into
- Multiple BLE keyboard libraries installed at once. Arduino was compiling the wrong one.
- NimBLE version mismatches that caused compile errors.
- Heap assert crashes from using the wrong BLE stack.
- The sensor initially spammed dozens of spaces per touch until I added a threshold-crossing check and we added some little debouncing timer.
Device

Core Logic
bool isAbove = (result >= THRESHOLD);
if (isAbove && !wasAbove) {
unsigned long now = millis();
if (now - lastSendMs >= 150) {
bleKeyboard.write(' ');
lastSendMs = now;
}
}
wasAbove = isAbove;The important part is detecting when the value crosses the threshold instead of continuously firing while it's above it.
Wiring

Demo
Once everything was stable, it felt solid. Touching the pad triggers a space instantly. Now I can build something more expressive on top of it.