1

I'm trying to switch on bulb via 4 channel 5V optocoupler relay controller from ESP8266 using WIFI Access point. All my connections looking fine and i can able to connect WIFI SoftAP and send signal to ESP8266 01. Even i can able to switch the Relay from NO to NC or other way around. Only when a connect 240V AC current to relay for powering the bulb, i'm getting following error from ESP

21:11:34.312 ->  ets Jan  8 2013,rst cause:4, boot mode:(1,7) 
21:11:34.312 ->  
21:11:34.312 -> wdt reset

If i use 12V DC power to light the led via relay its working fine. if again use 240V power to relay to light bulb i'm get same error again.

I have already tried using ceramic capacitor for decoupling to avoid noise from AC. Still no luck. Please advice. I'm very new and naive at handling electronics.

Adding the circuit as well.

enter image description here

Update: After further testing, I can see following behaviour, If i connect AC bulb to relay and turn it on. Then by provide a long gap before turning it off makes the ESP stable for longer time.

Even better, if i turn off/on my mobile wifi between each time i turn on or off the AC bulb then ESP is always stable.

Adding my code as well.

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "*****";
const char *password = "*********";

ESP8266WebServer server(80);

const int led = 2;  //GPIO2

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<body>\  
    <p>Status: Light ON</h1></p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/off\"><h1>Turn OFF</h1></a></p>\           
  </body>\
  ",

    hr, min % 60, sec % 60
  );
  server.send ( 200, "text/html", temp );  

}

void setup() {
    delay(1000);
    Serial.begin(115200);
    Serial.println();
    Serial.print("Configuring access point...");

    /* You can remove the password parameter if you want the AP to be open. */
    WiFi.softAP(ssid, password);

    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);

  pinMode(led, OUTPUT);
  digitalWrite ( led, HIGH );

  //URLs available to query
    server.on("/", handleRoot);
  server.on ( "/on", turnON );    
  server.on ( "/off", turnOFF );
    server.begin();
    Serial.println("HTTP server started");

}

void turnON(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<body><p><a href=\"http://192.168.4.1/off\"><h1>Turn OFF</h1></a></p></body>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);

}

void turnOFF(){

  digitalWrite ( led, LOW );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<body><p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p></body>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);

}

void loop() {
    server.handleClient();
}
0

To prevent EMI and to save the relay contacts, you could switch the relays at AC zero-crossing. Add some kind of zero-crossing detection to you project and before switching a relay, wait for a zero-crossing and then wait just before the next zero crossing (about 9500 microseconds at 50 Hz AC).

Simple is to use a current sensor to detect zero-crossing. Current AC wave should be aligned with the voltage wave, if there is no shift in power factor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.