Using a relay (the neverending story)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
johnnybee
Normal user
Posts: 4
Joined: 12 Nov 2017, 14:25

Using a relay (the neverending story)

#1 Post by johnnybee » 12 Nov 2017, 14:41

Hello,

I'm sorry to get on your nervs with this (i hope so) simple problem. I have an esp8266-01 and tried to switch an relay on gpio2 following the explanation on https://www.letscontrolit.com/wiki/index.php/Relais.
I could switch it on with http://<ip-adress>/control?cmd=GPIO,2,0 or 1

And thats the problem. I doesn't make any difference if I try a zero or a one. The Relais always get activatet. But I can't switch if off!:-(

The relais looks exactly like the single relais on the picture on https://www.letscontrolit.com/wiki/index.php/Relais. So it uses a SRD-05VDC-SL-C

Could someone please explain me, what I'm doing wrong? Thank you very much in advance.

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

Re: Using a relay (the neverending story)

#2 Post by TD-er » 12 Nov 2017, 15:34

I assume you are using some transistor to operate the relais? The output of the ESP is not powerful enough to directly operate the relais.
And do you have a diode over the relais? (to protect the rest of the electronics when working with coils)

Can you measure the Voltage on the relais coil, with a multimeter?
And perhaps exchange the relais for a LED with resistor, just to check it is working.

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

Re: Using a relay (the neverending story)

#3 Post by Shardan » 12 Nov 2017, 15:45

A transistor is not necessary ehre as there modules use an opto coupler and a transistor on the relay board.

Sadly iu don't have this relay board as a sample so i just have to guess.
Can you please give the pin descriptions?
I just guess it is
- GND
- VCC
- IN
- JD-VCC (or something similiar)

Did you connect Vcc to 5V?

Regards
Shardan
Regards
Shardan

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

Re: Using a relay (the neverending story)

#4 Post by Shardan » 12 Nov 2017, 16:18

Hm... inspecting the relay modules i have i got a suspicion.

Beware, this might not work as i don't have your module and can't test.

Try to just add 3 diodes in serial as shown here:
Relais_5V.jpg
Relais_5V.jpg (159.42 KiB) Viewed 3804 times
If your module has the same schematic as my ones have the opto coupler is fed with 5V.
If the ESP's GPIO is "high" it has ~3.3V. So a voltage of 1.7V is still on the opto coupler.
This is enough to keep the relay working.

The diodes have a forward voltage of ~ 0.7V so this simple trick adds ~ 2.1Vto the esp's output voltage.

Maybe give it a try.

Regards
Shardan
Regards
Shardan

johnnybee
Normal user
Posts: 4
Joined: 12 Nov 2017, 14:25

Re: Using a relay (the neverending story)

#5 Post by johnnybee » 12 Nov 2017, 18:53

Thank you for your answers,

@Shardan yeah its exactly some kind of module you specified. I connected it directly with 5 volt power and the gpio with the port on the relais. So you means I just need 3 diodes (in the right direction of course!), put them in a line and it would work?
Sorry, I'm an absolutly newbie in electric systems but very interested. I will give it a try and tell you.
Thank you for your help!

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

Re: Using a relay (the neverending story)

#6 Post by Shardan » 12 Nov 2017, 19:11

johnnybee wrote:
12 Nov 2017, 18:53
Thank you for your answers,

@Shardan yeah its exactly some kind of module you specified. I connected it directly with 5 volt power and the gpio with the port on the relais. So you means I just need 3 diodes (in the right direction of course!), put them in a line and it would work?
Sorry, I'm an absolutly newbie in electric systems but very interested. I will give it a try and tell you.
Thank you for your help!
Well, i'm not sure, i can't test as i lack that relay module. But worth a try anyways, these diodes are cheapest stuff.
Regards
Shardan

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

Re: Using a relay (the neverending story)

#7 Post by papperone » 12 Nov 2017, 20:56

Can you post a picture of your relay module?
All the ones I've seen have 3 pins and they requires separate power than the signal...
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

johnnybee
Normal user
Posts: 4
Joined: 12 Nov 2017, 14:25

Re: Using a relay (the neverending story)

#8 Post by johnnybee » 14 Nov 2017, 08:45

IT's the following relay:
s-l500.jpg
s-l500.jpg (36.25 KiB) Viewed 3725 times
I bought it from Ebay. The Relay needs 5V power to work but the in1 power was not specified. To it sounds (for me) logical right that i need 5V vor in1 too. Or is this wrong?

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

Re: Using a relay (the neverending story)

#9 Post by grovkillen » 14 Nov 2017, 09:44

You could test with 3.3V just to see (or hear) if the relay is pulled.
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:

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

Re: Using a relay (the neverending story)

#10 Post by Shardan » 14 Nov 2017, 10:43

Hm... this board is quite simple, not even an opto coupler.

Can you please make a very basic test:

- Just connect the board to 5V and ground.
- Then connect IN to Vcc first - does the relay "click"?
- if not, connect IN to GND - does it click now?

This is just for testing if the board works as expected and which transistor type is mounted on the board, NPN/N-ch or PNP/P-Ch.

Please tell the result, if the relay switches with IN=low (GND) or IN=high (Vcc).
Then we'll see what to do.

Regards
Shardan
Regards
Shardan

johnnybee
Normal user
Posts: 4
Joined: 12 Nov 2017, 14:25

Re: Using a relay (the neverending story)

#11 Post by johnnybee » 16 Nov 2017, 09:27

Chaca, i get it!:-)

Shardan, you was right! I needed just two diodes in line and now it's switching as it should!:-) I'm happy!
Thank you very much for your help!

And I make the test also. It's switch on when IN1 is on gnd.

Greetings
Thomas

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

Re: Using a relay (the neverending story)

#12 Post by Shardan » 16 Nov 2017, 18:35

you're welcome :)
Regards
Shardan

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

Re: Using a relay (the neverending story)

#13 Post by DeNB3rt » 21 Nov 2017, 09:55

relay's I hate them ;)
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

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

Re: Using a relay (the neverending story)

#14 Post by Shardan » 22 Nov 2017, 14:54

The biggest problem: there is no "standard" relay board.

Every relay board has another schematic.
Basically they all work. As soon as different voltages come up things get complex.
The ESP runs on 3.3V, relays run on 5..12 V usually.
Is the input part of the relay board (transistor, opto coupler...) connected to GND or
to the voltage of the relays? The later won't run without problems.

Oh and btw: The "security feature" of opto couplers is a nuisance in most cases.
Most people drive the opto couplers from the same power supply they use for the relays.
So the isolation the opto provides between input and output does not exist - it is done away by the wires of the power supply.
Second - a relay is a nice isolating device (if you chose some quality ones of course).
So what is the isolation of the opto coupler for?

Maybe we should revamp the "Relay" part in the wiki and put up some explanation what works or not and why.

(And no: Solid State Relays are not better always....)

Regards
Shardan
Last edited by Shardan on 22 Nov 2017, 19:49, edited 1 time in total.
Regards
Shardan

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

Re: Using a relay (the neverending story)

#15 Post by grovkillen » 22 Nov 2017, 18:28

+1
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:

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

Re: Using a relay (the neverending story)

#16 Post by toffel969 » 23 Nov 2017, 00:21

grovkillen wrote:
22 Nov 2017, 18:28
+1
:D
i agree , ssr downright suck when trying to switch DC :lol:

with AC they do have their advantages(switching at zero current, no arc, no wear), but downsides like leakage current (important when using low power LED) and heat generation must be considered in their application as well as their most common failure mode (they short out). all depends on what you are trying to achieve, for example sodium lamp ballast is very unreliable with traditional relays, the contacts often start sticking (even when using 30A rated relay, with a 400w ballast) no probs with ssr.
on the other hand, when trying to switch a 6w LED, there is the problem of flickering when switched off due to leakage current with ssr, a tradional relay is the much netter choice
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

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

Re: Using a relay (the neverending story)

#17 Post by Shardan » 23 Nov 2017, 13:22

Yes and no.
There are specialized SSR that work with DC too.... youll find them with searching for high price... :twisted:

With AC it depends on what you want to switch.
They are nice with resitive load - but what is really pure resitive these days? Inductivities, coils, valves, motors and such can execute an SSR within seconds.

I've just tested something very simple: A solenoid valve of about 5 watt power consumption with a standard "3 EUR AliExpress SSR".
Valve: https://de.aliexpress.com/item/co2-diy- ... eLevelAB=1

Relay: https://de.aliexpress.com/item/4pcs-lot ... eLevelAB=1

The SSR is made for 5A, says > 1000 watt on mains voltage.

I've just made it switch 5 sec on, 5 sec off. It took some on/off's and the valve was opened permanently, the relay shorted.

The induced voltage in the valve's coil even from this small gas valve killed the triac in the SSR.

I'm testing this for a pH control based on ESPEasy. I'm not too surprised about the destroyed relay, i expected that.
I'll have to repeat the test with a resistor/capacitor combination and / or a varistor to make switching reliable.

Murphy's law is valid as usual: Behind every problem you solve two others wait to appear.....

Regards
Shardan
Regards
Shardan

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

Re: Using a relay (the neverending story)

#18 Post by toffel969 » 24 Nov 2017, 08:08

One needs to be very careful when sourcing SSR. There are lots of fakes and parts with underdimensioned components, f.e. : https://www.youtube.com/watch?v=DxEhxjvifyY http://www.instructables.com/id/The-inn ... OTEK-SSRs/

My experience with ebay/Ali is equally bad. That's why I pointed out the pollin relays in the wiki.

These two work directly on an ESP GPIO and I can confirm their reliabilty, also when switching inductive loads like solenoids, motors, ballasts, though I never went even close to their rated currents. Particularly the solenoid is an application where I changed 3 mechanical relays in 3 months (sticking contacts) before changing to SSR.
https://www.pollin.de/p/solid-state-rel ... 0-v-340633
https://www.pollin.de/p/solid-state-rel ... 0-v-340470

I haven't tried these ones:
https://www.pollin.de/p/solid-state-rel ... 0-v-340625 but chances are, they work reliebly as well.

I feel like its worth spending a bit of extra money on the 230VAC components.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

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

Re: Using a relay (the neverending story)

#19 Post by Shardan » 24 Nov 2017, 11:14

toffel969 wrote:
24 Nov 2017, 08:08

I feel like its worth spending a bit of extra money on the 230VAC components.
Definitely. I'm testing around to see where the line between best price and cheap garbage is crossed.
Up to now the "Mager GJ-5-L" seems to work, testing the "Hoymk D3805HK" atm.
Sortet out a lot meantime, simply they are garbage.

Anyways, even really expensive, high quality ones get killed under inductive load.
The voltage peak can reach > 1000V, that's dangerous for every triac.
I've tested this with cheap SSR's, i've tested with expensife ones (Carlo Gavazzi, Comus, finder, Sharp).
With inductive load they all die sooner or later. Some are marked "snubberless" - anyways they die too.

Those relays with built-in "snubber" circuit are a game of luck. A snubber is a resistor/capacitor combination
that should "arrest" high voltage peaks. In theory that works - if the capacitor is tuned to the inductive load the ssr switches.
The capacitor and the inductive load build a resonant circuit to lead off the peaks. As the relay manufacturer doesn't lnow
what we want to switch, dimensioning might be good or bad.

Atm the best way to protect the ssr seems to be a varistor with 250..300 VAC.
I'll test that the next days with several SSRs.

For mechanical relays i'm using the Fuujitsu/Takamisawa JS-12 MN KT (12V) or JS-5 MN KT (5V).
They have some distance between low voltage and mains voltage so with some effort on PCB design
it's possible to avoid milling out gaps.
Regards
Shardan

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

Re: Using a relay (the neverending story)

#20 Post by Shardan » 24 Nov 2017, 11:15

Shardan wrote:
24 Nov 2017, 11:14
toffel969 wrote:
24 Nov 2017, 08:08

I feel like its worth spending a bit of extra money on the 230VAC components.
Definitely. I'm testing around to see where the line between best price and cheap garbage is crossed.
Up to now the "Mager GJ-5-L" seems to work, testing the "Hoymk D3805HK" atm.
Sortet out others over time, simply they are garbage.

Anyways, even really expensive, high quality ones get killed under inductive load.
The voltage peak can reach > 1000V, that's dangerous for every triac.
I've tested this with cheap SSR's, i've tested with expensife ones (Carlo Gavazzi, Comus, finder, Sharp).
With inductive load they all die sooner or later. Some are marked "snubberless" - anyways they die too.

Those relays with built-in "snubber" circuit are a game of luck. A snubber is a resistor/capacitor combination
that should "arrest" high voltage peaks. In theory that works - if the capacitor is tuned to the inductive load the ssr switches.
The capacitor and the inductive load build a resonant circuit to lead off the peaks. As the relay manufacturer doesn't lnow
what we want to switch, dimensioning might be good or bad.

Atm the best way to protect the ssr seems to be a varistor with 250..300 VAC.
I'll test that the next days with several SSRs.

For mechanical relays i'm using the Fuujitsu/Takamisawa JS-12 MN KT (12V) or JS-5 MN KT (5V).
They have some distance between low voltage and mains voltage so with some effort on PCB design
it's possible to avoid milling out gaps.
Regards
Shardan

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

Re: Using a relay (the neverending story)

#21 Post by Shardan » 30 Nov 2017, 21:09

As promised i uploaded some descriptions to the wiki.

https://www.letscontrolit.com/wiki/inde ... cal_Relays

Let me know if that helps guys.

Regards
Shardan
Regards
Shardan

danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: Using a relay (the neverending story)

#22 Post by danmero » 01 Dec 2017, 17:24

I use relay board with JVcc , separate rail for relay.

relay_jvcc.jpg
relay_jvcc.jpg (66.06 KiB) Viewed 3923 times

Regards,

PS. Ref: ESP8266 GPIO Behaviour at Boot

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

Re: Using a relay (the neverending story)

#23 Post by Shardan » 01 Dec 2017, 20:38

Nice analysis, good job.

The different behaviour of the GPIOs is somewhat easy to explain.
The ESP8266 is a kind of a jack of all trade device. Due to that nearly all GPIO's are hardwired internally to more then one function.
D0 (GPIO16) is internally used for deep sleep wake up. D5...D8 can be used as GPIO or additional SPI bus.
D3 (GPIO 0) is used to set flash mode at start up, D4 (GPIO 2) can be used to switch into other start modes, starting from a SD-card for example.
And so on.

So at boot these GPIO's will show some different behavior, that's just normal.

On top there is another point that has some effect on the GPIO pins.
The pins can be set to internal "weak" pull resistors at startup. This is usually done by the sketch you run.
As this is done at boot up time / starttime of the sketch this leads to some signals on the GPIOs too on startup.

Anyways the relay board you use is one of the "problem boards" switching on "low" signal".

All in all the conclusion is that boot time is not stable on GPIO's but that's a normal behaviour.
Even big CPU's like the ones in a PC do that. They use a line driver that is inhibited at startup to suppress such signals if necessary.

Last but not least - that relay board is not suitable for mains voltage at least in the EU.
The copper to copper distance between mains voltage and the low voltage circuit is far too low and the board has no millings to keep leak current off
as it is requiered by EU policies.

Regards
Shardan.
Regards
Shardan

danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: Using a relay (the neverending story)

#24 Post by danmero » 02 Dec 2017, 01:07

Shardan wrote:
01 Dec 2017, 20:38
Anyways the relay board you use is one of the "problem boards" switching on "low" signal".
That's i always use expanders to activate the relay.
Shardan wrote:
01 Dec 2017, 20:38
Last but not least - that relay board is not suitable for mains voltage at least in the EU.
The copper to copper distance between mains voltage and the low voltage circuit is far too low and the board has no millings to keep leak current off
as it is requiered by EU policies.
This type of relay(quality) shouldn't be use on main.

Regards,

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

Re: Using a relay (the neverending story)

#25 Post by DeNB3rt » 11 Dec 2017, 11:15

If you use an extender like the PCF8574 (https://www.letscontrolit.com/wiki/index.php/PCF8574)
a relay should not be doing crazy things anymore?
It states that the PCF8574 keeps the GPIO states at ESP8266 reboot.
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: Using a relay (the neverending story)

#26 Post by toffel969 » 11 Dec 2017, 15:21

DeNB3rt wrote:
11 Dec 2017, 11:15
If you use an extender like the PCF8574 (https://www.letscontrolit.com/wiki/index.php/PCF8574)
a relay should not be doing crazy things anymore?
It states that the PCF8574 keeps the GPIO states at ESP8266 reboot.
I made that statement, it's true, I tried. You can reboot/reset the esp, gpio of pcf keep their state until they receive new instructions via i2c
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

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

Re: Using a relay (the neverending story)

#27 Post by DeNB3rt » 13 Dec 2017, 11:31

toffel969 wrote:
11 Dec 2017, 15:21
I made that statement, it's true, I tried. You can reboot/reset the esp, gpio of pcf keep their state until they receive new instructions via i2c
that's just great! Could that chip drive an relay board with opto?
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

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

Re: Using a relay (the neverending story)

#28 Post by grovkillen » 13 Dec 2017, 11:42

Should not be a problem.
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:

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

Re: Using a relay (the neverending story)

#29 Post by Shardan » 13 Dec 2017, 14:43

DeNB3rt wrote:
13 Dec 2017, 11:31
toffel969 wrote:
11 Dec 2017, 15:21
I made that statement, it's true, I tried. You can reboot/reset the esp, gpio of pcf keep their state until they receive new instructions via i2c
that's just great! Could that chip drive an relay board with opto?
I've tested a PCF8574 with the usual 8ch relay board with optocouplers.
Image
Remember, if you use same power supply for relay and ESP/PCF, the opto couplers are useless as GND and VCC are connected and "bridge" the isolation of the optos.

Regards
Shardan
Regards
Shardan

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests