[Fixed!] Strange relay behaviour, not switching on/off on GPIO 0/1 command.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

[Fixed!] Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#1 Post by DeNB3rt » 20 May 2017, 11:32

Hi all

Perhaps a easy question, I have the most common relay board on the world here in a espeasy/domoticz setup.
But maybe other's had the same instability.

Image

I thought everything was working fine, but sometimes the relay is not switching on/off when I send commands through domoticz.
I thought a connection issue or whatever.

But when looking deeper, I have the same issue when sending the commands by hand.

Code: Select all

http://<ESP IP address>/control?cmd=GPIO,<pin>,0
I can switch on/off each channel without issue, but when I switch on both, it's not possible to switch them off separate. After sending an off signal to both chanels, the relay will switch off both chanels at the same time after the last command.

So I was thinking about
  • upgraded espeasy from R120 to 2.0.0-dev8
  • configured the output as output high or low, but does not help.
  • I am thinking that the level of 1/0 is wrong towards the relay, should it be connected with a pull down? (did not see something about that in the https://www.letscontrolit.com/wiki/index.php/Relais)
  • Onother thing in the wiki is the level shifter, could the TTL vs 3.3v cause this issue?
  • Last thing (not tried yet) is the separate power source to power the board,could that cause the 'instability'? /edit In the meantime, connected 5v to the vcc pin on the relay, same issue
  • any other suggestions?
//Edit 07/2017
And it's fixed!
Don't hit me, le dumb me found the easy fix...
I experimented with breadboards with external PSU and everything worked fine in test.
But in my wall switch setup, I was using an 5v 2Amps usb power supply.
Never thought that could be the issue, but there must be a power regulator or something like that on my nodeMCU board.
So I was draining power from the 5V pin on the nodeMCU board, thinking I was taking direct psu power....
That caused the strange behaviour.
After giving 5v power directly to the relay board, everything was working fine (stupid me) :roll:

See youtube illustration before/after:
https://www.youtube.com/watch?v=K6xgu1o1jh0
Last edited by DeNB3rt on 10 Jul 2017, 22:20, edited 1 time in total.
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#2 Post by DeNB3rt » 20 May 2017, 13:36

In the meantime, tested with separate power source to power the relay board, still the same.
So could that realy be the 3.3v vs 5v issue?
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

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

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#3 Post by Shardan » 20 May 2017, 14:42

Hello,

it's difficult to say whats going wrong as i don't know your relay board.
It might be an issue due to the circuit on the board, depending on how the inputs are wired.

Any hints what board you use?
If you have a schematic that would be perfect.

Regards
Shardan
Regards
Shardan

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#4 Post by papperone » 20 May 2017, 23:19

I use few of relays module like this one in the picture and never had issues or weird behaviour.
I guess a "real picture" of your with more details (if any) woudl help to understand...
Would be great if you have another module to test if any difference (as a suggestion I can give alway sbuy extra units when buy form China as the qualitu is not excellent and having at least a spare one is good for testing/troubleshooting and as well for the future if anything will break!)
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

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

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#5 Post by Shardan » 21 May 2017, 19:02

Well, i've done some research to find your module.

What i see is it's running on 5V, and normally the 5V is connected to the electronic circuit too.
(Jumper from JD-Vcc to Vcc).

According to the offers at AliExpress the opto couplers are "low level triggered".
This says that the opto couplers LED ist one end connected to 5V, the other end is lead to the pin header (In1 / In2)

The ESP runs on 3,3V, output "high" is 3 .. 3.3 V. To securely switch on/off the relay board needs 5V for "high" (= off).
The ESP offers 3,3V max. so there is still about 1,7V on the LED of the optocoupler.

This is very near to the threshold value of the opto couplers so the board may behave unpredictable.

Maybe it would be a good idea to completely isolate the input of the relay board from the ESP-circuit.
The board can do that. (And this improves electrical security, too!)

- Remove the jumper cap from JD-Vcc - Vcc.
- use a separate 5V power supply for the relays, 5V to JD-Vcc, gnd to the GND header.
- Connect the 4 pins (Vcc, in1, in2, Gnd) to the ESP accordingly: 3,3V from ESP to Vcc pin,
gnd to gnd, GPIO*s to the In-Pins.

This way the Optocouplers are running on 3,3V from ESP circuit and the relays are on 5V.

Beware: I've looked up the pins from another relay board and hope the pin naming is same... but with the chinese guys one never knows.
Please check if JD-VCC is really the power supply for the relay coils!

The quality of this boards isn't that bad. They have the isolationg cut-outs required by european safety regulations,
i've seen much worse relays.... so for around 1,50 € they are just OK.
The relays might die fast if you switch a motor or pump or machinery. But even a 15€ high quality
"Finder"-relay will die with that if no further measurements are taken.

Regards
Shardan
Regards
Shardan

maluko
Normal user
Posts: 112
Joined: 02 Sep 2015, 00:49

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#6 Post by maluko » 22 May 2017, 00:14

Shardan wrote: 21 May 2017, 19:02 Well, i've done some research to find your module.

What i see is it's running on 5V, and normally the 5V is connected to the electronic circuit too.
(Jumper from JD-Vcc to Vcc).

According to the offers at AliExpress the opto couplers are "low level triggered".
This says that the opto couplers LED ist one end connected to 5V, the other end is lead to the pin header (In1 / In2)

The ESP runs on 3,3V, output "high" is 3 .. 3.3 V. To securely switch on/off the relay board needs 5V for "high" (= off).
The ESP offers 3,3V max. so there is still about 1,7V on the LED of the optocoupler.

This is very near to the threshold value of the opto couplers so the board may behave unpredictable.

Maybe it would be a good idea to completely isolate the input of the relay board from the ESP-circuit.
The board can do that. (And this improves electrical security, too!)

- Remove the jumper cap from JD-Vcc - Vcc.
- use a separate 5V power supply for the relays, 5V to JD-Vcc, gnd to the GND header.
- Connect the 4 pins (Vcc, in1, in2, Gnd) to the ESP accordingly: 3,3V from ESP to Vcc pin,
gnd to gnd, GPIO*s to the In-Pins.

This way the Optocouplers are running on 3,3V from ESP circuit and the relays are on 5V.

Beware: I've looked up the pins from another relay board and hope the pin naming is same... but with the chinese guys one never knows.
Please check if JD-VCC is really the power supply for the relay coils!

The quality of this boards isn't that bad. They have the isolationg cut-outs required by european safety regulations,
i've seen much worse relays.... so for around 1,50 € they are just OK.
The relays might die fast if you switch a motor or pump or machinery. But even a 15€ high quality
"Finder"-relay will die with that if no further measurements are taken.

Regards
Shardan
just follow the shardan, this is the correct for the most relay board.

with 3,3v will work but its bad idea if you have a lot of relay that open at the same time, so the best is to put a separete 5v on jd-vcc and 3.3v on vcc near the l1,l2,etc. of course without jamper

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#7 Post by DeNB3rt » 22 May 2017, 10:40

Shardan wrote: 21 May 2017, 19:02 Well, i've done some research to find your module.

What i see is it's running on 5V, and normally the 5V is connected to the electronic circuit too.
(Jumper from JD-Vcc to Vcc).

According to the offers at AliExpress the opto couplers are "low level triggered".
This says that the opto couplers LED ist one end connected to 5V, the other end is lead to the pin header (In1 / In2)

The ESP runs on 3,3V, output "high" is 3 .. 3.3 V. To securely switch on/off the relay board needs 5V for "high" (= off).
The ESP offers 3,3V max. so there is still about 1,7V on the LED of the optocoupler.

This is very near to the threshold value of the opto couplers so the board may behave unpredictable.

Maybe it would be a good idea to completely isolate the input of the relay board from the ESP-circuit.
The board can do that. (And this improves electrical security, too!)

- Remove the jumper cap from JD-Vcc - Vcc.
- use a separate 5V power supply for the relays, 5V to JD-Vcc, gnd to the GND header.
- Connect the 4 pins (Vcc, in1, in2, Gnd) to the ESP accordingly: 3,3V from ESP to Vcc pin,
gnd to gnd, GPIO*s to the In-Pins.

This way the Optocouplers are running on 3,3V from ESP circuit and the relays are on 5V.

Beware: I've looked up the pins from another relay board and hope the pin naming is same... but with the chinese guys one never knows.
Please check if JD-VCC is really the power supply for the relay coils!

The quality of this boards isn't that bad. They have the isolationg cut-outs required by european safety regulations,
i've seen much worse relays.... so for around 1,50 € they are just OK.
The relays might die fast if you switch a motor or pump or machinery. But even a 15€ high quality
"Finder"-relay will die with that if no further measurements are taken.

Regards
Shardan

Great reply Shardan!
Thanks!
In the meantime I connected, JD-VCC to 5v power before you posted this, but the VCC near the in1 and in2 is still on 5v!
So I was still having the same issue.
I'll correct this when I come home.
I also switched from gpio's, but still the same.
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#8 Post by DeNB3rt » 24 May 2017, 10:57

I tried what Shardan proposed.
Connected 5V to JD-Vcc, both gnd's to same gnd.
Connected Vcc to 3.3v.

I see the led near the relay going on/off (not that bright as vcc on 5v).
But the relay is not getting triggering at all.

If i connect 5v to JD-Vcc and vcc (like it was before) the led is also going on/off when sending gpio 1/0 command.
But is sometimes failing to handle the coil correctly.

I think I better post some images + video? ;)
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

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

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#9 Post by Shardan » 24 May 2017, 14:00

A photo of the circuit would be helpfull indeed.

Sadly i don't have this relay module myself, so i have to guess how it is wired internally.
It is possible that the resistor in serial with the opto coupler LED is too big for 3,3V or
the current limit of the ESP is too low for that module...
but as said, this is kinda prophecy + guessing mix. :)

Regards
Shardan
Regards
Shardan

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#10 Post by costo » 31 May 2017, 18:43

I have the 2 relais module and found out that ´IN´ is connected to a red led, optocoupler_diode and a 1k resistor all in series between Vcc and the logic input..
Like in this article: http://howtomechatronics.com/tutorials/ ... -tutorial/ .

Image
The schematic say that the input can be connected to 5V of a Arduino output pin. So it will not work reliable with the 3.3V of a ESP.
If you have the solder skills you should bridge the red led which has a Vf of about 1.7V with a solderblob or wire. After that the module will work reliable with 3.3V logic and Vcc connected to 3.3V of the ESP..
Ofcourse you should keep the two voltage rails separated and feed the JD-Vcc with 5V because the relais only work reliable on 5V.

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

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#11 Post by Shardan » 31 May 2017, 20:09

Alternatively you can use a small NPN transistor (2N2222 or similiar) or FET (2N7000 or similiar) between "In1" and ground.
Then you may drive the LED with 5 V too from the relay's voltage (Jumper Vcc -JDVcc closed).

Regards
Shardan
Regards
Shardan

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#12 Post by DeNB3rt » 13 Jun 2017, 10:38

Hi Shardan and Costo

Thanks for the feedback.
I did not have a lot of time the last day's do I did not see that feedback.

So yesterday, I tried to sort some things out...
I thought, why not replacing the relay board with a spare board just to test?

Left side new board, right side old board. (here you can see my board version)
That setup seems to do what it should.
Image

So I had to shut of the mains to replace the AC~ cables to the new relay.
After doing so and turning on the power again, the nodemcu/espeasy board did not came online again.
Weird, I did a few restarts and checked dhcp, no other ip...
Connected with usb cable to serial monitor and I saw some unreadable chars... :shock:
switched baud rate from 1152000 to all other options and found out that 74880 was showing one line

Code: Select all

  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
I thought, fuck it, I'll replace it with another nodemcu on my breadboard (it was becoming darker outdoors and my wife was becoming angry that the lights did not work :twisted: ).
flashed the latest espseasy and reconfigured it, working!

So for now, all stuff is running again like it should :) I'll monitor the behaviour and I keep you guy's updated :) Thankss!
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#13 Post by DeNB3rt » 23 Jun 2017, 10:26

Dammit, setup was working perfectly for about 2 weeks (controlling my living and kitchen lights with domoticz app, web interface and MQTT button on another esp :) )
But since yesterday, again a similar problem like before.
The relay was not reacting anymore on any command.
But the leds on the opto do enlight/shutoff when I make gpio 1/0.
It looks like the coil does not get enough power to get triggered.

I make it more weird, I cut off the power to the relay board, restarted the ESP and connected the relay back like before (vcc 5v).
Everything is working fine again now? :|
PSU do deliver 5v 2a max.
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#14 Post by papperone » 23 Jun 2017, 10:48

May I ask you which type of PSu are you using?
In a friend of mine setup he had similar issue despite the "beefy" PSU (1.5A) but at the end the final solution was to replace it for another one!
I provided him a 700mA PSU which I normally use for all my project (HLK-PM01) mounted on a small PCB with varistor in parallel to the AC input and fuse on the Live line and since then (more than 2 months) no more problem!
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#15 Post by DeNB3rt » 29 Jun 2017, 10:01

Hi Paperpone

I'm using a 230~ 5V- smartphone charger.
I already tested with an iphone or samsung charger, but same shit :oops:

The weird thing now, is that I am not able to trigger both coil's at the same time, crasy shit :D
If I trigger both coils, the first triggered coil will enable, the 2nd will stay off (but optical led will enlight).
When I shutoff the first coil, the second will enable.
if I do the inverse, the 2nd will trigger.
So the behavior is predictable.

I will try to use two boards with only one relay per board to see what happens.
It's time to buy Eltako's I think :lol:
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#16 Post by toffel969 » 30 Jun 2017, 12:15

DeNB3rt wrote: 29 Jun 2017, 10:01 Hi Paperpone

I'm using a 230~ 5V- smartphone charger.
I already tested with an iphone or samsung charger, but same shit :oops:

The weird thing now, is that I am not able to trigger both coil's at the same time, crasy shit :D
If I trigger both coils, the first triggered coil will enable, the 2nd will stay off (but optical led will enlight).
When I shutoff the first coil, the second will enable.
if I do the inverse, the 2nd will trigger.
So the behavior is predictable.

I will try to use two boards with only one relay per board to see what happens.
It's time to buy Eltako's I think :lol:
For switching AC I can really recommend the SSR-Relays from Pollin http://www.pollin.de/shop/dt/NjYzOTU2OT ... 80_V_.html. They switch reliably with the current that the ESP GPIOs can sink and will not stick/ have mechanical units. Due to reliability issues (and therefore an angry wife), I swapped many of the electromagnetic relays for SSR. Beware they can only switch AC
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#17 Post by grovkillen » 30 Jun 2017, 13:31

Great pointer Toffel!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: [Fixed!] Strange relay behaviour, not switching on/off on GPIO 0/1 command.

#18 Post by DeNB3rt » 10 Jul 2017, 22:20

And it's fixed!
Don't hit me, le dumb me found the easy fix :roll: ...
I experimented with breadboards with external PSU and everything worked fine in test.
But in my wall switch setup, I was using an 5v 2Amps usb power supply.
Never thought that could be the issue, but there must be a power regulator or something like that on my nodeMCU board.
So I was draining power from the 5V pin on the nodeMCU board, thinking I was taking direct psu power....
That caused the strange behaviour.
After giving 5v power directly to the relay board, everything was working fine (stupid me) :roll:

See youtube illustration before/after:
https://www.youtube.com/watch?v=K6xgu1o1jh0
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 36 guests