Matthias Wandel Turns Metal Into Proximity Sensors with the Raspberry Pi Pico's PIO Blocks
A simple timer can turn a single-pin input into a surprisingly sensitive proximity sensor — just add metal.
Software developer Matthias Wandel has turned the Raspberry Pi Pico's programmable input/output (PIO) blocks into a surprisingly sensitive capacitance sensor — capable of not only tracking proximity in free air but through a wooden floor too.
"[I have been experimenting with] measuring very low capacitance value changes (down to 10s of femtofarads) by toggling output lines on a [Raspberry] Pi Pico and timing how long it takes for the line to transition from 1 to 0 using the PIO state machine," Wandel explains of the project, which uses simple pieces of metal — including a drinks can — as the electrode for a capacitance sensor. "This is able to detect capacitance changes just from changes of my proximity to the electrode."
The Raspberry Pi Pico is built around the Raspberry Pi RP2040 microcontroller, with the successor Raspberry Pi Pico 2 using the RP2350. Both were designed in-house by Raspberry Pi, and alongside the main microcontroller cores include programmable input/output (PIO) blocks — hardware that runs separately to the processor cores and can execute state machines while the CPUs do something else.
In Wandel's case, the PIO blocks are being used as a capacitance sensor in a surprisingly simple way: one of the chip's general-purpose input/output (GPIO) pins is driven as a high output then switched to a pull-down input, and the state machine times how long it takes for the input to bleed from a logical 1 to a logical 0. It's not instantaneous, as a look at the process on an oscilloscope reveals — and it's also affected by nearby capacitance, meaning that with a suitably-sized electrode connected to the pin it's possible to track proximity.
While Wandel initially approached the project with a view to reading precise distances, the technique proved ill-suited — but its sensitivity means it can be used for a range of tasks where precise ranging isn't required, including room occupation sensing with a metal sheet placed beneath wooden floorboards tracking the movement of a person in the room above.
Wandel has detailed the project in the video above and on his YouTube channel, with MicroPython source code available on GitHub under an unspecified open-source license.
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.