Hello everyone,
I'm working with an Adafruit TRRS Jack Breakout Board and need to detect when a plug is inserted by turning the ESP32’s internal LED on when connected and off when removed.
I'm using the RSw pin on the breakout board for detection, as it’s floating when the plug is connected. I've combined the Left and Right audio pins into a mono signal with two 10K resistors, then passed the signal through a 100nF capacitor to remove any DC component before sending it to pin 35. The RSw pin (yellow) is connected to pin 32 on the ESP32.
Here is the code that I'm using with no result
define AUX_DETECT_PIN 32 // Connect either RSw or LSw here
#define LED_PIN 2 // ESP32 built-in LED
void setup() {
pinMode(AUX_DETECT_PIN, INPUT_PULLUP); // Use internal pull-up to handle floating
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int auxStatus = digitalRead(AUX_DETECT_PIN);
if (auxStatus == HIGH) {
// Pin is floating, aux cable is connected
digitalWrite(LED_PIN, HIGH); // Turn on LED
} else {
// Pin is grounded, no aux cable is connected
digitalWrite(LED_PIN, LOW); // Turn off LED
}
delay(100); // Small delay to debounce
}
Sleeve - This is the microphone pin (the sleeve or S in TRRS).
Right - This is the right audio pin (the first ring or R in TRRS).
RSw - This is the right switch pin. When the plug is not inserted, this pin is connected to the right contact. When the plug is inserted, this pin will float.
LSw - This is the left switch pin. When the plug is not inserted, this pin is connected to the left contact. When the plug is inserted, this pin will float.
Left - This is the left audio pin (the tip or T in TRRS).
Ring - This is the ground ring pin (the second ring or R in TRRS).
Do I need a pull-up resistor for RSw, or should I connect both RSw and LSw? Any insights or suggestions would be greatly appreciated!
Thank you!