Driving Relay using esp8266-01
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 23
- Joined: 20 Nov 2015, 10:53
Driving Relay using esp8266-01
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. ??
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. ??
Re: Driving Relay using esp8266-01
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.
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.
Re: Driving Relay using esp8266-01
Could you meassuzre the voltage in the different states ?
-
- Normal user
- Posts: 23
- Joined: 20 Nov 2015, 10:53
Re: Driving Relay using esp8266-01
Case 1. Ledkr0815 wrote:Could you meassuzre the voltage in the different states ?
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
Re: Driving Relay using esp8266-01
so Case 2 - Relay
what voltage do you have after a reboot ? also 2.5-3 V
what voltage do you have after a reboot ? also 2.5-3 V
-
- Normal user
- Posts: 23
- Joined: 20 Nov 2015, 10:53
Re: Driving Relay using esp8266-01
yup 2.5 -3V
Re: Driving Relay using esp8266-01
What relay do you use?
Does it have a built in diode and can it operate on just 3 volt?
Does it have a built in diode and can it operate on just 3 volt?
-
- Normal user
- Posts: 23
- Joined: 20 Nov 2015, 10:53
Re: Driving Relay using esp8266-01
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?
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?
-
- Normal user
- Posts: 23
- Joined: 20 Nov 2015, 10:53
Re: Driving Relay using esp8266-01
Actually Relay is gettin switched even with 3V . Esp8266 is able to switch relay.
Re: Driving Relay using esp8266-01
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?
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?
Re: Driving Relay using esp8266-01
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.
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.
-
- Normal user
- Posts: 23
- Joined: 20 Nov 2015, 10:53
Re: Driving Relay using esp8266-01
Thanks buddy. I'll get to you . 

Re: Driving Relay using esp8266-01
+1 !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.
Testing a mysensors sketch : relay + button is the best way to drive a light.
Re: Driving Relay using esp8266-01
Martinus, would you be able to create such output device for us?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.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.
Re: Driving Relay using esp8266-01
Or maybe use the hardware tab for this. Just testing if it makes sense to have this boot state config in the hardware tab: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.
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
Re: Driving Relay using esp8266-01
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.
Re: Driving Relay using esp8266-01
Very Nice option.
I thinks it is wise to use active low technologie in critical applicaties. So 0 volt to activatie.
I thinks it is wise to use active low technologie in critical applicaties. So 0 volt to activatie.
-
- Normal user
- Posts: 35
- Joined: 11 Nov 2015, 13:52
Re: Driving Relay using esp8266-01
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.
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.
Re: Driving Relay using esp8266-01
But I'm not sure what needs to be build? I think that I can do this already with the current version: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.
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.
-
- Normal user
- Posts: 35
- Joined: 11 Nov 2015, 13:52
Re: Driving Relay using esp8266-01
I will try that.. first i have to get my esp's stable. The longest uptime for now is 19hrs1) 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.
Re: Driving Relay using esp8266 - High at Reboot
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?BertB wrote:Very Nice option.
I thinks it is wise to use active low technologie in critical applicaties. So 0 volt to activatie.
-----------
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.
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.
Re: Driving Relay using esp8266-01
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.
Re: Driving Relay using esp8266-01
Do not forget to connect a flyback diode.
Who is online
Users browsing this forum: No registered users and 7 guests