Using a pin as a capacitive sensor seems to work with this code:
#include <bluefruit.h>
#define TOUCH_PIN A2 // Define the analog pin you are using for capacitive touch
void setup() {
// put your setup code here, to run once:
// Serial.begin();
}
void loop() {
int touchValue = analogRead(TOUCH_PIN); // Read the analog value from the touch pin
Serial.println(touchValue);
delay(500);
}
However, it is very unreliable, sometimes when touching the reading will go to a 1000, sometimes it will go to a 0. Am I doing something wrong? I simply soldered a wire to the A2 pin, running the board on a usb-c.
i dont think that particular MCU has touch pins… i think that might be what you are doing wrong…
XIAO ESP32S3 Sense
Doesn’t seem to have touch pins as esp32 one does, but it seems to still register value changes when I touch the wire, so I wonder if it is possible to make this work without a dedicated capacitive touch sensor.
what you are detecting is milivolts on the ADC… that is why is has eratic readings
you could write an adjacent pin high and “short” to an analog read pin and you would be measuring the milivolts that are trying to “ground thru your finger” not dangerious at all, but not capacitive in any way…
I see, I am trying to make a touch switch work without any external hardware like (https://electroslab.com/products/ttp223-capacitive-touch-switch-module)
We don’t want to use external hardware, because off-the-shelf switches are too large for our use case. Curious if you know any possible approaches here.
yes that module will do it or buy a XIAO ESP32s3 Sense… make sure you get the sense because i dont think the other does touch either
BE CARFUL MESSING WITH MAINS VOLTAGE… AT YOUR OWN RISK
FYI