Page 1 of 1

Help detecting fencing weapon touch with ESP32 Devkit V1

Posted: Mon Jun 23, 2025 1:42 pm
by valentin.fayolle
Hello,
I have an ESP32 Devkit V1( See attachment) board and I would like to connect it to a fencing weapon (foil or épée) and detect when the touch button is pressed.

Right now, my Arduino code looks like this:

cpp
Copier
Modifier
#include <WiFi.h>
#include <PubSubClient.h>

int past = LOW;
const int inputPin = 2;
#define ledPin 2

void loop() {
client.loop();
int sensorValue = digitalRead(inputPin);

if (sensorValue == HIGH && past == LOW) {
past = HIGH;
Serial.println("Switch is pressed!");
client.publish("ESP/out", "touch");
} else if (sensorValue == LOW && past == HIGH) {
past = LOW;
Serial.println("Switch is released.");
client.publish("ESP/out", "touch");
}
}

But so far, when I press the button (the "touch"), nothing happens!
Do you have any idea what might be wrong or how to better connect the weapon to the ESP32 for proper detection?

Thanks in advance!