Trouble running relay module with esp32

Hello everyone.
(too formal, lemme make it a bit more casual)

5v relay ain't running with esp32!
The 3.3v output of the GPIO pins(of the esp32 of course) is registered a LOW state by the relay.
Hence, I am NOT ABLE to switch it into high mode.
I also tried using a BC547(General purpose NPN BJT Transistor) as a switch, and for some reason, it doesn't work.

These are the two circuits I made. Just assume that the Arduino uno is the esp32 and the PIR sensor is the relay.

But none of them work for some reason.
Any other suggestions would be definitely appreciated

Help

Instead of posting completely irrelevant pictures, why not post a link (Ebay page etc) to your relay module ?

Can you simply not, just to try, apply power to the relay from the +5v / ground terminals of your ESP32 and then try the connecting the trigger (a) to ground and (b) to 5 volt to see if anything happens. Say it clicks or a led switches on.

And whiles you are doing the suggestion from post #1, post the well formatted code in code tags and provide a real schematic, please.

The ESP32 is particular as to which I/O port is assigned to do what things portA and portB are designed for different things.

And, what the heck does this mean, "The 3.3v output of the GPIO pins(of the esp32 of course) is registered a LOW state by the relay.
Hence, I am NOT ABLE to switch it into high mode."?

Sorry, people for the inconvenience, this is just my second post, and this is the first forums where I have posted anything at all and obviously, I need a bit more experience on authoring the question.
Anyways...

6v6gt:
Can you simply not, just to try, apply power to the relay from the +5v / ground terminals of your ESP32 and then try the connecting the trigger (a) to ground and (b) to 5 volt to see if anything happens. Say it clicks or a led switches on.

The relay does work that way(clicks AND the LED powers up), and hence I could confirm that it is a working module.
And here is the link to my relay module.
http://https://www.amazon.in/AusleseTM-Channel-Module-Raspberry-Trigger/dp/B08C7W3B41/ref=sr_1_7?dchild=1&keywords=Relay+Module&qid=1611419404&sr=8-7

Idahowalker:
And whiles you are doing the suggestion from post #1, post the well formatted code in code tags and provide a real schematic, please.

Sorry, Idahowalker, because I am extremely new to this place.
Now,
All I am using is the most simple LED blink sketch.
Here it is:

[code]
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

[/code]
.
The relay is connected the way it is supposed to be:
VCC to Vin(I read a few forums and they say it is OK to draw 5v from the VIN pin, and following them, I went ahead)
GND to GND
Input pin to GPIO-13

Idahowalker:
Hence, I am NOT ABLE to switch it into high mode."?

Okay, lemme elaborate a bit.
When the GPIO pin is in the low state, the relay, as predicted, will have become energized as it does whatever it is supposed to do in the LOW state.
But when the GPIO goes high i.e. 3.3v, the voltage is too low to switch the relay from the LOW to the HIGH state.
I figured out, any voltage below 4v is understood as the LOW state and anything above is considered HIGH by the relay

(I used a variable power supply and the threshold voltage is around ~4v).

In the first diagram, I held the input pin low, and tried using the transistor to switch on and off the ENTIRE RELAY module.
In the Second diagram, I used the circuit of a logic inverter to invert the Signals(which I didn't care about) and also BOOST the input voltage to around 5v(which I did care about), without any success in either of the circuits.
Uh... I wrote this answer in the quick reply mode and don't see any button for attachments.
Okay! The schematic pictures will be in my next reply!

Here are the pictures:

That link does not work.

When using a relay module with a ESP32, I use the relay modules that have built in opto-couplers so that the thing works.

Like this one SunFounder Relay Module for Arduino and Raspberry Pi 5V DC Trigger by HIGHLO (HIGH Trigger)

That relay has this in the description:

Auslese 5V Relay One Channel Module for Raspberry Avr Pic Low Level Trigge
The 5V relay module is suitable for SCM development, home appliance control. It is with 5V~12V TIL control signal which can control DC / AC signal. The module is perfect for common application. - Color: Blue + black - Suitable for SCM development, home appliance control - 5V-12V TTL control signal, can control DC/AC signal - Can control 220V AC load Useful to control a motor, a led strip, or any other module using . How to use it: Just connect a digital output of your to your relay module, and you can control a power-demanding appliance with the digital signal provided by your .

So it appears to need a 5volt trigger voltage.

To switch 5volts using a 3.3volt pin, you need 2 transistors, arranged as a high side switch. Google for transistor high side switch.

Or get another relay which can be triggered by 3.3 volts (those with an opto coupler can work like that) - as @Idahowalker has just said as I was typing.

OP's Relay . . .

relay.JPG

relay.JPG

A relay module with a design similar to this will not function correctly if the trigger voltage is less than the power supply voltage by a margin of around 0.7 volts (assuming the transistor illustrated is a silicon type, of course)

This because it is driven on the high side by a PNP transistor, the base of which is used as the trigger input. It is an unusual design. Normally, such relay modules are driven on the low side with an NPN transistor and, therefore, can operate on voltages above around 0.7 volts.

I guess the OP has a relay like protosupplies design. In which case, a single NPN transistor between the trigger and ground and a base resistor of , say, 1k connected to the ESP32 pin should work.

1 Like

Thanks a lot, 6v6gt
The module you posted is the exact one I have
I did not know what the transistor circuit was called.
As you pointed out, the transistor layout on the circuit board is not favourable.
Anyways, you gave me exactly what I needed.
Thanks a lot.

Just for completeness, this is how you could make that relay controllable from a 3.3v ESP pin.
The complete circuit is a classic high side driver. I've never seen a relay module like the before, where the module has a single PNP transistor. It is very inflexible because, without additional circuitry, the trigger voltage cannot be much lower than the drive voltage.

Hey! Thanks for the schematic, but I can't stop wondering, isn't this circuit exactly same as my circuit 2, aside from the extra resistor at the Base and a different resistance at the collector. WOW man I was close.
I will try it the first chance I get.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.