12V solenoid connection with relay and esp32

My connections:
GND (Relay) → GND (ESP32)
VCC (Relay) → 5V (ESP32)
IN (Relay) → GPIO13 (ESP32)
COM (Relay) → Positive terminal of Solenoid (+)
NO (Relay) → Positive terminal of 12V Power Supply (+)
Negative terminal of Solenoid (-) → Negative terminal of 12V Power Supply (-)

Relay Details:

The relay I’m using is low-triggered, where 0 opens the solenoid and 1 closes it.

Problem:

When I connect the ESP32 to my laptop and turn on the 12V power supply, the solenoid opens as expected but remains open indefinitely. However, my code is designed to alternate the solenoid’s state (open/close) every 5 seconds.

To troubleshoot, I tried using a more advanced relay module with additional ports for JD-VCC and JD-GND, which I connected to the 12V power supply. The relay also had three pins labeled with H and L, seemingly to configure high-trigger or low-trigger modes. Assuming this, I placed a jumper between the H pin and the middle pin to make the relay high-triggered.

Unfortunately, with this setup, I believe I damaged my ESP32. After connecting the ESP32 to my laptop and powering the 12V supply, the ESP32’s communication port became unresponsive, and it is no longer connecting to my system.

Could anyone please help me identify the issue and provide guidance to resolve it?

Please post a picture of the relay module you bought.

Advanced relay( with JD+,JD-,3pins for High and low trigger)

Basic relay:

As far as I can tell from your picture, your “basic relay” was opto-isolated.

Have you read this page?

Exactly what connections did you make between the new relay and your ESP32?

My connections with advanced relay:
GND (Relay) → GND (ESP32)
VCC (Relay) → 5V (ESP32)
IN (Relay) → GPIO13 (ESP32)
COM (Relay) → Positive terminal of Solenoid (+)
NO (Relay) → Positive terminal of 12V Power Supply (+)
Negative terminal of Solenoid (-) → Negative terminal of 12V Power Supply (-)

Just after taking this picture i noticed that, in the image of advanced relay we have JD+, DC+ and JD -, DC- they had jumper in them, i forced a male pin in that jumper and connected it to 12v source, instead of removing that jumper and connecting JD+,JD- to 12v source, i know its a dumb move from my side, probably it would have caused damage to esp32. Normally connecting the JD-,JD+to 12v source should work right?

And thanks for providing that link will check that out before setting it up again

Do you have a multimeter (aka VMM)?

Yes can get access to it

You definitely want to make sure that the relay isn’t configured in a way that puts more than 5V on an ESP32 GPIO. Really it shouldn’t be more than 3.3V but they may be tolerant of 5V. More than that can destroy the ESP32, though. You can probe that with the voltmeter before hooking it up to the ESP32. :smiling_face:

Okay i will check that first. Thank you so much for helping me out.

I connected components based on the above mentioned connections, in that i did not connect IN pin in relay to gpio, then i placed the red probe in my multimeter to that IN port and black port to a grnd and i got 0voltage as reading. Is this what you wanted me to test or something else?

Pictures with your text would make it easier to follow. :slight_smile:

But yes, as long as you did that with JD_Vcc supplied to the relay board and had the grounds connected, that’s what I meant.

I don’t have one of these modules to play with myself, so I’m just going by what I read on that page I linked to and hoping it is right. Assuming that…

If you connected Vcc to either 5V or 3V3 on the ESP32 and also connected the JD_Vcc jumper, you were putting 12V onto the 5V or 3V3 of the ESP32, which would definitely “let out the magic smoke” — destroy it.

In the page I linked to above, you’ll find this image:

That’s how I suggest you connect your relay.

  • 5V or 3V3 on your ESP32 to Vcc on the relay board input
  • a GPIO to IN
  • don’t connect the ESP32 GND at all.

On the output side of the relay module:

  • “JD-Vcc” (relay power) to +12V on your power supply
  • COM to +12V on your power supply
  • NO or NC to positive terminal of your solenoid, depending on which state you want to start with when you power it up (leave the other disconnected)
  • GND to negative/GND terminal on your power supply

And your negative solenoid terminal connected to ground.

1 Like

This is similar to the setup i followed. The only difference is
My connection:
COM (Relay) → Positive terminal of Solenoid (+)
NO (Relay) → Positive terminal of 12V Power Supply (+)
Connection you suggest:

  • COM to +12V on your power supply
  • NO or NC to positive terminal of your solenoid

I will be working on this project only next week, when i do i’ll make sure to follow the link you provided. Thanks once again !

Correct, the direction of current flow through the relay doesn’t matter. You could put the relay between the solenoid and ground if you wanted.