Go Down

Topic: Esp8266 + Relay, yet another post.. (Read 1 time) previous topic - next topic

spacefolder

Aug 13, 2017, 02:16 am Last Edit: Aug 13, 2017, 11:50 pm by spacefolder Reason: image links
Hi Guys!

I´m trying to actuate a relay with an esp8266 (3.3v), but I have some questions..

The relay module I have, is rated for 5v input.
It seems to have a crude driving circuit + a flyback diode.
I've tested it connecting the module to +5v, gnd, and Signal to an output pin of the esp8266, and the relay activates just fine.

Question:
1) It's ok to use it this way? Or do I still need a 2n2222 (for example) to drive the module in a safe way for the esp?
2) It's ok to drive the relay module with a high state GPIO? I've seen several youtube videos where they say it's better to set the GPIO as input and "drain" the current through the pin. I am not able to fully understand how this method works.  :smiley-confuse:
3) If I measure current between the active GPIO pin and the Signal pin of the relay module, I get roughly 3.5 mA. Is it safe to draw this amount of current from a "data" pin?

This is how I have them connected..



ESP8266 + 5v relay

Relay Module images..
R1, smc value "151", what does it even mean?
Q1, smc value "J3Y"
(Apparently the traces show that Signal goes first through the LED, then through R1 and the to Q1, not sure though..)

Relay 1

Relay 2

This is the post where it shows how to add the 2n222 and other componets to drive the module, BUT on a 5v arduino, instead of a 3.3v esp8266)

https://forum.arduino.cc/index.php?topic=493559.0

Thanks guys for shinning a light..
Cheers!
Marc

edgemoron

#1
Aug 13, 2017, 08:47 am Last Edit: Aug 13, 2017, 09:09 am by edgemoron
That module has the switching transistor and kickback diode onboard, good to go, just remember those relay coils draw about 75 mA, so size your 5V power supply accordingly.
R1 is a 150 (15 + 1"0") Ohm base resistor for the NPN transistor (Q1) and LED current limit.
3.5 mA from GPIO pin should be fine, datasheet says 12 ma max, if relay pulls up with a HIGH thats OK, some are switchable, most "opto isolated" boards use low true logic.
https://cdn-learn.adafruit.com/assets/assets/000/035/388/original/0a-esp8266_datasheet_en_v4.3.pdf

PieterP

VR = VESP - VBE = 3.3V - 0.7V = 2.6V
I = VR / R = 2.6V / 150Ω = 17.3 mA
That's too much current for the ESP to source. You could probably just add another 150Ω resistor in series.

Pieter

edgemoron

What about the ~2V dropped by the series LED?.

PieterP

You're right, I didn't spot that LED, my bad.

Pieter

spacefolder

#5
Aug 14, 2017, 12:19 am Last Edit: Aug 14, 2017, 12:24 am by spacefolder
Hi guys!

Thank you both!
The relay was working fine, drawing roughly 3.5 mA from the ESP.
I was curious to try PieterP's suggestion and add a second 150 ohm resistor in series with the module.

It still works great, and current has gone down to 1.65mA!
So I guess I'll stick with the resistor. Any disadvantages? (apart from extra cost and breadboard space?)



Thanks!
Marc

edgemoron

#6
Aug 14, 2017, 05:51 am Last Edit: Aug 14, 2017, 06:16 am by edgemoron
If the transistor is not fully saturated it will be acting like a variable resistor instead of a full on switch and may overheat, also, if the relay coil is not getting enough hold in current, it could drop out with a hard mechanical shock, I wouldn't use the second R, nor second guess the module designer.

spacefolder

If the transistor is not fully saturated it will be acting like a variable resistor instead of a full on switch and may overheat, also, if the relay coil is not getting enough hold in current, it could drop out with a hard mechanical shock, I wouldn't use the second R, nor second guess the module designer.
Thanks Edge!
So.. another question arises  :)
The module was not designed for 3.3v  (It´s for 5v. VCC and ground are going to 5v, but signal is triggered by a ESP high state pin.) So, how can I know if the transistor is fully saturated? Maybe measuring voltage across base and ground?
I dont want to blow the smc transitor!
BTW: I´m planning to use this circuit to trigger my central heating "thermostat" input, by closing a (I think) 30v DC standard thermostat circuit. Do you recommend a solid state component such as a mosfet, etc.?
Cheers!

edgemoron

#8
Aug 15, 2017, 05:10 am Last Edit: Aug 15, 2017, 05:33 am by edgemoron
With the relay energized for 5 minutes or so, measure the voltage from emitter to collector, should be only a few mV (< 100), feel the transistor with the tip of your pinky finger (carefully) it may be warm but shouldn't be "spit sizzlin" hot, (< 120 F) or so.
Most TStats here in the US work on 24VAC, don't know about EU and ROW.

spacefolder

Once again, thank you Edge!

1) Transistor doesn't even get warm at touch, though current between emitter and collector is 112mV.
[Base to collector is 0.713 V]. I guess I shouldn't be really worried (?)

You were right, thermostat wiring uses 24 V AC.
As a prototype, a relay works fine. But I was curious that ready made digital thermostats run on 2xAA batteries and last months, or even years. I believe they are using some type of solid state switch. Any guesses?

Cheers!
Marc 

edgemoron

112 mV dropped with current of 75 mA is only 8.4 milliWatts, transistor should outlive both of us. I believe modern TStats use a triac to switch the AC current that pilots the main unit.

dipalworld

My connections are : ac mains to ac of hlk-pm01, dc +ve to vin of nodemcu and relay +ve, dc -ve to gnd of nodemcu and relay -ve. From nodemcu d5 to relay input.

When i checked the nodemcu using tester, neon light glown up. If i touch that, it had current. Ideally it should not, right?

I checked hlk-pm01 of hilink and found it was giving 5v output and 1.9 A current when measured using multimeter.

Pls help.

wvmarle

To saturate a transistor you typically need 1:10 to 1:20 base current:collector current. So in your case, to switch 75 mA, that would mean 3.75-7.5 mA base current. The data sheet of the particular transistor should have more information.

An EC voltage of 112 mV sounds very low to me, even if saturated. Even at a (very large) 1V drop you'd have only 75 mW of power dissipation so indeed nothing to worry about either way at these low currents.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up