If we give external power supply(a 5V adaptor) to the relay should we connect gnd of relay to gnd of esp32
Hello, I recommend reading my relay module guide for Arduino (it’s the same for the ESP32, but just connect it to the right GPIO): https://randomnerdtutorials.com/guide-for-relay-module-with-arduino/
I don’t have the schematics for that exact circuit.
Here’s some information about the JD-VCC pin:
Note: notice that the module has a jumper cap connecting the VCC and JD-VCC pins; the one shown here is blue, but yours may be a different color. The jumper cap allows you to choose whether the circuit is physically connected to the Arduino circuit or not, and you can choose to have it on or not.
With the jumper cap on, the VCC and JD-VCC pins are connected. That means the relay electromagnet is directly powered from the Arduino’s power pin, so the relay module and the Arduino circuits are not physically isolated from each other (this is the configuration we’ll use).
Without the jumper cap, you need to provide an independent power source to power up the relay’s electromagnet through the JD-VCC pin. That configuration physically isolates the relays from the Arduino with the module’s built-in optocoupler.