See How Every Pin on an RP2040 Can Be a Capacitive Touch Sensor

Move out of the way dedicated capacitive peripherals, this how any digital or analog pin can be transformed into a button-less input.

Capacitive touch is everywhere

From almost every touchscreen to the buttons on a refrigerator, capactitive touch allows us to interact with countless devices while avoiding the risk of mechanical failure that buttons or switches can experience. And for most projects that leverage this versatile technique, dedicated hardware is used, often adding complexity and cost. So in his project, Fangzheng Liu shows how he was able to leverage both the digital and analog pins of an RP2040 microcontroller to detect when a connected pad was being touched.

Detecting voltage changes

Although both digital and analog pins work on a similar principle, their implementations on the RP2040 differ significantly. In the case of analog I/O, the process starts by outputting a short pulse to charge a capacitor before quickly switching to an input mode. Thanks to the large resistance on the pin, the capacitor will discharge slowly while also having the speed of this discharge decrease when being touched- something the RP2040 can easily measure and identify.

Digital pins are a little bit tougher because they are unable to sample incremental changes in charge over time. However, by using the same knowledge of slower discharge times while being touched, the time between the initial pulse and measuring a low value can be measured.

Building the circuit

In order to test the setup, Liu designed and milled his own 1-layer PCB from a copper-clad board with an array of mounting pins for the RP2040 and several touch pads. With it, he could touch each analog and digital pad while observing the board's built-in LED illuminate in an identifying color. To see more about this project, you can visit Liu's Hackaday.io project page or read his blog post here.

Evan Rust
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.
Latest articles
Sponsored articles
Related articles
Get our weekly newsletter when you join Hackster.
Latest articles
Read more
Related articles