Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: switch power to LEDstrip using WLED controller and relay: how? #631

Closed
raoulteeuwen opened this issue Jan 26, 2020 · 36 comments
Closed
Labels

Comments

@raoulteeuwen
Copy link

I read a couple of tickets about using a relay, like #301 .

I currently have 2 strips, one with a NodeMCU , one with a Wemos D1 which both run WLED. I'm also using Home Assistant.

I read LED strips still consume power when 'off', so for now, i use a Sonoff Basic (on one strip) and a Tuya-kind of smart plug to totally switch off power to the strip and NodeMCU/Wemos. So my automation from HA basically is: switch on the Sonoff/Tuya, wait a couple of seconds, send any commands to the WLED NodeMCU/Wemos.

This works, but means for every LED strip i need 2 devices. Would it make more sense to connect a relay to the NodeMCU/Wemos, and use the relay to switch on/off power to the LED-strip? What are advantages/disadvantages?

If it is recommended instead of my current config, can someone help me a little? Never used a relay: am i right i need to to run 5v and gnd to the relay, and connecting a pin from the NodeMCU/Wemos (D6) to the relay to switch/control the relay? And connect the LED-strip to the other side of the relay, running either gnd or live through the relay?

How does the software side work? Do the standard bin-files have this option, or do you need to compile your own version to control the relay? How do you control the relay (MQTT-commands, GUI...)?

@Aircoookie
Copy link
Owner

Don't worry, using a relay in WLED is now fully supported and should offer a great replacement for your current setup, which isn't bad, but some simplification would indeed be nice!

Yes, that's true, they use about a milliamp per LED when unlit, which can add up quickly when running more than 100 or so LEDs. Setting it up is quite easy, just get a generic Arduino relay shield like this one and connect its input to GPIO12 (D6).
Advantages are definitely the reduced power consumption (+what you save by not running a second ESP or smart plug), disadvantages are that it only works up to ten amps (the relay rating).

You can choose whether you want the relay to interrupt the LED 5V power line or the live wire to the LED power supply. I would use the former for safety reasons and since you don't need another power supply for the ESP.

Yes, D6 as relay pin is enabled by default in all recent binaries :) The relay operates automatically (turns on when LEDs are on and off a second after lights are fully off), but that is basically all you need, so there is no manual control of the relay possible at this point, it always depends on the WLED power state.

Hope I was able to help and let me know how it goes or if you have more questions!

@raoulteeuwen
Copy link
Author

Will try it somewhere in the future/when i find the time. Thank you @Aircoookie !

@Dreamoffice
Copy link

@Aircoookie is it possible to swap the logic of GPIO12. my relay needs to get ground to power on. actually the D1 mini is serving 3.3 volt on GPIO12 if the LEDs are switched on

@austwhite
Copy link

austwhite commented Mar 1, 2020

The relay can be inverted in the script if you want to compile yourself in the ide.
Either that or get a relay that can be inverted. Some have a jumper that can switch the logic.

@Dreamoffice
Copy link

@austwhite where can i change it? i tried it but no success

@raoulteeuwen
Copy link
Author

(sorry for the long post)
Just checking. I have, for me for the 1st time, tried to use a relay. I'm using a Wemos D1 mini, which has only 1 GND pin. Afaik, i need gnd to run from the PSU to a) the LEDstrip, b) the Wemos, c) the relay (control side). I have now wired up as can be seen in https://photos.app.goo.gl/waCYwMe6zSRF6gyZ6
wled-wemosd1mini-relay
When i connect the plug to a power source, the Wemos boots, WLED starts, the red LED on the relay turns on (green is off) and the LED-strip behaves as expected (doing the sequence i configured in WLED). When i switch off WLED via a browser (pressing on/off button), the LED-strip turns off, and on the relay the green LED turns on (red stays on as well).

On the relay, one wire (from the power supply plug) goes to COMM, and i have a wire running from NC to the LED-strip.

Although everything seems to work, i'm just a little unsure whether i accomplish what my intention with adding the relay is: making sure the LEDstrip doesn't use power when WLED is off. I'm confused by the green LED turning on. I've tried to measure power running over the system with a multi meter, but i'm such a noob with this, that when i tried, i seem to short something, the Wemos turns off, and when i remove a probe, everything turns on again. I've resorted to a smart plug, and i do see low electricity use when the strip is off, just not sure whether it can be even lower (the Wemos keeps being powered off course, and maybe there is a little loss in the relay). I measure about 1W (and 224 V and .02 A). When i, while the LED-strip is on, unplug the wire that enables the Wemos to control the relay, and than switch off WLED, the LEDstrip switches off, the relay does not change state (nor click), and i measure 1.6W (and 224V and .02A).

One more thing i tried to verify correct working: while everything was off (but powered, so the relay should make sure there is no power to the LED strip, the green led on the relay was on), i unplugged the wire from the relay that the Wemos/WLED uses to control the relay. I hoped the relay would retain its state, but when i unplug the control wire, i hear it click, and the green LED turns off.

Can anyone confirm this looks o.k. / seems o.k. / relay probably works as intended :-)?

@raoulteeuwen
Copy link
Author

@Aircoookie one question please: i have a circuit with a relay. When i press the Power-button in WLED, i hear the relay click, the green LED on the relay switches on, the LED strip turns off. Am i right that current D6 behaviour in WLED is to turn on D6 (am i right the correct language is: switch the pin to high?) when WLED is switched off? (when i use the COMM and NO on the relay, the LED strip never lights, so i use COMM and NC)

@Aircoookie
Copy link
Owner

@raoulteeuwen I just checked in the code and the default behavior is to turn D6 on (high) when the LEDs are on and off (low) when the LEDs are off. It can be changed though with the RLYMDE define in NbpWrapper.h. Many relays are powered when the signal is LOW, so that is probably the case for you.

@raoulteeuwen
Copy link
Author

Tried to compile from master (haven't done that a lot, but was able to compile without errors, so seemed ok). Change RLYMDE from 1 to 0 in NbpWrapper.h. After uploading, the Wemos started to flip flop its blue LED every 1.5 sec or so, i heard a relay kind of click every time, but this made the whole config unaccessible. So went back to the compiled bin and leave it like this for now (is working fine, just now using the NC port on the relay, which means WemosD1 with WLED is powering the relay when WLED is off: would rather had it the other way around ... will look into another relay as well)

@Aircoookie
Copy link
Owner

Just tried it and RLYMDE 0 seems to work fine for me, rather I believe that you are having bootloops with the version you compiled. Here is a rlymde 0 binary, you can try if that works :)
https://drive.google.com/open?id=1TgOx3Va1OA2GBNZmgMgoSj0cJufyjEeq

@raoulteeuwen
Copy link
Author

Guess you were right, and that bin works, thank you, i can now use the NO port, and the relay only gets powered when WLED is on. Buying you a <beer/coffee/tea...>. Will search what could cause that boot loop (bad flash, wrong baud rate...)

@Aircoookie
Copy link
Owner

Awesome, thank you for the coffee :)
Actually the most common cause for bootloops is Lwip 2, which ist the default in Arduino IDE. It works best if you use these settings: https://github.com/Aircoookie/WLED/wiki#compile-settings
If you are already using them, maybe a library is outdated or the flash layout is wrong...

@Warsenius
Copy link

reversing the relay pin might be a nice feature to have a checkbox for in the webinterface.
since triggering the relay also takes a bit of power if depends if your relay is on or off most of the day what is most efficient per case.

@Chaosflori25
Copy link

Could you reupload a binary for 10.2 again? @Aircoookie I tried to compile it but it did not work and after 2,5h I can't find anything that I can change for it to work. Thanks a lot in advance.

@Aircoookie
Copy link
Owner

@Chaosflori25 here you go (assuming you were asking for a ESP8266 binary with RLYMDE 0)
https://drive.google.com/file/d/1BuXCWeDjRP9R8om7s3zuceRMQfFvbhug/view?usp=sharing

@fpovoski
Copy link

I was wondering if there is a built-in delay from the time you fire GPIO12 for the relay until you actually start pushing data to the LEDS. Reason is this; when using high led counts and a large supply you actually want to switch on that supply (separate small supply for ESP of course) at mains which takes some time to ramp to nominal voltage. This eliminates the "idle" draw of about 15 watts of a large supply being on continuously, plus of course "idle" current of the LEDS. Otherwise you see strange behavior on the undersupplied string until supply ramps. By the way, very nice software but in my initial testing last year on my current hardware which is very reliable using my custom software I was getting some undesirable "flashing" effects with WLED. But I shortly will be taking one unit offline and will give WLED another test. Thanks and I'll keep you updates

@Aircoookie
Copy link
Owner

@fpovoski no, there isn't yet but I agree that at least like 50ms are needed for the power to stabilize before sending data. There is an FR for this: #346

For getting rid of the flashing, you'll most likely need a level shifter to convert the 3.3v data signal to 5v. If your own software doesn't exhibit this flashing, it is probably either running the LEDs at a higher brightness (causing voltage drop and the voltage differential between LED supply voltage and data signal voltage to lower, thus making the signal readable to the LEDs) or at a lower framerate than the 42 fps WLED uses for most effects.
https://github.com/Aircoookie/WLED/wiki/FAQ#reason-2

@fpovoski
Copy link

fpovoski commented Sep 28, 2020 via email

@mortenx
Copy link

mortenx commented Jul 2, 2021

Where can i see relay button in wled app?

@Aircoookie
Copy link
Owner

@mortenx you can set the Relay pin and mode in LED settings/Hardware Setup if you are running WLED 0.12.0 or newer.

@snorrebot
Copy link

snorrebot commented Jul 9, 2021

Hi all, i'm also struggling with the 5v relay. Would be wonderful if someone could help me out...

  • relay is properly connected with pin d6 (see attachment)
  • in the settings menu I entered the right pin for the relay
  • I press ON in the app and the relay clicks nicely to on.
    - I press OFF and the relay stays on, nothing changes.

The D6 pin just hangs with the ON signal, even after a restart of my ESP. Only when I change the relay pin in the settings menu to a different pin, I can start over and turn ON the relay, but again I can't turn it off. It feels like a software problem but I can't figure it out....

Thanks for your help!

scheme

image

@raoulteeuwen
Copy link
Author

Hi all, i'm also struggling with the 5v relay. Would be wonderful if someone could help me out...

Just checking: if ON, does WLED still work, and does it change your LED-strip? Did you try to change the wires on the relay to check whether NC/NO is making any difference (only needs 1 wire changed on the output side)? Does wiring the relay with ground directly from the power supply make any difference?

@snorrebot
Copy link

Thanks for your quick response!

  • if ON WLED works as it should, ledstrip works as intented
  • I changed between NC and NO, NO did not work
  • all the ground cables are connected in one chain together to the power supply

@snorrebot
Copy link

No one? It feels like a software bug because the D6 pin for the relay just keeps the ON signal forever . If I remove the cable from pin D6 my relay immediately switches off as it should...

@RichieRich69
Copy link

RichieRich69 commented Jul 30, 2021

Hi @snorrebot, I had a similar issue a while ago. Turns out hyperion/ledfx was keeping WLED on despite it not showing streaming on the UI. Your wiring looks okay. Also test the relay separately, I had a defective one too. Finally the latest version has a pull high / low in the config it's worth trying both.

@ChuckMash
Copy link
Contributor

@snorrebot I ran into this exact issue, with this exact (or extremely similar) relay module.
I was able to solve the issue by adding a 4.7K ohm resistor between D6 and the relay input.

I'm not terribly sure why this was necessary for this relay module, so I ended up selecting a different "higher quality" relay module that didn't have this problem.

@blazoncek
Copy link
Collaborator

The relay module in question is a 5V relay, taking 5V logic as input. This is important since ESP can only provide 3.3V.
This module also features negative logic whic means that relay is switched off when input pin is HIGH (5V).

What you need to do is add simple MOSFET between D6 and relay input. Don't forget to add 10k pull-down resistor to D6 and 4k7 resistor between 5V and drain on MOSFET, connect source to GND.
I can recommend 2N7000 as a good choice for MOSFET.

@snorrebot
Copy link

Thanks ChuckMash and blazoncek for the great options!
@ChuckMash do you have a model number or link for your working relay module?

@blazoncek
Copy link
Collaborator

Another option is to use level shifter in the same way as for LEDs.

@ChuckMash
Copy link
Contributor

@snorrebot The 5v Relay module by HiLetgo.

@Jemago
Copy link

Jemago commented Sep 1, 2021

Hi. First of all, sorry for my English.
I've had similar problems and in my case , the problem has been the config in the app.
There is a option where you can choose the pin for the relay. For default, these option is -1, and you must change this, por example to 12, if you want D6 for you take control of the relay.
This option is in led preferences below of the output pins....

@supss
Copy link

supss commented Sep 14, 2021

hello all, great to see relays being supported, but is there a way to also have an external switch (like a momentary switch). logically this would be considered a 3 way setup so that the LEDs can be toggled by both the UI and the physical switch?

@blazoncek
Copy link
Collaborator

hello all, great to see relays being supported, but is there a way to also have an external switch (like a momentary switch). logically this would be considered a 3 way setup so that the LEDs can be toggled by both the UI and the physical switch?

These are supported as well.

@vxav
Copy link

vxav commented Mar 5, 2023

Don't worry, using a relay in WLED is now fully supported and should offer a great replacement for your current setup, which isn't bad, but some simplification would indeed be nice!

Yes, that's true, they use about a milliamp per LED when unlit, which can add up quickly when running more than 100 or so LEDs. Setting it up is quite easy, just get a generic Arduino relay shield like this one and connect its input to GPIO12 (D6). Advantages are definitely the reduced power consumption (+what you save by not running a second ESP or smart plug), disadvantages are that it only works up to ten amps (the relay rating).

You can choose whether you want the relay to interrupt the LED 5V power line or the live wire to the LED power supply. I would use the former for safety reasons and since you don't need another power supply for the ESP.

Yes, D6 as relay pin is enabled by default in all recent binaries :) The relay operates automatically (turns on when LEDs are on and off a second after lights are fully off), but that is basically all you need, so there is no manual control of the relay possible at this point, it always depends on the WLED power state.

Hope I was able to help and let me know how it goes or if you have more questions!

Hey @Aircoookie, you mention that it’s safer to interrupt the led power line as opposed to the psu live wire. Why is that? I would have assumed the opposite.

@nightshade00013
Copy link

Hey @Aircoookie, you mention that it’s safer to interrupt the led power line as opposed to the psu live wire. Why is that? I would have assumed the opposite.

Well since most people are powering with the same PSU for both the ESP and the LED strip removing power from the PSU input would effectively shut everything off. So if it turns off then it's off and it likely wouldn't turn on again unless you use something like the Adafruit Huzzah32 which has it's own onboard battery, but if the battery dies then it won't turn on unless you modify the software to include battery monitoring. And remember that having 2 psu's you still have to unify the ground lines anyway and that will potentially cause issues if one PSU is on and powering the ESP and the other is off.

Just removing the power from the LED strip saves a good amount of power use. If you really have to have ultra low power then put everything on a wall switch and manually turn it on and off. I have my 1242 LED strip setup this way so that I can reboot without much effort, just turn off the switch and turn it back on. I am also using the same PSU for an ESP8266 that I use for a few other functions with my HA install as well.

@glebmiller
Copy link

Hi all, i'm also struggling with the 5v relay. Would be wonderful if someone could help me out...

  • relay is properly connected with pin d6 (see attachment)
  • in the settings menu I entered the right pin for the relay
  • I press ON in the app and the relay clicks nicely to on.
    - I press OFF and the relay stays on, nothing changes.

I had the same problem, solved it by powering relay from 3.3v, seems that the relay only works when both IN and VCC has same voltage. (GPIO from esp or nodemcu gives 3.3v)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests