I'm a relatively new user, but I've tripped across a weird issue that has me stumped!
I'm using a simple while (digitalRead(touchPin) == HIGH) to call a function that turns on a relay for 10seconds. BUT after about 6 or 7 seconds touchPin is driven LOW and the while is exited. I've tried with 2 switches, a proximity and capacitive touch switch.
I hope I'm just missing something small. I've tried it on a Nano, Pro micro and Attiny85 with the same result. Hoping someone has tripped across this behavior?
We need to see your complete code.
Please post it in code tags as explained in the above link.
Can you please post a schematic of your project?
Please do not use Fritzy, a hand drawn image will be fine.
Include ALL power supplies, component names and pin labels.
Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
In the Arduino IDE, use CtrlT or CMDT to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
The thought process was that maybe giving it a poke would act as a keep alive.
I just tested the sensor and guess what it does after 6-7 seconds? Another sensor does the same thing too. Not sure what it is, but looks like it's an issue with the touch sensors.
First thing you need to do is toss the nonsense theory that digitalRead is somehow timing out. It absolutely is NOT. There is no hardware or software present that would cause that to happen, so stop looking there. Your problem lies elsewhere.