I’m trying to follow a tutorial online for using a 5V Relay and the D1 mini to power a fireplace on. I can’t figure out why they’re using tons of code and MQTT when you can accomplish the same in ESPHome with minimal code.
That gets to my question here, why won’t my 5V relay flip on and of using this code found on the ESPHome website?
switch:
Yep - you’re right - that’s about all you’d need.
Just be sure you get that relay, because it’s actually more than just a relay.
It’s got a driver transistor inside, among other things, that enable it to accept a logic-level input signal.
Powering an ordinary relay coil using a GPIO pin is likely to ruin the GPIO pin, if it works at all, because the GPIOs aren’t designed to supply the kind of current a relay coil needs (nor the backlash current when power is cut).
So, even though a plain old relay might be found for many fewer dollars, it’s crucial that you use one that has a logic-level input, like the one shown in that page you linked to.
Yes, that is the relay I’m using. It powers on (light on), but with my code above it doesn’t toggle on/off when I flip the switch in HA. I thought additional code might be needed but guess I have a different issue, perhaps the signal from the D1 pin isn’t sending the signal
Tried this, didn’t work. I put a multimeter on the D1 Mini, the 5v pin is getting about 4.57volts, and the D1 pin is getting about 2.2v and is toggling on and off as I toggle the switch, but the relay isn’t doing anything. Perhaps the relay is defective, I’ll order another one.
Before ordering another relay, I’d check that your power supply is up to the task.
Those voltages appear to be far below what they should be.
It is possible that your supply is too weak to support the load of both the ESP and the relay (when it’s activated). Try a more beefy power supply before replacing anything else.
Hi,
I have the exact same relay and using the D1 Mini. If relay is connected to 5V the D1 output pin will always trigger relay. If I connect relay to 3.3V VCC, then it will work as normally with the exact same code as you use here. But when connecting VCC to 5V it will just trigger the relay all the time.
If I change the code to be pin D3 and put the wire there, then it will stay low and not trigger. But as soon as the code uploads it will be forced high, and inverting the pin als does nothing. Why is this?
I found a solution:
OK, now for that particular relay module, you need to connect its Vcc to 5 V (not 3.3), its “GND” to your WeMOS ground and its “in” to the anode of a LED whose cathode goes to the WeMOS output pin. Without the series LED the relay will not turn off .
Eficaz y simple!!. It’s a great solution.
Ahora otorgamos más de 4V. (4.37V aprox.)
It must be taken into account that it is only a solution to power certain devices: relays, motors, LEDs. But not switches since the board will not be able to absorb them.
info: Configuration Types — ESPHome
So this was bugging me because I could see the green LED flickering and I could actually hear some noise coming from the relay when it was turned off. After some research I found this article.
Basically the relay power voltage and control voltage should be the same. So powering with 5V and sending a 3.3V control signal as the ESP32s do on GPIO is causing the issue where the relay doesn’t turn off. There are a couple of fixes according to the article but the simplist is to power the relay with the 3.3V pin instead of 5V. This configuration does draw a little more amps, but when powering this way you no longer need the “open_drain” option.
My noise and flickering are now gone and the relay works as expected.