0
\$\begingroup\$

I'm designing an esp32 interface on its own PCB that will be used to control an SPDT relay by means a software based on Home Assistant.

For this purpose I'll use an output of ESP32 (say GPIO 34) to control the relay and I would have chosen a relay like this:

enter image description here enter image description here

However, until now, I've never used this kind of solution.

I've ever used relay mounted on its own PCB and connected to Arduino in this way:

enter image description here

The question is:

May I directly connect the ESP32 output to the relay's DC signal input (other then DC + and - power) or I needed a sort of protection circuit?

And in this case, which?

Any idea?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Probably not. Most MCU pins have very low current capability. You need a suitable MOSFET and a flyback diode. Do a search here, it’s often asked. \$\endgroup\$
    – winny
    Jun 10, 2022 at 17:05

2 Answers 2

1
\$\begingroup\$

Connecting it directly could damage the ESP32 and will not likely get the relay to operate reliably. ESP32 is 3.3V and the relay you show is 5V also.

You can duplicate the circuitry on the module if you like. There is nothing unnecessary on there except the LED (which actually performs a function- to leave it out, increase the resistor to about 510\$\Omega\$). You can see the exact circuit in my answer to this question. The diode can be 1N4001 to 1N4007, 1N5817 to 1N5819, 1N914, 1N4148, 1N4448 etc. The transistor is an SOT23 S8050, a very common NPN transistor- a jellybean part, at least in Asia.

\$\endgroup\$
2
  • \$\begingroup\$ Hi. Thanks for your reply. Seeing the post that you are linked it seems to me that there is not a flyweel diode but only a LED. Is correct? \$\endgroup\$
    – M4Biz
    Jun 11, 2022 at 9:50
  • \$\begingroup\$ D2 in my schematic is the protection diode. In the product photo it is an axial-lead part. \$\endgroup\$ Jun 11, 2022 at 15:39
1
\$\begingroup\$

You'll need to look up two important concepts if you plan on using this to control line-powered equipment: clearance and creepage. Then, you'll need to determine how wide your traces need to be for the current you plan to run through the board. There are online calculators for both of these. Controlling a ~70mA @ 5VDC relay from a 3.3V GPIO is not going to happen without additional circuitry as @Spehro Pefhany mentioned. While you're getting those additional components, I also recommend getting better relays than the "10 for $7.50" deal off Amazon.

\$\endgroup\$
2
  • \$\begingroup\$ Hi, thanks for you reply. May you suggest me wich relays are better ? \$\endgroup\$
    – M4Biz
    Jun 11, 2022 at 9:53
  • \$\begingroup\$ Specific product recommendations are off topic for a host of reasons, but if you go to any of the big electronics distributors (Digikey, Mouser, Newark, Allied, etc), ones who have a reputation for selling quality electronic parts to uphold, you'll find suitable relays for not much more than what you were paying on Amazon. \$\endgroup\$
    – vir
    Jun 13, 2022 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.