Simple Circuit Help - D1 Mini and a Relay

I’m trying to control a simple 5v strip of dumb LEDs with this relay and a D1 Mini flashed with ESPHome 2024.12.2. My circuit diagram is below.

Nothing I do will make the LED strip light up via the relay. It lights if I plug both legs into the breadboard where the 5v comes in. I can toggle the relay via HA with no issues. Put the relay in line? Nada. I’ve tried it with

I’m hoping it’s a simple wiring issue, but for the life of me I can’t find the problem. Would really appreciate some extra eyes on this one.

On the relay: put a jumper wire between DC- and COM.

No change, unfortunately.

There’s got to be a loose connection either on the screw terminals of the relay or the LED stip. You can hear the relay engage, right? Check the polarity of the hookup on the LED also.

What does this mean?? You can toggle some HA icon or the physical relay?
There are two issues on your circuit, already mentioned missing wire between COM and DC-
And the fact that normal (low trigger) 5V relay module doesn’t work with 3.3V trigger.

You need either additional transistor circuit there or 3.3V relay or relay with separate coil power and trigger, which you can often identify from pin labeled “JD-VCC”.

Edit: I saw your link for your relay. You can try by moving the high/low jumper to another position. It’s a question of luck if it works because it’s not built for 3.3V trigger and in every case it’s abusing your Esp boards max pin voltage and eventually damaging it.

I assumed OP had the relay triggering already. That relay will trigger on low if the selector on board is changed.

Thank you both for the replies!

I can toggle the physical relay via HA. Click the switch on the screen in Home Assistant and the relay engages/disengages in real life.

So to keep this as simple as possible, I guess I need an ESP with 5v pin voltage to go with a 5v relay and my 5v LED strip? Or does the relay voltage not need to match the LED strip voltage?

The ESP is simply switching on/off your GPIO12 and you can hear it clicking on and off, right? This sets 3.3v on or off on that pin. Perhaps “inverted” is an issue based on the YAML you haven’t posted?

You should set the level trigger on the relay board to low not high even if it is working - the GPIO is 3.3v not 5. It the relay works without the LED attached then follow the circuit through to the LED.

If the Relay is successfully turning on or off then it’s a simple matter of completing/interupting the power circuit to the LED. You have 5v+ wired to the LED according to your diagram. The relay supplies on/off negative based on DC–>COM and NO being closed or open in your diagram assuming you’re supplying negative to COM.

Mine does. You can’t drive a 5V relay coil with 3.3V GPIO, but the relay module likely has an optoisolator driven by a ground on the in pin.

OP, your rambling doesn’t make one thing clear. Can you hear the relay clicking?

I have one also that works, but mainly they don’t.

Sinking 5V on Gpio pin…And when you drive the pin high, there is still 1.7V and the relay might or might not turn off.

Use a pullup. 10KΩ should do it.

Seriously?

Yes, but only if jumper is set to high. When jumper is set to low and I toggle it via Home Assistant nothing happens.

It’s worth noting that, with identical connections to power/ESP, multiple relays from the same box behave differently. One audibly clicks with the jumper on either high or low. One clicks only on high, and the other doesn’t click at all but the LED indicating the relay status brightens and dims.

In no case, however, does the LED strip I’m trying to power light up.

I’ve ordered some 3.3v relays and will try them when they come in. Something’s definitely screwy here but I don’t think I’m the entire problem.

Thanks again for your assistance, everyone!

Yeah, it sounds like you have some funky relays. Return them to Amazon and I’m sure you’ll be fine with the next batch. Just remember that COM and NO carry one leg of your LED current, the other leg is directly connected (per your diagram).

If you are getting 3.3v relays you can not use a jumper from the power to the relay to COM. You will need to supply 5v to the COM terminal and then the NO terminal on to the 5v LEDS.

You got this.

1 Like

Unfortunately, there is no schematic for the relay board and there are different ways it could be wired on the board. It does appear to have a transistor to drive the LED in the optoisolator, so that is good. Looking at the pictures, it has: 5 resistors, 2 LEDs, 1 transistor, 1 diode, and the relay. The resistors are 2k2, 1k0, and 10k. The 2k2 resistors are likely for current limiting for the LEDs. The transistor is a PNP transistor. The 1k0 and 10k resistors are for the transistor that drives the relay. The optoisolator has an LED inside it. My guess is that when you set it for active low one side of the LED is connected to +5V (coming into the board) and when you set it to active high, it is connected to gnd. The optoisolator must have two LEDs in it so it works with either polarity. This means you should be able to use it either way. The gpio pin is driving an LED NOT a digital input, so it should work either way. The Internet says the esp32 can source or sink at least 12mA on a gpio pin in output mode, so should be more than enough to drive the optoisolator.

If the relay is clicking and the light on the relay board is on (both when the relay clicks on), you have that part of the circuit correct.


this is the schematic from a similar relay board.

looking at the schematic, I would set it up to be active HIGH. This will ground one side and the other side of the optoisolator LED will be connected to the GPIO pin.

If you make it active LOW, one side is hooked up to 5V and the LED might turn on with even 3.6V on the other side, since the forward voltage drop of the LED is only a maximum of 1.4V (typically 1.2V).

Yes, but it doesn’t change the fact that in “low side mode” it’s sinking 5V to Esp gpio, which is rated to max Vcc+10% (3.6V).

The common problem with these (on top of the gpio abuse) is that when gpio is set high, there is 1.7V across the optocoupler, enough to keep it on. So it never turns off.
One could simply use NPN to drive the relay correctly:
relay-fix-3.3V

Hence the reason I said to use active HIGH mode. The boards I have are not switchable and only support active high.

However, since the jumper provides access to the other side of the optoisolator LED in the OP’s board, if you want active LOW, just remove the jumper and provide 3V3 from the esp to it. Problem solved.

That’s correct.
I forgot the jumper again…

1 Like