[SOLVED]Problem with relays during boot nodeMCU

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

[SOLVED]Problem with relays during boot nodeMCU

#1 Post by mackowiakp » 11 Aug 2019, 07:01

I use modules with 2 or 4 relays connected to nodeMCU. They have the ability to set the relay activating state, high or low. Because such modules work in 5V logic, I added a transistor at the input so that it can be used in 3.3V logic.
The problem occurs during boot nodeMCU. Well (regardless of whether the relay activation state is 0 or 1) during boot the relays are activated briefly one after the other. The problem has always been present. That's why I'm using an external circuit based on the CD4541 timer. It supplies the supply voltage to the relay module with a 10 sec delay after reboot or power on/off. This is particularly sad because I can't use EasyESP with Linknode8, because apart from the phenomenon described earlier, the software works very well on this device.
Linknode8.jpg
Linknode8.jpg (65.07 KiB) Viewed 1741 times
Only that the problem is probably solvable at the software level. Such a phenomenon does not occur in software dedicated to Sonoff. (tested on Sonoff one relay ver).
This phenomenon is prevented, for example, by using the nodeMCU to open/close the entrance or garage gate. Because after each reboot or power on/off, the gates open or close by themselves. And if I'm not at home, then the alarm is activated.
Can it be somehow remedied without soldering the additional delay circuit?
Last edited by mackowiakp on 15 Aug 2019, 06:26, edited 1 time in total.

TD-er
Core team member
Posts: 1484
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem with relays during boot nodeMCU

#2 Post by TD-er » 11 Aug 2019, 20:37

What GPIO pins are used to trigger the relays?
Some do ge activated at boot, before the software is active,
See: https://espeasy.readthedocs.io/en/lates ... on-esp8266

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Problem with relays during boot nodeMCU

#3 Post by ThomasB » 12 Aug 2019, 04:01

The OP's photo shows the Linknode R8. Full details, with GPIO mapping:
http://linksprite.com/wiki/index.php?ti ... controller

Per TD-er's concern, some pins used to control the R8's relays are also temporarily used during ESP8266 initialization (boot mode config pins). And to bring that home, I found a comment on the Tasmota github that warns that two of the relays will energize during the boot up sequence (and ESPEasy cannot avoid this either).
https://github.com/arendst/Sonoff-Tasmota/issues/545

Regarding the problem on the NodeMCU, avoid the special GPIO pins and the relay issue shouldn't occur. And some relay transistor driver circuits will need an external bias (i.e., pulldown) resistor on the GPIO signal so that the relay is not energized during a ESP8266 reset.

- Thomas

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#4 Post by mackowiakp » 12 Aug 2019, 07:18

Hmmm. From what I see, the only 100% sure solution is to make an additional, external delay circuit based on 4541 (as I do now). As an option, you can consider using a ready-made module available on the market. But such a module is based on IC type 555 and requires a 12V power supply. Such voltage is not always available. Well, unless you add a step-up voltage converter module 5 to 12V.
The 4541 based circuit can be powered from 5V and there is no additional relay unlike ready-made 555 based modules.
Only that eliminates the use of Linknode because the use of such a circuit would require in this case "rebuilding" the PCB. Too complicated.
Anyway, just using a delay circuit will protect me from unexpected opening of the garage or entrance gate.
As for the use of an additional transistor at the input of the relay module, I think it is necessary. This is because if the relay activation state is 0, then 5V voltage is present at the module input. Provided for sure by some resistor (which should not destroy the nodeMCU) but the nodeMCU will work out of specification. If, on the other hand, the active state is 1, then nodeMCU will supply 3.3V voltage to the relay module. Generally, it should work, but the relay module works in 5V logic. Of course, such a transistor reverses the signal phase.

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#5 Post by mackowiakp » 12 Aug 2019, 08:54

I have another idea how to connect 8 relays or more to nodeMCU. Consider using I2C I/O extender like PCF8574 with 8 relays module connected to extender. I have not experience with PCF8574 working with nodeMCU, so must ask. Does the phenomenon of short activation of relays during boot also occur in this configuration? When using PCF8574 connected to RPi, there is no such phenomenon.

TD-er
Core team member
Posts: 1484
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem with relays during boot nodeMCU

#6 Post by TD-er » 12 Aug 2019, 10:31

We have support for such an GPIO expander.
I know Shardan does have experience with those. Maybe he can tell if ESPeasy does mess with the GPIO state during init.

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#7 Post by mackowiakp » 12 Aug 2019, 11:16

Yes, I know that PCF8574 is supported by EasyESP. So @Shardan, be so kind to answer.
I sent him PM.

Shardan
Normal user
Posts: 1112
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Problem with relays during boot nodeMCU

#8 Post by Shardan » 12 Aug 2019, 17:48

No problem.

I'd prefer the MCP23017 over the PCF8574 for a simple reason.
I've cut the simplified output schematic for an output pin of the PCF8574 from datasheet
.
PCF8574-Output_Circuit.jpg
PCF8574-Output_Circuit.jpg (111.65 KiB) Viewed 1662 times
.
If you take a closer look you'll notice a circle with "100µA" noted beside it.
The circle is the sign for a constant-current source, in this case with a current 0f 0,1mA.
This says:
If Output is "0" it can sink a current of about 10..20 mA to ground.
If Output is "1" it can deliver a maximum of 100µA from VCC to output

I've tried to drive a NPNJ transistor (2N2222, BC547) with a relay.. it is not reliable.
It depends heavily on the quality of the transistor, more exact the current amplification factor of the transistor.

You can test this with a LED adn a 470 Ohm resistor ... Connect LED with resistor in serial to the output, the other end to VCC.
The LED will light up if output is "0". Connect it to Ground and Output, and you may see a very faint light....

It might work if you use a small FET (2N7000, or SMD type 2N7002), that might work... I didn't test that.

It's easier to use the MCP23017 instead. More IOs (16 instead of 8) and it does not have the current source as with the PCF8574.
There's not much of a difference in ESPEasy to use... it's MCPGPIO,x,y instead of PCFGPOIO,x,y... that's it.

Watch out that your relay board uses NPN transistors or N-FETs... While it is possible to use PNP transistors (and several
relay boards do so) it runs into the next problem: Relay with 5V and PCF/MCP with 3,3V.
PNP transistor emitter is connected to 5V, the PCF/MCP delivers 3.3V max. leaving a "gap" of 1,7V.
This will lead to strange behaviour like relay always on or relay triggers on once and stays on.
If this happens, use two or three diodes (1N4148 or 1N400x) in serial to the Input, this helps.
A schematic for this and a lot of other information about realys can be found in the wiki:

https://letscontrolit.com/wiki/index.ph ... cs:_Relays
Regards
Shardan

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Problem with relays during boot nodeMCU

#9 Post by ThomasB » 13 Aug 2019, 03:14

Only that eliminates the use of Linknode because the use of such a circuit would require in this case "rebuilding" the PCB. Too complicated.
Anyway, just using a delay circuit will protect me from unexpected opening of the garage or entrance gate.
The Linknode R8 should be safe to use to control your gate if you avoid the two relays that have the undesirable turn-on issue. That leaves six other relays to choose from. And you could consider downgrading to the Linknode R4, which has four relays (and avoids the relay turn-on problem).
I'd prefer the MCP23017 over the PCF8574 for a simple reason. {snip} I've tried to drive a NPNJ transistor (2N2222, BC547) with a relay.. it is not reliable.
The MCP23017 is a nice chip and I've used it in my projects. But in defense of the PCF8574, the weak output sourcing current is a feature, rather than a defect. It's related to the chip's quasi-bidirectional geometry which gives it the ability to read and write its I/O pins without the overhead of direction control registers.
If Output is "1" it can deliver a maximum of 100µA from VCC to output
I agree that 100uA is not much output source current. But when more drive current is needed an external pull-up resistor can be added to the PCF8574's I/O pin. For example, when driving a common NPN transistor (like a 2N2222) a 2.2K ohm to VDD should provide enough current to activate the relay. Or if a switching MOSFET like a 2N7000 is used then this extra resistor can often be omitted.

Long story short, the PCF8574 is a good guy if you play by its rules.

- Thomas

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#10 Post by mackowiakp » 13 Aug 2019, 08:51

I agree that 100uA is not much output source current. But when more drive current is needed an external pull-up resistor can be added to the PCF8574's I/O pin. For example, when driving a common NPN transistor (like a 2N2222) a 2.2K ohm to VDD should provide enough current to activate the relay. Or if a switching MOSFET like a 2N7000 is used then this extra resistor can often be omitted.
Becuse of low maximal output current, I used small Darligton type transistor MPSA13 with PCF8574 and RPi. But it's only because I had one in a drawer.

I would like to thank @Shardan for very observant and professional advice. And I would like to ask for final confirmation that the effect of momentary switching on of relays connected to the extender does not occur in the boot nodeMCU time.

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Problem with relays during boot nodeMCU

#11 Post by ThomasB » 13 Aug 2019, 17:12

And I would like to ask for final confirmation that the effect of momentary switching on of relays connected to the extender does not occur in the boot nodeMCU time.
NodeMCU won't be the issue. But keep in mind that at power-up the PCF8574 I/O are reset to logic high. To avoid relay turn-on at power up you can use a relay driver circuit that is controlled by a logic low.

- Thomas

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#12 Post by mackowiakp » 13 Aug 2019, 18:02

Yes I know. In the case of RPi in which I use PCF8574, there are Darligton transistors that invert the signal phase. So after reset I have 0 on all outputs.

Shardan
Normal user
Posts: 1112
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Problem with relays during boot nodeMCU

#13 Post by Shardan » 13 Aug 2019, 18:53

ThomasB wrote:
13 Aug 2019, 03:14
I'd prefer the MCP23017 over the PCF8574 for a simple reason. {snip} I've tried to drive a NPNJ transistor (2N2222, BC547) with a relay.. it is not reliable.
The MCP23017 is a nice chip and I've used it in my projects. But in defense of the PCF8574, the weak output sourcing current is a feature, rather than a defect. It's related to the chip's quasi-bidirectional geometry which gives it the ability to read and write its I/O pins without the overhead of direction control registers.
Well, the MCP23017 is bidirectional too without this problems ;-)
A pullup Resistor may help indeed. Just it adds additional parts not needed with the MCP. A 2N7000/7002 is even better as it does not need any resistor.
100µA should be OK to switch the FET gate.
I use the PCF for input IOs, as soon as output comes up, even in combination with inputs I use the MCP.
Regards
Shardan

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Problem with relays during boot nodeMCU

#14 Post by ThomasB » 13 Aug 2019, 19:15

I agree that there are many solutions, its all personal preference. That's one of the attractions to DiY projects.

I'll end my chatter with one last idea. For convenience, a cheap $1 relay module with active low control can be used. For example: https://ebay.to/2TsKle0

Set the relay's logic control jumper to logic low trigger mode. Directly connect the relay input signal to the PCF8574 I/O. Relay now turns on with logic low bit. No extra resistors, transistors, or magic dust.

- Thomas

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#15 Post by mackowiakp » 13 Aug 2019, 19:41

Yes, but with this solution (when the jumper is set to trigger low) you have a voltage of 5V at the relay module input. Certainly given by some resistor but it is 5V. Of course, I'm writing about modules that I bought, working on 5V. So the expander will work out of specification, because it is powered by 3.3V.

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Problem with relays during boot nodeMCU

#16 Post by ThomasB » 13 Aug 2019, 20:15

Yes, but with this solution (when the jumper is set to trigger low) you have a voltage of 5V at the relay module input.
That would indeed be a problem. The transistor and magic dust is going to be needed after all.

- Thomas

Shardan
Normal user
Posts: 1112
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Problem with relays during boot nodeMCU

#17 Post by Shardan » 14 Aug 2019, 22:18

mackowiakp wrote:
13 Aug 2019, 19:41
Yes, but with this solution (when the jumper is set to trigger low) you have a voltage of 5V at the relay module input. Certainly given by some resistor but it is 5V. Of course, I'm writing about modules that I bought, working on 5V. So the expander will work out of specification, because it is powered by 3.3V.
This will reproduce the problem when using 3.3V device on 5V input.
If output is high it has 3.3V. The difference of 1,7V is high enough to drive a transistor or sometimes even an opto coupler.
The relay keeps on or can be switched on one time then remains on.

In this case use 2..3 standard diodes (1N4148, 1N400x) as described in the relay wiki.
The diodes take up around 0.65... 0.7V each so the 5V isn't a problem any longer and
the relay works reliable.
Regards
Shardan

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Problem with relays during boot nodeMCU

#18 Post by mackowiakp » 15 Aug 2019, 06:25

Yes, it is also one of the possible solutions too. But - as ThomasB wrote - in the DiY world everything depends only on individual preferences. And what's just in the drawer :D
I mark the topic as SOLVED.

mackowiakp
Normal user
Posts: 134
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: [SOLVED]Problem with relays during boot nodeMCU

#19 Post by mackowiakp » 20 Aug 2019, 06:45

As for Linknode R8, the problem is with three relays and not with two. This is because GPIO10 is also used, which is set to high before ESPeasy is loaded. And it remains in this state after loading the system.
But this gave me an idea how to make the delay circuit for relays in ASAP way (as simple as possible). All you need is a transistor, e.g. BD135 and a 1k resistor. Simply connect the transistor base via a resistor to GPIO5. Emitter to ground and collector to ground connector of the relay module. Then, using rule, after ESPeasy is loaded, set first GPIO10 (if You want to use it for relay) to low and then GPIO5 output to high. And now the relay module is fully powered. The solution can be used both with module supply from 5V and 12V. And it can be mounted directly on the module's input contacts. I checked - works correctly.

User avatar
ThomasB
Normal user
Posts: 400
Joined: 17 Jun 2018, 20:41
Location: USA

Re: [SOLVED]Problem with relays during boot nodeMCU

#20 Post by ThomasB » 21 Aug 2019, 22:32

All you need is a transistor, e.g. BD135 and a 1k resistor. Simply connect the transistor base via a resistor to GPIO5.
Glad to hear the final solution was quick and easy. In some paper/rock/scissors contests, solder beats software.

- Thomas

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 34 guests