How do I get my relay to trigger?

Hi all!

I am troubled by this conundrum -hope I can get your advice on what I am doing wrongly.

Objective: Getting LED 1 to switch on & off for 5s each using a relay

Problem:
My relay does not trigger, with LED 1 being continuously on.
Whereas LED 2 switches on & off for 5s each, despite being on the same circuit.

Equipment: ESP32 dev board x1; 220 Ohm resistors x2; LED x2; 5VDC Relay x1

const int relay = 5;

void setup() {
  Serial.begin(115200);
  pinMode(relay, OUTPUT);
}

void loop() {
  digitalWrite(relay, LOW);
  Serial.println("Current Flowing");
  delay(5000); 
  
  
  digitalWrite(relay, HIGH);
  Serial.println("Current not Flowing");
  delay(5000);
}

Appreciate your assistance and advice!
Thank you!

What voltage does the relay require to turn on ?
What voltage does the ESP board output ?

According to https://www.generationrobots.com/media/JQC-3FF-v1.pdf:

  • Pick-up Voltage = 3.80V

  • Drop-Out Voltage = 0.5V

ESP32 board output:

  • VIN pin = 5V

  • GPIO 5 (HIGH) = 3.3V

  • GPIO 5 (LOW) = 0V

Your ESP32 outputs 3.3V. But your relay needs 5V. You will find more details regarding this issue here: ESP32 Relay Module - Control AC Appliances (Web Server) | Random Nerd Tutorials

Can you see a possible problem here ?

There is also the question as to how much current the relay requires to operate and how much current an ESP pin can safely supply

Appears to be a dead link. Try again?

Never mind, remove the colon at the end. https://www.generationrobots.com/media/JQC-3FF-v1.pdf

Yes. Connecting a 70 Ohm relay to an ESP output.

But it isn't the relay cited, is it? It is a relay module. So let's have a little sense here and tell us what the module is? :roll_eyes:

It works if you take the colon off the end

I - kind of mentioned that! :grin:

@UKHeliBob @Paul_B
Thanks for responding guys!

Ahh, I did not realise that a relay module may have different attributes from a relay.
Unfortunately I do not have the datasheet -currently requesting one from the seller.
Will update here once I get it.

@Paul_B
Sorry could you share with me the implications of connecting a 70Ohm relay to an ESP output?

@tepalia02
Thank you -I have looked through the guide on the webpage.
They did mention that:

"A relay ... can be controlled with low voltages, like the 3.3V provided by the ESP32 GPIOs and allows us to control high voltages"

And the example they provided used a 2-relay 5VDC module.
With similar code and setup as theirs, shouldn't a 3.3V output (from ESP32) suffice?

Tried disconnecting LED2's resistor?

Perhaps a picture of the relay module?

@runaway_pancake
Hello! Thank you for helping me look into this.

Tried disconnecting LED2's resistor?

No, let me try that when I get home tonight -will update the results here.

Reference Link

OK, so that was somewhat confusing. :grin:

What you meant was that the relay is always on or in fact "triggered" and illuminating your "LED 1".

This is a "low level trigger" relay module and when powered from 5 V (as it must be), connecting its "IN" terminal directly to an ESP I/O means that the "IN" terminal is always LOW since 3.3 V is lower than 5 V. :astonished:

Just connect LED 2 - with no resistor - between the ESP I/O pin and the relay "IN" - with the LED anode to the relay module. :+1:

I think one of the board's LEDs is for VCC present and the other is likely an Input indicator (no external LED required).
It also looks like it has a transistor there (common emitter? IDK), not an opto-device.

I use these kind/types of relays with ESP32's.

Yeah, its low level trigger.
The transistor is PNP switching the high side of the relay coil. Below I've highlighted the path of VCC to the PNP to the relay coil +''ve terminal on the PCB:

image

The base transistor is 1K.

Possible solution:

I suggest trying this with an LED to drop the relay "IN" voltage ... LED anode to IN, LED cathode to ESP32 output pin. The LED will illuminate and the relay should energize when the ESP32 output pin goes LOW. Use Vin (5V) from ESP32 connected to relay module VCC

1 Like

As per #14. :+1:

1 Like

Actually it depends on which relay module you use. Is the relay board as same as the board used in the tutorial? Some relay boards. Some relay boards have in built logic level converter. They can trigger at 3.3V from ESP32. But for the other ordinary relay modules, logic level converter must be added as shown here: ESP 32 Connect 5V Relay via Logic Level Converter (ESP32) - YouTube

1 Like

Ah, OK. When I initially read #14 I thought it implied that LED2 was on the PCB. No problem, just an external LED will do the trick.

Late to the party, but fundamental question - can you in fact use the "VIN" pin on that device as an OUTPUT? Because unless there's more to your circuit than shown, that's what you're doing.

As for the 5V, 3.3V discussion, here's a different viewpoint. When the GPIO connected to the relay is not "LOW", i.e. not sinking current, it is driven "HIGH"; but, it is exposed to the voltage attached to other devices at it's output. That voltage will be 5V, assuming you resolve my first question successfully. Is that 5V acceptable to the output ratings of the 3.3VDC GPIO pin? IIRC, they're not tolerant of voltages exceeding the supply voltage of the device, in this case 3.3 VDC.