The ESP can only output 3.3V. A lot of relay boards that say 5V will also trigger on this, but definitely not all. You can verify the ESP is working properly by using a multimeter to confirm the GPIO is going high as well as try connecting the relay to the 3.3V pin of the ESP to see if that triggers it.
Then resolder it back to that module. Do you think they made the circuit next to yellow connector just for fun? Or because it’s needed to drive 5V relay safely with 3.3V microcontroller…
Where you think the current flows?
Relay coil is nominally drawing about 100mA. Esp Gpio can sink safely may be ~20mA.
So you are abusing your Gpio sinking too much current, but not only, you are sinking 5V. And esp Gpios are not 5V tolerant.
On the other hand, when you need to turn off your relay you write Esp gpio high. At this point relay coil has a voltage 1.7V (5-3.3V) and unknown behavior, may bee it’s not turning off, may be it’s flickering between…
Also, relay module has flyback diode to protect circuit from spike when coil is de-energized. Bare relay doesn’t.
You should not be using 5 volt relays in an ESP32 device. Only use relays compatible with 3.3 volts. In addition to that, you need to consider using a relay module. Otherwise you have to wire a flyback dial in the opposite direction of the current so that the ESP isn’t fried when the relay shuts off.
Reality is that most (all the dozens I own) relay (modules) designed for 5V do work perfectly fine with 3.3V too.
Why is that? Because the threshold voltage to toggle the relay (distinguish between high and low state) is usually around 2 - 2.5V. And that is perfectly fine to be toggled by 3.3V GPIO’s.
So the GPIO state is low: ~0V → Relay is OFF (because lower then 2 - 2.5V)
Now when GPIO is high: ~3.3V → Relay will be ON (because it is higher then 2 - 2.5V)
So in general you can assume 5V relay do work perfectly fine on 3.3V GPIO’s
I think this is more of a lack of understanding regarding how GPIOs work, because in theory if I was able to switch a GPIO to GND, then what I was trying should have worked.
No really. You can “switch” Esp gpio to gnd to sink a small current (~20ma). But not to sink 100mA and not to sink 5V in any case.
If you look at the module from where you pulled the relay out, you will see transistor, optocoupler, flyback diode, some resistors etc.
Believe me, those chinese module manufactures didn’t put even one single resistor on that module if it wasn’t necessary.