I’m using a two-channel relay, I used this following code, I configured the two D5 buttons for channel 1 and D7 for channel two. Everything works well but when you restart the NodeMcu channel 1 (D5) remains accessed. How can I make sure that at both reboots both channels are off ???
I suspect you will need to look into the use of virtual pins.
What type of board are you using? Some of the esp dev boards have pins boot in a certain state as to make sure the ESP will boot in the correct configuration.
I had to set the command: digitalWrite (14, HIGH) with LOW were accessed. Maybe they work the other way around. Attach code that works for other forum users.
I have exactly the same issue, can someone suggest a link of the High level relay? I looked up alliexpress and was not able to figure out which is the correct relay for this application. Thanks
Thank you Costas, this worked and solved my problem. The other problem that I noticed only now was that I was connecting the relay power VCC and ground to an “external supply” (Since I thought this was a 5v relay and my NodeMCU was 3.3v). With Relay connected to external power supply nothing was working. I then connected the Relay VCC and ground to the board (3.3v) and reversed the widget as you suggested and the relay started ticking just the way I wanted it to.
The bigger question is now to connect this relay to a 220V AC load where I am going to draw about 5-6 AMPS running a motor. I will add a diode to prevent any damage to my board. Not sure if this will work or not, Any comments on this, thanks in advance.
You need to have a shared Ground wire between your relay PSU and the NodeMCU.
That is not really a question for this forum… Mains power is deadly!! Always seek out a local professional, not a forum, before messing with mains power, particularly 240vac.
If you feel your relay is not sufficiently isolating the AC from the switching MCU, then a diode is not a solution in any way… a better isolated relay is.
If you are referring to using the diode as flyback protection, then be aware that you cannot use a diode on an AC motor anyhow.
Thanks a ton. Your advice is much appreciated. Excuse my knowledge on electronics, I am more of a IT professional.
(1) I now understand that for flyback protection there is no need to add a Diode so long as I am using AC. Thanks
(2) I will test my relay if this works or not, in case not then I will look for a better isolated relay. Would it be right to combine a Solid State Relay with my 5V relay already in place.
Define combine… as in add a 2nd SS relay to your project to control a 2nd AC device, then sure, why not
Or do you want to switch one relay from another? If so, then NO don’t do that, as there is no need and could lead to other issues if you are unsure of what you are doing.
Just make sure you use a TTL switching compatible relay (electrical/mechanical or SS) that is properly rated for the load (if in doubt, ask that professional… no not the paperboy or the neighbor who borrowed, and still has, your hammer last year… ask a mains power pro)
Be aware that SS “relays” are sometimes capable of variable controlled output (e.g. dimmer or even speed control). If you need that then make sure it is properly rated for it. If you don’t need that, then make sure OFF meens OFF and not allowing a small leakage of current.