Relay module doesn't work on esp32

Hello, I bought an Arduino ESP32 on AliExpress. I'm doing some projects but I can't use relay modules when I give digitalWrite(PINRELAY, HIGH) or digitalWrite(PINRELAY, LOW). The relay module doesn't make the transition. I don't know if I'm using the wrong board in the IDE or if I have to use a specific relay. The board I bought is this one:
https://pt.aliexpress.com/item/1005004605399313.html?spm=a2g0o.order_list.order_list_main.44.2e38caa4LmzxfX&gatewayAdapt=glo2bra
And the relay module is this one:
https://pt.aliexpress.com/item/1005005622532797.html?spm=a2g0o.order_list.order_list_main.21.2e38caa4LmzxfX&gatewayAdapt=glo2bra
5V option

Welcome to the forum

The ESP32 outputs 3.3V but the relay that you bought is the 5V model

Do you think that could be a problem ?

The ESP32 uses 3.3V output logic levels.

So there might not be enough volts on the GPIO pin to trigger a relay that needs 5V.

yes, but is this module necessary to have a 5v signal? or will it only be necessary to power the module with 5v?

Connecting that 5V relay to your 3.3V ESP could damage the ESP.
You will a transtor to drive the relay.

ahh ok, so I can't use this module with the arduino esp32?

Both

Yes you can

how can i use?

Hi @pretoet , Welcome,

Please remember the ESP32 outputs are 3,3V, some of those relay modules are 5V, at least the VCC for driving the relay coil.

So be sure to connect the VCC to a +5V source, not a 3v3 source. The signal pin (IN) is supposed to work for lower voltages, the 3v3 pin outputs of the ESP32 will be enough, that must not be a problem.

Good Luck!

Gaby.//

Github: /GabyGold67
bool supercalifragilisticexpialidocious{true}: error - wrong variable name
bool superCaliFragilisticExpialiDocious{true}: 0 errors - 0 warnings

Please and thank you, they're the magic words

You nee one resistor and one transistor like this:
Connect relay Vcc to 5V.

Do not connect the relay IN pin directly to the ESP, you may damage the ESP.

Hi @pretoet ,

The 5v is for the module working, for the signal the 3v3 is enough.
More, if the module is being powered from the USB connector, you can drain 5V from the 5v pin used for Vin of your development board... depending on the current required. I've done it, it worked for me!

Gaby.//

Hi @jim-p ,

Your's the safe way to go, but I've done it and worked with no problems, as long as the drain is low...

Gaby.//

It is NOT the safe way to go. You are applying 5V directly to a pin that is NOT 5V tolerant. It may work for a while but eventually the pin or entire ESP will fail.

The safe and correct way is to use a transistor interface as I show.

The ESP32 will output 3.3V to the relay input pin so I don't understand what you are saying

Hi @jim-p ,

I quoted you and added that YOURS was the safe way to go... I'll edit that publication... sorry if I was misunderstood.

Gaby.//

The relay is a low level trigger with no optoisolator. So the base of a PNP transistor is connected to the IN pin and the emitter is connected to 5V. So 5-0.7V will appear on the IN pin

I did this but it didn't work

Hi @pretoet ,

Then I believe more information will be needed, is your pin setup as Output done, the exact connection diagram, etc.

Once I used some of those modules with an extra jumper used to disconnect the coil, so to test the code, checking the leds but avoiding the coil activation, once it came high level activated, once low level activated... If you have a breadboard and a breadboard power header try the module alone by itself using cables.

Gaby.//