ESP32-GATEWAY / ESP32-EVB to control 5v relay

Started by oleole, October 22, 2020, 02:43:20 am

Previous topic - Next topic


October 22, 2020, 02:43:20 am Last Edit: October 22, 2020, 03:35:27 am by oleole
so I need to control 8 channel 5v Relay Module via board connected with Ethernet.
My question is: would you suggest to use ESP32-GATEWAY / ESP32-EVB for this purpose? Or maybe some other board (INDUSTRIAL)?

I need to run it with no external power connected to relay other than 5v output pin. The board would be powered with usb/power socket.
Will that work?


October 22, 2020, 08:18:44 am #1 Last Edit: October 22, 2020, 08:49:52 am by LubOlimex
Sure it would work. Depending on the relays typical problems with relays should be expected. Whether you get industrial or commercial version would depend on the temperature around the module. We even have ESP32 evaluation design with relays already on-board, maybe use as a reference:

We have published some relay examples for both ESP32-GATEWAY and ESP32-POE. For the ESP32-POE the relay demo uses Olimex MOD-IO extension board that has a four relays. The MOD-IO board is here:

and the ESP32-POE + MOD-IO example here:

Technical support and documentation manager at Olimex


October 24, 2020, 11:19:40 pm #2 Last Edit: October 24, 2020, 11:21:30 pm by oleole
Thank you LubOlimex for your reply.
In the end I bought both ESP32-Gateway and ESP32-EVB for my evaluation purposes.

The problem I have now is that it's not exactly working as I expected:

I managed to get relay to work with a few some of GPIOs (2, 4, 12) but not all. I need 8 of them - which else can I use?.
Built in relays and GPIOs (32 & 33) work as expected.

I tried to use many of them, but found none working (GPIO 2,4,12,32 etc.). Which of the GPIOs should I use (no SD card in use) - I need 8 outputs to relay in total.

I power it from USB 5V, 2.1 A.
Any advice will be appreciated, thank you.


For ESP32-GATEWAY there are probably 8 free GPIOs if you don't use the SD card, refer to this document to locate them:

If you have trouble setting these free pins - maybe something in the hardware connection of the relay, use the schematic of ESP32-EVB as a reference on how we have connected the relays. Consider that the relays you use might be different compared to the ones we used. If the hardware connections are similar maybe it is something in the software.

I am not sure if there are 8 free GPIOs on ESP32-EVB, the board is already packed with a lot of hardware and it is meant for evaluation of the ESP32's capabilities.
Technical support and documentation manager at Olimex


October 27, 2020, 01:46:32 pm #4 Last Edit: October 27, 2020, 02:43:29 pm by oleole
Ok. Let's focus on ESP-32 GATEWAY then.

My setup: 5v output, GND in hole no 2.


int relay = 4;
int light = 33;
void setup() {
pinMode (relay, OUTPUT);
pinMode (light, OUTPUT);
void loop() {
digitalWrite(relay, HIGH);
digitalWrite(light, HIGH);
digitalWrite(relay, LOW);
digitalWrite(light, LOW);

Unfortunately not only relay is not activated but also it loses PWR when GPIO is High.

I have checked it with two ESP32-Gateways and 2 different relays.
Testing similar code on Arduino - all works.


Well, thanks for the video - the issue seems clear - in ESP32-GATEWAY, the +5V_EXT pin is only input (e.g. to power the board using it); it is not output - you can't power things from it.

Try with the ESP32-EVB, the +5V there can be used to power boards.
Technical support and documentation manager at Olimex


Also even if the powering works I would not recommend powering 8 relay board via any ESP32 board... This would lead to some major glitches during switching and might influence the onboard wifi and whatnot other typical problems when using electromechanical relays.

Consider powering the relays from another source.
Technical support and documentation manager at Olimex


Thank you for both, that makes sense.
I will check with external power source once I find it.

In a meantime - EVB works (checked few pins).

Many thanks for your support LubOlimex!

And last question - how can I understand from schematics that 5V in Gateway is intended for input only?



October 28, 2020, 08:54:37 am #8 Last Edit: October 28, 2020, 09:05:09 am by LubOlimex
It is easily traceable even in the PDF here:

Download the PDF and you find on the page 5V_EXT and see it goes at the wrong side of the FET2 - top left corner of the schematic.

Make sure to compare that power part of the schematic of ESP32-GATEWAY and ESP32-EVB to see the differences. You see in ESP32-EVB's schematic signal +5V goes to the other side of the transistor.

It is also mentioned in the pinout diagram, albeit a little bit convoluted, under the top header (where powering options are described):
Technical support and documentation manager at Olimex


Thank you LubOlimex for your your kind and quick support.
I do understand the schematics now. Also, I'm confirming using external power source for relay solved the issue for me.