I need to use the ESP32 to trigger a SPDT relay. The output of a single pin is insufficient to surpass the relay's threshold. Can I combine multiple pins to achieve greater voltage?

This microcontroller is commonly powered by 5V from USB, but in my case it's getting 9V DC from a wall wart, so hopefully its "upstream voltage" isn't a problem here.

  • 4
    \$\begingroup\$ How would you hook up output pins in series??? \$\endgroup\$ – Ron Beyer Jan 6 at 23:40

No. You cannot add in series signals which have the same ground.

But even apart from that, you cannot power a relay with an MCU output pin.

You need to use a transistor or FET to amplify the output of the MCU into the power needed to activate the relay, along with a backwards diode to catch the turn off kick. Most commonly this is done in the form of a low side switch; some off-the-shelf solutions additionally introduce an optocoupler.

There are many, many questions here showing suitable setups, and some of the complications which can result.

  • \$\begingroup\$ "you cannot power a relay with an MCU" Evidently you're wrong, I can flip a OJE-SH-1050W I have laying around no problem with an Arduino's output pins (5v). \$\endgroup\$ – armani Jan 7 at 1:08
  • 2
    \$\begingroup\$ You're probably confusing a supply pin with an I/O, but if you're not, you're grossly violating the absolute maximum ratings of the ATmega in a way likely to lead to early failure. It is most definitely not a sound practice. \$\endgroup\$ – Chris Stratton Jan 7 at 1:39
  • \$\begingroup\$ Terminology aside, my relay has 4 pins. 2 are connected to load (e.g. 110v mains), 1 to Arduino GND, 1 to some GPIO pin that gives 5v when issued digitalWrite(pin, HIGH); If that isn't clear let me know. \$\endgroup\$ – armani Jan 7 at 2:40
  • 3
    \$\begingroup\$ @armani that is clear and that is the wrong way to connect it. Powering a relay directly from a GPIO pin exceeds the limits of safe operation. If the MCU is not damaged yet, it might soon be. \$\endgroup\$ – Justme Jan 7 at 9:06
  • \$\begingroup\$ @Justme If a relay has a coil rating of 5V and an MCU's GPIO pin is measuring 5V using a multimeter, how can this be "exceeding the limit?" \$\endgroup\$ – armani Jan 7 at 23:09

You can't put IO pins of a single MCU in series, so greater voltage is unachievable. IO pin also do not provide enough current anyway to drive a typical relay coil, so you need to drive a transistor with the IO pin, and let the transistor drive higher currents and/or voltages of the coil.

Just to make sure, the OJE-SH-105DW relay coil is rated for 55.6 ohms, at 5V, which is 450mW, so it would like to consume about 90 milliamperes.

For comparison, the Arduino 5V GPIO pins are rather strong, but they still have absolute maximum rating of 40mA, which is a limit that must not be exceeded during normal operation to prevent immediate or long-term damage.

It has an electrical specification that guarantees that the GPIO pin can provide 20mA under normal conditions, and voltage will have dropped to about 4V at that current. The tiny transistor providing the current will then heat up at 20mW, so only 80mW is provided to your load.

Beyond the guaranteed 20mA, the circuit is not guaranteed to work, it may or may not work depending on manufacturing tolerances, temperature, supply voltage, etc, and it would heat up the tiny transistor too much.

The 5V you are measuring from GPIO pin must be without load, I'd expect it will be much lower when the relay is connected.

  • \$\begingroup\$ "IO pin also do not provide enough current anyway to drive a typical relay coil" -- I can flip an OJE-SH-1050W from an Arduino's GPIO pins (5v) no problem. \$\endgroup\$ – armani Jan 7 at 1:08
  • 2
    \$\begingroup\$ @armani The OJE-SH series is far from a typical relay, it has very low coil current. Even then, the 5 volt one requires 40 mA coil current, which is right up at the limit of the ATmega328P, certainly stressing the microcontroller far more than I would want to. \$\endgroup\$ – Hearth Jan 7 at 1:55
  • 3
    \$\begingroup\$ I can flip an OJE-SH-1050W from an Arduino's GPIO pins (5v) no problem ... will it be a problem for you if the Arduino becomes an expensive fuse? \$\endgroup\$ – jsotola Jan 7 at 2:33
  • 2
    \$\begingroup\$ No, you can't step up the voltage, as the IO pins are not meant to deliver power to begin with. The IO pin is simply used to control a transistor, which in turn can drive the relay from a higher voltage/current/power supply, like 5V or 12V. \$\endgroup\$ – Justme Jan 7 at 8:35
  • 2
    \$\begingroup\$ @armani "5V" is not "power", it's voltage. IO pins can't give out much current, as they are not meant to drive high power loads. MCU supply pins can't tolerate much current through them either, as they are meant to power up the MCU itself, not high power loads on IO pins. An Arduino IO pin gives out 5V only when no current flows. When 20mA flows out of IO pin, voltage has dropped to 4V. Within safe limits, you can draw 20mA out of a single pin without exceeding manufacturer limits for normal operation. If you exceed that, it may not get permanently damaged, but it does not have to work either. \$\endgroup\$ – Justme Jan 7 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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