How can you add a button to a device without drilling a hole in its enclosure? This was the challenge I faced when designing the Pendrive S3, as I wanted to use an off-the-shelf USB enclosure. Drilling a hole was an option, but I aimed for the Pendrive S3 to resemble a regular USB stick without any conspicuous buttons altering its exterior.
The solution became clear: a capacitive touch button. These buttons are ubiquitous in modern devices, from stoves to elevators. The primary advantage of a touch button is that it doesn’t require openings in the surface, preventing water or dirt from entering the electronics.
A capacitive touch button works by detecting the presence of a finger through changes in capacitance, caused by the conductive properties of the human body. When a finger approaches or touches the button, it alters the electric field and increases the capacitance, which a controller then detects and interprets as a touch event, triggering the corresponding action.
However, for optimal performance, the gap between the button and the finger should be minimal. In the Pendrive S3, the distance from the PCB to the outer shell of the enclosure was 6.3mm—far too much to provide a clear touch signal. I considered filling the gap with a material that has a high dielectric constant, as higher dielectric constants increase capacitance. While air has a low dielectric constant, materials like ceramics or certain plastics are much better.
Material | Dielectric constant |
Vacuum | 1 |
Air | 1.00058986 |
Glass | 3.7–10 |
Silicone | 11.68 |
Water | 80 |
This approach, however, raised manufacturing concerns regarding how the material would be inserted during assembly. Seeking alternatives, I discovered a class of components typically used to solve this problem: metal wire springs.
It’s Spring Time
I experimented with a copper wire, winding it around an AA battery and connecting it to an ESP32. The ESP32 chip has a built-in driver for capacitive touch buttons, requiring only a sensor to detect a finger’s touch. This sensor could be a copper area on a PCB, aluminum foil, or a wire.
After confirming that a wire could effectively detect a finger’s touch, I needed to consider efficient manufacturing. Manually winding copper wire into a spring is impractical for an automated assembly process. Therefore, I turned to my primary source for electronic components: https://jlcpcb.com/parts. It is most cost-effective to select components from JLCPCB’s catalog, as they manufacture the boards. While it’s possible to source components from other distributors like DigiKey or Mouser, doing so significantly increases costs per board.
Searching the JLCPCB catalog for “spring” yielded many options. Under “press spring,” I found suitable components, including variations with one pin soldered in the center and others with two pins, all through-hole. Knowing the distance between the PCB and the enclosure was 4.6mm, I needed to determine how much force was required to compress the spring to fit into the enclosure. Experimentation provided the answer.
The spring I selected is 7mm in height, with a weak enough spring force to fit perfectly into the enclosure. Now, the “hidden” button in the Pendrive S3 can be used for various applications, whether to start a ducky script or trigger another function.
The Test
#include <Arduino.h>
#include <driver/touch_sensor.h>
int threshold = 180;
bool touch1detected = false;
void gotTouch1(){
touch1detected = true;
}
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
analogRead(T1);
touchAttachInterrupt(T1, gotTouch1, threshold);
}
void loop()
{
if (touch1detected) {
touch1detected = false;
if (touchInterruptGetLastStatus(T1)) {
Serial.println(" --- T1 Touched");
} else {
Serial.println(" --- T1 Released");
}
}
delay(50);
}