Driving Relay using esp8266-01

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tvasudev007
Normal user
Posts: 23
Joined: 20 Nov 2015, 10:53

Driving Relay using esp8266-01

#1 Post by tvasudev007 » 29 Nov 2015, 10:17

My problem is

case 1:

step 1:
On powering circuit:

gpio 00 -> Led positive
common gnd

Led state-> OFF

Using openHAB I send ON command -> LED ON
OFF command -> LED OFF

step 2:

openHAB ON -> LED ON
openHAB OFF -> LED OFF

It works perfect with LED. and also with Arduino UNO . Initial reading of UNO is LOW.

Case 2:

On powering circuit:

gpio 00 -> Relay input
common gnd

Relay state-> ON . Input pin is HIGH unlike in the case of LED.By default it is in the ON state.

Using openHAB I send OFF command ->Relay OFF
ON command -> Relay ON

step 2:

openHAB ON -> Relay ON
openHAB OFF -> Relay OFF

Facing problem with relay & attiny85. Initial reading is ON unlike in case 1.

I think, I am facing this issue with the devices that do not have pull-up/pull-down resistors. I am not using any transistors etc., for switching.
Should I make changes in the circuit. ??

Martinus

Re: Driving Relay using esp8266-01

#2 Post by Martinus » 29 Nov 2015, 11:04

What ESP board are you using?

I think the issue is that GPIO-0 is a floating (or weak pullup) input during boot until you send some command to it. The LED will not light up.
The relay board probably has a high-impedance input circuit and may think that it's an active high output while it's actually a high impedance input.

kr0815
Normal user
Posts: 136
Joined: 18 Nov 2015, 18:24

Re: Driving Relay using esp8266-01

#3 Post by kr0815 » 29 Nov 2015, 11:18

Could you meassuzre the voltage in the different states ?

tvasudev007
Normal user
Posts: 23
Joined: 20 Nov 2015, 10:53

Re: Driving Relay using esp8266-01

#4 Post by tvasudev007 » 29 Nov 2015, 11:55

kr0815 wrote:Could you meassuzre the voltage in the different states ?
Case 1. Led

on booting :

A spike of 1.5-2V is measured for fraction of sec.

after that I am able to OFF & ON.

Default state OFF 0.1 -0.2 V
ON state 3-3.15V

Case 2 : relay

2.5-3V is measured . Default state ON

OFF state 0.1-0.2V

kr0815
Normal user
Posts: 136
Joined: 18 Nov 2015, 18:24

Re: Driving Relay using esp8266-01

#5 Post by kr0815 » 29 Nov 2015, 12:19

so Case 2 - Relay
what voltage do you have after a reboot ? also 2.5-3 V

tvasudev007
Normal user
Posts: 23
Joined: 20 Nov 2015, 10:53

Re: Driving Relay using esp8266-01

#6 Post by tvasudev007 » 29 Nov 2015, 12:26

yup 2.5 -3V

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#7 Post by BertB » 29 Nov 2015, 14:11

What relay do you use?
Does it have a built in diode and can it operate on just 3 volt?


BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#9 Post by BertB » 29 Nov 2015, 20:35

As far as I can see, without a proper schematic, the relay board has a small circuit with a transistor, some resistors and a diode. It is likely that it needs a 5 volt power supply and probably the same voltage on the control pin to make it work.

What I would like to know is:
- what voltage on the input pin is required to make the relay switch?
- what happens when you power the relay with 3.3 volt and put 0 or 3.3 volt on the input?
- Can you actually switch the relay with the esp?

tvasudev007
Normal user
Posts: 23
Joined: 20 Nov 2015, 10:53

Re: Driving Relay using esp8266-01

#10 Post by tvasudev007 » 30 Nov 2015, 16:25

Actually Relay is gettin switched even with 3V . Esp8266 is able to switch relay.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#11 Post by BertB » 30 Nov 2015, 20:49

Ah, so, your problem is that the relay is on after reboot?

If that is so, I see three possible ways to solve this:
1) Ask Martinus to create a output device. This is not really necessary to switch a pin, but it can be used to set a pin to a certain state (0 in your case) upon boot.
2) Use a transistor to invert the output level of the pin. In this case, also the control signals are inverted.
3) First, what voltage is on the input pin of the relay when it is floating? If that is close to 0, you could try to connect a resistor of 470 Ohm between the input pin and ground. This might be enough to get rid of the pull up voltage.
4) Did you try to make the pin that controls the relay a Switch input, without Pull Up? What happens?

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#12 Post by BertB » 30 Nov 2015, 23:45

I did some experiments myself with a NodeMCU 1.0 on both GPIO14 and GPIO02.
GPIO02 has a pull up and GPIO14 does not.
After boot, GPIO14 was 0 and GPIO02 was 3.3 volt. After one command to switch off, both were 0.
With a resistor of 470 Ohm across GPIO02 and ground, reduced the level after boot to 500mv, This could be enough to stop the relay.
I would not recommend that on GPIO00, because is likely to cause a switch over to programming mode at start up.
Turning GPIO02 into a switch input without pull up, did not help. Perhaps the pull up is not really switched off at boot.

I still think making an output device is the simplest way to overcome this problem, since it allows for presetting a pin to 0 at boot.

tvasudev007
Normal user
Posts: 23
Joined: 20 Nov 2015, 10:53

Re: Driving Relay using esp8266-01

#13 Post by tvasudev007 » 01 Dec 2015, 06:56

Thanks buddy. I'll get to you . :)

Deennoo
Normal user
Posts: 158
Joined: 07 Sep 2015, 13:03

Re: Driving Relay using esp8266-01

#14 Post by Deennoo » 08 Dec 2015, 20:59

BertB wrote: I still think making an output device is the simplest way to overcome this problem, since it allows for presetting a pin to 0 at boot.
+1 !

Testing a mysensors sketch : relay + button is the best way to drive a light.

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: Driving Relay using esp8266-01

#15 Post by mkotek » 15 Dec 2015, 11:26

BertB wrote:...
I still think making an output device is the simplest way to overcome this problem, since it allows for presetting a pin to 0 at boot.
Martinus, would you be able to create such output device for us?
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

Martinus

Re: Driving Relay using esp8266-01

#16 Post by Martinus » 16 Dec 2015, 09:25

BertB wrote:I still think making an output device is the simplest way to overcome this problem, since it allows for presetting a pin to 0 at boot.
Or maybe use the hardware tab for this. Just testing if it makes sense to have this boot state config in the hardware tab:
GPIOBootStates.png
GPIOBootStates.png (23.94 KiB) Viewed 18913 times
This will set the output as soon as the user application starts. But it will still take a split second before this is done, because the hardware and SDK control some pins before the user application can take over control.

One example that will still not work as expected:
If i connect a Relay board with active high input to GPIO-2 and set the default to "Output LOW", it will still drive the relay high for a split second during reset of the ESP board. This is due to bootloader or SDK behavior on this pin

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: Driving Relay using esp8266-01

#17 Post by mkotek » 16 Dec 2015, 10:35

This would definitely help, but in some cases, even this tiny moment could be dangerous. But this is the design issue then.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#18 Post by BertB » 16 Dec 2015, 12:55

Very Nice option.
I thinks it is wise to use active low technologie in critical applicaties. So 0 volt to activatie.

DMeekelenkamp
Normal user
Posts: 35
Joined: 11 Nov 2015, 13:52

Re: Driving Relay using esp8266-01

#19 Post by DMeekelenkamp » 16 Dec 2015, 13:42

Would it be possible to switch like the mysensors button+relay. It doesn't need to be a toggle switch a momentary push switch would probably easier to program.
Also the dimmer+rotary encoder would be a very nice option.
I like controlling things with my phone or tablet but a physical button on the wall is sometimes better. And I really don't like the cheap looking battery powered kaku switches.

Martinus

Re: Driving Relay using esp8266-01

#20 Post by Martinus » 17 Dec 2015, 14:28

DMeekelenkamp wrote:Would it be possible to switch like the mysensors button+relay. It doesn't need to be a toggle switch a momentary push switch would probably easier to program.
But I'm not sure what needs to be build? I think that I can do this already with the current version:

1) Domoticz: Create a virtual switch in, IDX=250
2) On Action: http://192.168.0.206/control?cmd=gpio2,1
2) Off Action: http://192.168.0.206/control?cmd=gpio2,0
3) ESP: Create a Switch Input on GPIO-0, IDX 250, Push Button Active Low

Each time a push the button on the NodeMCU board, the relay toggles accordingly. I think it's the same as the RelayWithButtonActuator sketch does.

DMeekelenkamp
Normal user
Posts: 35
Joined: 11 Nov 2015, 13:52

Re: Driving Relay using esp8266-01

#21 Post by DMeekelenkamp » 19 Dec 2015, 22:56

1) Domoticz: Create a virtual switch in, IDX=250
2) On Action: http://192.168.0.206/control?cmd=gpio2,1
2) Off Action: http://192.168.0.206/control?cmd=gpio2,0
3) ESP: Create a Switch Input on GPIO-0, IDX 250, Push Button Active Low

Each time a push the button on the NodeMCU board, the relay toggles accordingly. I think it's the same as the RelayWithButtonActuator sketch does.
I will try that.. first i have to get my esp's stable. The longest uptime for now is 19hrs

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Driving Relay using esp8266 - High at Reboot

#22 Post by JR01 » 25 Apr 2016, 20:56

BertB wrote:Very Nice option.
I thinks it is wise to use active low technologie in critical applicaties. So 0 volt to activatie.
Bert, how would one do this practically? I want to use an optocoupler like one below, pin 1 = GPIO16, 2 = GND, 4 = GND, 5 = Relay, (with 5v power source between pins 4 and 5). But this would require High on pin 1, thus, how can one switch it around, to let 0 on GPIO activate the Optocoupler? Or is the opto not the right thing to use here?
Screen Shot 2016-04-25 at 8.53.41 PM.png
Screen Shot 2016-04-25 at 8.53.41 PM.png (23.89 KiB) Viewed 17433 times
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#23 Post by BertB » 25 Apr 2016, 21:18

Try pin 1 to vcc and pin 2 via a resistor of some 100 Ohm to gpio16. It all depends on the opto you use, how it will work.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Driving Relay using esp8266-01

#24 Post by BertB » 25 Apr 2016, 21:28

Do not forget to connect a flyback diode.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests