touchRead issue

MonkeyWrench
Posts: 1
Joined: Tue Nov 04, 2025 2:26 pm

touchRead issue

Postby MonkeyWrench » Wed Nov 05, 2025 3:43 am

Hello everyone, first post here!! FYI I'm a relative newbie to coding for microprocessors so I appreciate your patience.

I've built a project that utilizes the built-in touch capabilities of ESP32 to set up capacitive touch-based switching of six relays (amongst other functions.) I chose this arrangement because I wanted logic control of the relays, so that I could simultaneously access switching via a bluetooth connected interface. I also wanted to arrange the code so that only one one relay could be switched on at a time.
This is with a WROOM dev board, by the way.

I've set a threshold value, looping code checks touchRead values and watches for them to drop below the threshold, which triggers a software response and toggles corresponding relays on/off. My "ambient" touchRead values while running are in the range of 1230 – 850 across six inputs, and their "touched” values are just under half of the ambient values across the board. (example 1230/481, 850/375.)

I’m not posting code here because everything is up and running, working more or less as intended. The capacitive touch switching works, and the bluetooth interface works in parallel to switch the relays, also updating relay switch status over bluetooth in real time. So far so good. The problem is that the touchRead values randomly/occasionally dip very low, triggering a change in relay switching status without any user touch input.

I have been able to _almost_ eliminate the "false" switching by dropping my threshold to barely above the actual touch values, but at the cost of making the touch pads much less sensitive – sometimes you have to touch 2 or 3 times to trigger a response. A more firm touch helps, but then that will occasionally get by my debounce.

I was hoping someone might have some insight as to why these downward spikes in the ambient are happening ? Any suggestions for how to configure the touchRead parameters to deal with this ? Is there something in my hardware (touch pad) setup that could be causing this, or is this just the nature of the beast with touchRead() ? Has anyone else experienced similar behaviour ?

I do have a couple of ideas for how I might modify the code to help reduce this issue. Right now the looping code is basically just running "full speed" and I'm thinking of perhaps modifying the code to reduce the touchRead sampling rate, in the hopes that some of the spikes might then be simply skipped over. This might not eliminate the problem but could perhaps reduce it to very near zero ?? Another approach that I was thinking of, was introducing some sort of averaging of the touchRead values in the hopes that it might smooth out the spikes.

This might be ideal in that it could be used to simultaneously reduce the sampling rate? Perhaps check touchRead values ten times in loop(), then calculate the average and check that against a threshold value ?

I will have to add a snippet of code so that I can determine the current loop() sampling rate.


BTW – the troubleshooting is complicated by the fact that I get different touchRead values when I run the device on its own power supply, versus when the dev board is running via a plugged USB cable. So serial monitor output via a USB connection doesn’t give me data that’s accurate to actual runtime values. Luckily the project incorporated a little OLED display, so I could temporarily reprogram that to display the touchRead values. I also tweaked the code to display (in real time) holding the lowest touchRead value for each pin. It updates the values on the display whenever there is a new lowest value. It will sometimes run for several minutes at a low of (example) around 800, before it suddenly spikes down to around 425.

Sorry for information overload, thanks in advance for any insight or advice.

Who is online

Users browsing this forum: Baidu [Spider], ChatGPT-User, meta-externalagent and 8 guests