-->
Page 1 of 2

Relay switch runs ESP8266 crazy

PostPosted: Fri Sep 04, 2015 2:49 pm
by Kasty
Hello,
I am new to the forum, and sorry if i missed the topic :D So, I programed my ESP8266 for a simple webserver, so i can control my relay over Wi-Fi... And everything works perfect, until the relay actually gets loaded... When I connect my lights on the relay, it can turn them off and on one time, than the ESP just goes crazy, it writes some dibrish ->
(x 2ü<–ń =xń ź Ź_tĘ„.ČSMŚü2Y ÂÖyůA$IÚ¬ý)
in lualoader, and i need to reset it. Than it again runs normally for one switch and goes crazy... I am wondering if anyone else run to a problem of this sort, any suggestions would be most helpful.
I am using an arduino relay (5V) connected to GPIO0, I also tried to connect it to the GPIO2 on the ESP but it doesn’t mater.

THE CODE: (but I doubt that there is the problem)
wifi.setmode(wifi.STATION)
wifi.sta.config("BBQ","1004199399")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<h1> Zan soba </h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON2")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "OFF1")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "ON1")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)


Thank you,
Žan

Re: Relay switch runs ESP8266 crazy

PostPosted: Fri Sep 04, 2015 3:00 pm
by martinayotte
How do you driving the relays ?
Did they have a flyback diode on the coils ?
Do they have separate power supply ?
Is you ESP power supply is really clean and sufficient with a big capacitor nearby ?

You can read viewtopic.php?p=22771#p26995 where a lot of people faced that.

Re: Relay switch runs ESP8266 crazy

PostPosted: Sun Sep 06, 2015 8:10 am
by Kasty
Im running everything with a 5V(0,8A) power supply, with an 3,3V regulator. I think it uses a diode (http://www.elecfreaks.com/store/images/product_images/Breakout/Relay/BK_SRD_03.jpg).
Well im running it on 3,3V connected to the VCC, the IN pin goes on GPIO0 pin from the ESP, and GND on the common GND. And like i said it runs without a problem until I load the relay...

Re: Relay switch runs ESP8266 crazy

PostPosted: Sun Sep 06, 2015 8:58 am
by Barnabybear
Hi, as you mention GPIO 0 & 2 I'm guessing that you are using an ESP8266-01.
As this only occurs when your relay contacts are powered it looks like it is a RF interference from the switching.
Two things to help:
1, The ESP8266-01 board has a badly designed track for the reset pin, which acts as an antenna and has been known to pick up RF and cause random resets. Personally I solder Vcc, RST & CH_PD together on the header pins if I don’t need them.
2, RF may be affecting the ESP8266 chip directly. To combat this you can increase the distance between the ESP and the relay or place the relay in a metal container (making sure that it is insulated from the container).