Noob question about esp32, relay and solenoid

Apologize, i have almost 0 knowledge/experience.

esp32: esp32-devkit-esp32-wroom

Relay module 2 way

solenoid: 24V

power supply: 24V

I’m trying to follow this simple diagram.

But the solenoid is not able to be activated using the relay module.
When I connect the solenoid directly to the power supply, it works.
When I toggle the pin programly via esp micropython, the led of the relay is toggled as expected but the solenoid isn’t.
I tried different pins: 33, 26…
When measuring with multimeter it looks like there is a static current of 24V in the relay common’s and NO’s ports.
Switching to NC didn’t help.

I’m probably missing something very basic, please enlighten me

This is from a link on using the HL-52S relay module.

This layout indicates a separate supply… do you have power to JD connection?

The esp32 is a 3.3V micro the arduino is 5V, take that into consideration.


I dont have a separated power supply to power the relay.
In the diagram i’m using, it’s connected via vin pin which should be 5v. When tested with multimeter i see it’s rated 4.5v.
Nevertheless, the name states it’s input and not output.
The jumper is placed and connects between vcc and jdvcc pins.
Do you think that this is the issue and i should use a separated power supply?

As ever, clear photos of the hardware you actually have really help us give good advice.

In your first post you link to the relay specifications, not the relay board itself, these boards typically come with 5, 12 or 24v relays. That link implies it is a 24v relay.

  • The relay voltage is the ‘coil voltage’ needed to activate the relay.

If the relay on the board is a 24V relay, you need to remove the jumper and supply 24v to the JDVcc jumper pin.

  • The supply on JDVcc must match the activation voltage for the relay mounted on the board.
  • The Vcc line on the relay board should go to the 3.3v coming from the ESP32 (which is a 3.3v part),

(*) Critical! or you will blow up the ESP board

I hope that those images are clear enough:

This is the link to the datasheet of the relays’ board:

I’m confused.

In the second link i provided in the original post, it looks like the power supply should connect to the common and NO sockets of the relay, and to the solenoid (instead of the lamp).

I thought that the jumper on the relays’ board should be removed only if an external power source is needed to activate the board, not the solenoid.
In this case i understand that i should connect positive of 24V to JDVcc and negative of the same to the Gnd (in the same component of the jumper. Sorry, not sure how it is called)

But as far as i understand this is not my case. Maybe i’m wrong. Can you please clarify? does the diagram i used is not good for me?

Can you please take a clear photo from straight above it of your relay board? I think we need to be able to see the labels, and have clarity on what wires are connected where. The pictures you provided don’t show that well enough.

The schematic @jkwilborn found should almost work for you; note that in your case JDVcc is 24V and Vcc is 3.3V, and that the optocoupler and parts between the optocoupler and the relay are all part of the relay board.

However, you probably don’t want the DS1 LED in series with the optocoupler, because 3.3V might not be enough for the two diodes in series. If you don’t need it, you can just omit it. If you need it, you will also need a separate resistor; let us know and we can explain more.

Yes! You need 24v to make the relay close so remove the jumper and put the +24v to JDVcc as well as to the solenoid, and the negative to 0v/GND on the jumper header (these are commonly called ‘pin headers’).

VCC on the board should go to 3V3 line, but as @mcdanlj says the LED on the breadboard may prevent the opto-coupler from working.

  • If you look at the diagram from @jkwilborn above you can see DS1 and R1 in the circuit.
  • DS1 is in fact a LED mounted on the HL52S board (but only shown as a simple diode in the diagram).
  • This means you already have a protection resistor and indicator light on the HL52S board itself. You can totally dispense with the LED+resistors on the breadboard. :wink:

Thank you all for the information.
I’m still don’t know what should i do, i believe that in the next post, if any of you will agree to help more, i’ll know what to do.

I’ve removed unnecessary components and took 3 new closeups of my current circuit:

  • the network cable is there just to verify that i can use this kind of cable for the circuit. i see that i can.

jkwilborn’s diagram is a bit hard for me to understand, as the components implementation are not identical.

As there probably no specific diagram for my case, please explain in words where i need to connect which cable.

Following is a personal legend in words, in order for us to speak the same language (as i’m not familiar with all the terms):
RBE: Relay board bottom right section. as far as i understand the wires should go from here to the esp32 board.
RBJ: jumper secion of my relay board
R: Relay component (big blue box)
ESP32: my esp device which has a 5v PSU. i think we don’t need to regard it here.

This is my current circuit in words. I wonder if any of you can suggest a new words-diagram that i should be using.
ESP32_Vin (red) → RBE_Vcc
ESP32_Gnd (black) → RBE_Gnd
RBJ_Jumper (yellow) is placed. and connect between RBJ_JDVcc and RBJ_VCC. No wires for RBJ_Gnd

Edit: Note that I wrote this before I saw your reply above…

The PDF for the HL52S board is interesting; on page 2 there is a description of supplying the board with 5V(in their example) on JDVcc while using 3v3 on the control pin. They then say

NOTE: Some Raspberry-Pi users have found that some relays are reliable and others do not actuate
sometimes. It may be necessary to change the value of R1 from 1000 ohms to something like 220 ohms, or
supply +5V to the VCC connection.

This may imply that 3v3 is not always enough to activate the OptoIsolator. But I think you will be OK in this case, ESP32’s provide a lot more current on their IO pins than the RPi does.

Regard the LEDs and resistors. On the final “product” they will be mounted on some box side, representing each solenoid’s status. This is just a sample. Final product will contain a dozen of solenoids and LEDs.

OK, so let’s see if i understand well the changes I need to make:

  1. remove RBJ_Jumper (yellow)
    (without disconnecting: PSU_24v_POSITIVE → SOLENOID_POSITIVE (black))
  3. PSU_24v_NEGATIVE → RBJ_Gnd
    (without disconnecting: PSU_24v_NEGATIVE → SOLENOID_NEGATIVE (blue))

I didn’t see this in any diagram. Did i understand the required changes correctly?
I won’t burn anything right?

Chat GPT provided the following nice diagram. But it’s confused at least as I am.
It occasionally changes its mind.

ESP32 GPIO ----> Relay Control Input
ESP32 GND ----> Not connected to relay

Relay JDVCC ----> External Power Supply Positive
Relay GND ----> External Power Supply Ground

Relay COM ----> Solenoid +
Relay NO ----> Solenoid -
Solenoid - ----> External Power Supply Ground

Is it OK to connect Solenoid negative to RELAY NO and on the same time to External Power Supply Ground?

See if this helps.
Using your simple drawing as a reference and consistent with what others have suggested try this simple setup and test:

  • Remove the JDV to VCC jumper
  • Connect 24V to the JDV pin
  • Disconnect the ESP end (GPIO5) of the IN1 pin (green wire in drawing)
  • With power applied [esp and the 24V supply]
  • Ground the end of the IN1 wire.

The relay should click.

Thank you all, now it’s working.
It was not clear to me that all the grounds should be connected together, and that the relay needs to click.

Something went wrong and my circuit went up in smoke.
This is a safety risk and i don’t like it.

I had connected all the ground together in one strip of the breadboard and all the 24v in a different strip of the breadboard.
It looks like meltdown stared on the cords of the 24v power supply, and then in that shared strip of the 24v on the board.
Some of the cords have start twisting.

Trying to figure out what was the reason
Wrong wiring?
The fact that i connected thinner cords to the 24v cords?
The fact that i had a shared 24v strip?
Can you point the root cause?

Here is my connection diagram:
PSU (24v):
+ → Relay (COMM)
- → Shared ground

Pin 33 → Relay (IN1)
Gnd → Shared ground
5v psu (usb)

Near inputs (from esp32):
Gnd → Shared ground
Vcc → Shared + (24v)
In place of jumper:
JDVcc → Shared + (24v)
Gnd → Shared ground

- (Blue) → Shared ground
+ (Black) → Normally Open (NO)

You posted that it was working
and then
It was “smoking”…

Did you do something to the circuit between these two posts?

Do you have 24V connected to the relay boards VCC?

I think I’ve connected the wrong wires, but i’m not sure now.
I don’t want to confuse everybody, i’ll open a new thread if i’ll have more issues.
Thank you.

If you still struggle you can sent the code and I will check it, if it wasn’t done yet.

It’s REALLY important to understand what a “circuit” is and how the electric signals move through the wires. When you don’t know how this works, things just look like pins and sockets then it’s all a guessing game if things are connected up so they work or burn down the house.

You seem to enjoy making this stuff so I would hope you’re also interested in learning a bit about what’s going on so that your more successful. Links found here can get you the understanding that’ll move you so much further than just plugging things in.

1 Like

This seems like an “interesting” problem.
Those relay boards have specific 3.3v and or 5v versions. The 5v version does usually NOT switch reliably with 3.3v.

It is usually NOT needed to change the jumpers on the JD-VCC VCC GND header. That usually results in releasing the magic smoke…

The board can be modified by changing the values of the two resistors near the optocouplers to suitable values for 3.3v. It is however easier to just get the correct voltage module.

Further than that, the relay side will switch your solenoid with no problem. Also, Make sure that you are NOT using one of the input only pins on the ESP32.

I have been out of things for the last 2 months due to an injury. If you have a circuit diagram of what you are trying to do, post it here, and I shall try to help you. Between all of the other guys here, we will definitely get the answer :slight_smile: