0

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();
}
1
  • I know this question is more than 5 years old, but since nobody has mentioned it: are you trying to produce 5 V from a 5 V input using a linear regulator? That will not work. Also, if the regulator is an LM317T, it's wired incorrectly and would need a pair of resistors to set the output voltage.
    – StarCat
    Commented Dec 24, 2023 at 10:53

1 Answer 1

-1

Before running to dark magic of EMI problems - let's try isolate all our parameters that can cause or affect (and perhaps is is not only one):

  1. make a test code as simple as possible for switching a relay periodically on/off. At start make a 5 second delay between changing states, and down to 500 millis- This way you check both EMI interference and power issues inside you circuit (sometimes the relay consumes power more that the MCU can give, and that can cause resets. Problem can be MCU's power issue or Relay, mechanical or electrical issues).
  2. Components - try to replace with others, especially MCUs, and relays, to make sure it is not a malfunctioned or degraded components. For example - a Wemos mini with is Relay shield can easily isolate any "EMI"- related issue.
  3. From you diagram (and in contrast to your question's title) - an Uno is used for switching ? and not the ESP-01' right? did you make sure that the relay's vcc is correct for its MCU? (you said 5v relay, which is not correct for ESP8266).
  4. Load - make sure to choose a simple resistive load (AC light bulb), rather that an AC motor (which cause a massive EMI interference).
  5. EMI - if all above did not help (I doubt) or it solved for that "bulb case" only, EMI affect are distance related. Try to use a long AC wires that will take you MCUs and relay far from that source. 1m will be enough.

To sum up, I will be very surprised to know that it is EMI (and I dealt with AC motors with WEMOS and a dual relay module successfully).

Please update.

Guy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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