2
\$\begingroup\$

My ESP32 is controlling a relay which I switch on for 500ms (controlled through the internet).

Do I need a diode to protect my ESP32 from voltage spikes when the magnetic flux collapses?

I'm using an ESP-WROOM-32, and the relay specs are (taken from here):

Small and light weight.Specifications:- Contact form: SPST normally open- Coil Resistance: 1050ohms- Nom Volts: 12 - Pickup Voltage: 8.4V DC- Rated Current: 11.4mA - Allowable Voltage: 160%- Dropout Voltage: 1.2V DC - Carry Current = 500mA.- Power Consumption (W): 0.1 - Contact Rating: 1A- 12 VOLT

I've been using it without any problems for quite a few days, but I'm wondering if there's a chance it could be damaged randomly, or if there's something in the ESP32 pins that protects it from things like this.

Here's a circuit diagram of my setup:

enter image description here

\$\endgroup\$
6
  • 1
    \$\begingroup\$ It should not even work. You are driving a 12V relay coil directly from a 3.3V IO pin. The coil resistance is so high that only few mA will flow, so the IO pin protection diodes inside the chip do not blow up immediately. However you should not drive the coil directly from an IO pin to begin with. \$\endgroup\$
    – Justme
    May 20, 2020 at 10:14
  • \$\begingroup\$ @Justme The voltage has been enough to activate the relay. Everything has been working fine. \$\endgroup\$ May 20, 2020 at 10:15
  • \$\begingroup\$ @Justme so there are already IO pin protection diodes inside the chip? \$\endgroup\$ May 20, 2020 at 10:39
  • 1
    \$\begingroup\$ Something is incorrect in the description of the project. Perhaps that is not the relay. Perhaps the asker actually has a relay module. A picture would help. \$\endgroup\$ May 20, 2020 at 12:47
  • \$\begingroup\$ @ChrisStratton I've added a link to the relay in the question. \$\endgroup\$ May 20, 2020 at 13:34

1 Answer 1

3
\$\begingroup\$

Basically, yes you need to protect any switching device from the inductive kickback.

Yes, the IO pins have internal protection diodes, but they are meant for ESD protection, they are not meant to be used as part of normal operation, that would be considered bad design. On most chips, the amount of injected current would exceed the safe limits.

So the problem is, you should not be driving the relay power directly from the IO pin to begin with, but with a transistor. As per the relay specification, the voltage of the IO pin is not even guaranteed to operate the relay. Even if it seems to work now, it may not be reliable, especially now that the internal ESD protection diode has already had extra burden on it for which it is not designed for.

\$\endgroup\$
3
  • \$\begingroup\$ What type of diode would I need? Do I just need one between pin 17 and the relay? What about between ground and the relay? \$\endgroup\$ May 20, 2020 at 23:38
  • \$\begingroup\$ How do I incorporate a transistor? What's the benefit? Could I replace the relay with a transistor? \$\endgroup\$ May 20, 2020 at 23:42
  • \$\begingroup\$ Those are new questions already, so they should be posted as new questions. However they are so basic and general questions you can find the answer with one minute googling or on this site as already answered questions, like "how to drive a relay with a transistor" or "which diode for a relay", so they might get closed due to lack of own reseaech. Currently, you'd need a schottly diode, in parallel with a relay, not in series. Using a transistor keeps the ESP32 pins safe and operates relay reliably. You should keep the relay to isolate the intercom, if you get it wrong you might damage it. \$\endgroup\$
    – Justme
    May 21, 2020 at 7:57

Your Answer

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

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