So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Kowa92
#87929 Hello everyone!

I wanted to expose you the following problem from which i do not come out:

I have an ESP-01S that pilots an ESP8266 Relay v1.0 board (i tested ESP8266 Relay v4.0 board too.. Same problem! :roll: ).
I made the connection on a solderless breadboard. I think both the electrical wiring and the software should have no problems as everything works correctly and never crashes "at zero load".
The problem is that it crashes everytime i connect the NO and COM contacts of the ESP8266 relay board, to any type of AC power supply (both 24 and 230 VAC) that drives a load (for example another relay or fan). After a short time (or immediately) the ESP8266 relay board switches his contact, the ESP-01S always crashes with a reboot and i can't understand why...
I don't think it's a drop down voltage (nor peaks) on the main 3.3V power supply of the ESP-01S because with the multimeter i have not detected anything of abnormal.

- What do you think the problem may be? Has this issue ever happened to someone of you?

I tried to search the web but i did not find anything of useful ..

PS: The ESP-01S reboots for the following reason: "ets Jan 8 2013, rst cause: 4, boot mode: (3,6)"

Thanks to everyone! :)
User avatar
By Kowa92
pangolin wrote:I think we need to see both the wiring and the sketch you are running

Yeah, this is ESP-01S Relay v1.0 Schematic:


and this is how i linked ESP8266 Relay v1.0 to ESP-01S chip:


The sketch i'm running is that:

Code: Select all/*
    This sketch demonstrates how to set up a simple HTTP-like server.
    The server will set a GPIO pin depending on the request
      http://server_ip/?gpio2=on will set the GPIO0 low,
      http://server_ip/?gpio2=off will set the GPIO2 high
    server_ip is the IP address of the ESP8266 module, will be
    printed to Serial when the module is connected.

/* This sketch is Powered by Kowalski */

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "xxx"
#define STAPSK  "xxx"

const char* ssid = STASSID;
const char* password = STAPSK;

const int O0 = 0;
const int O2 = 2;

bool esp_res = false;
unsigned long CN = 0;

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {

  // prepare GPIO
  pinMode(O0, OUTPUT);
  pinMode(O2, OUTPUT);
  digitalWrite(O0, LOW);
  digitalWrite(O2, LOW);

  // Connect to WiFi network
  Serial.print(F("Connecting to: "));

  WiFi.begin(ssid, password);

  bool ff = false;
  while (WiFi.status() != WL_CONNECTED) {
    ff = !ff;
    digitalWrite(O2, ff);
  digitalWrite(O2, LOW);
  Serial.println(F("WiFi connected"));

  long rssi = WiFi.RSSI();
  Serial.print(F("WiFi signal strength (RSSI): "));
  Serial.println(F(" dBm"));

  // Start the server
  Serial.println(F("Server HTTP started"));

  // Print the IP address and MAC address
  Serial.print(F("The ESP8266's IP is: "));
  Serial.print(F("The ESP8266's MAC is: "));

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    if (esp_res) {
      Serial.println(F("Reset cmd launched. Bye"));
  Serial.println(F("New client connected"));
  Serial.print(F("CN: "));

  //client.setTimeout(5000); // default is 1000

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  //String req = client.readString();
  Serial.println(F("Client's request is: "));

  // Read the actual state of GPIO
  int state = digitalRead(O0);
  int state1 = digitalRead(O2);
  Serial.print(F("GPIO0 Read: "));
  Serial.print(F("GPIO2 Read: "));

  // Match the request
  if (req.indexOf(F("/?gpio0=on")) != -1) {
    state = 1;
    Serial.println(F("R: switching on GPIO0"));
  else if (req.indexOf(F("/?gpio0=off")) != -1) {
    state = 0;
    Serial.println(F("R: switching off GPIO0"));
  else if (req.indexOf(F("/?gpio2=on")) != -1) {
    state1 = 1;
    Serial.println(F("R: switching on GPIO2"));
  else if (req.indexOf(F("/?gpio2=off")) != -1) {
    state1 = 0;
    Serial.println(F("R: switching off GPIO2"));
  else if (req.indexOf(F("/?resetboard=true")) != -1) {
    Serial.println(F("R: resetting ESP board.."));
    client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n"));
    client.print(F("<head><title>ESP8266 Web Server</title></head>"));
    client.print(F("<style>html {font-family: Helvetica;}</style>"));
    //client.print(F("<body onload=\", '_self');\">The ESP8266 is now rebooting.. Please wait.</body></html>"));
    client.print(F("<body><p>The ESP8266-"));
    client.print(F(" is now rebooting.. Please wait.</p><p>Click <a href=\"/\">here</a> in a little while for review the previous page.</p>"));
    client.print(F("<small><p>CN: "));
    client.print(F("</p><p>Powered by <b>Kowalski</b></p></small></body></html>"));
    Serial.println(F("Response sent. Disconnecting from client"));
    esp_res = true;
  else {
    Serial.println(F("Invalid client's request. Do nothing"));

  // Set GPIO according to the request
  digitalWrite(O0, state);
  digitalWrite(O2, state1);
  Serial.print(F("GPIO0 Write: "));
  Serial.print(F("GPIO2 Write: "));

  // read/ignore the rest of the request
  // do not client.flush(): it is for output only, see below
  while (client.available()) {
    // byte by byte is not very efficient;

  // Send the response to the client
  // it is OK for multiple small client.print/write,
  // because nagle algorithm will group them into one single packet
  client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n"));
  client.print(F("<head><title>ESP8266 Web Server</title></head>"));
  client.print(F("<style>html {font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"));
  client.print(F(".button {background-color: #77878A; border: none; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"));
  client.print(F(".button1 {background-color: #195B6A;}"));
  client.print(F("i {font-size: 19px;}</style></style>"));
  client.print(F(" HTTP Server</h2><form action=\"/\" method=\"get\">"));

  // GPIO 0
  client.print(F("<p><b>GPIO 0</b> - State is: "));
  client.print((state) ? F("<i>on</i>") : F("<i>off</i>"));

  String content;
  if (state) content = "<input class=\"button\" type=\"submit\" value=\"off\" name=\"gpio0\">";
  else content = "<input class=\"button button1\" type=\"submit\" value=\"on\" name=\"gpio0\">";

  //GPIO 2
  client.print(F("<p><b>GPIO 2</b> - State is: "));
  client.print((state1) ? F("<i>on</i>") : F("<i>off</i>"));

  if (state1) content = "<input class=\"button\" type=\"submit\" value=\"off\" name=\"gpio2\">";
  else content = "<input class=\"button button1\" type=\"submit\" value=\"on\" name=\"gpio2\">";

  //client.print(content + F("</form>"));
  client.print(F("<br><br><button onclick=\"location.reload(true);\">Reload</button>"));
  client.print(F("<br><br><small><a href=\"javascript:if(confirm('Are you sure to reboot ESP8266-"));
  client.print(F(" Module?')){'/?resetboard=true', '_self')};\">Reset ESP</a>"));
  client.print(F("</form><p>CN: "));
  client.print(F("</p><p>Powered by <b>Kowalski</b></p></small></body></html>"));

  // The client will actually be *flushed* then disconnected
  // when the function returns and 'client' object is destroyed (out-of-scope)
  // flush = ensure written data are received by the other side
  Serial.println(F("Response sent. Disconnecting from client"));