1
\$\begingroup\$

I am working on a simple circuit (for debugging purpose) which switches a 3V3 relay every second through the Esp-01 GPIO2 pin. The power supply comes from the USB to ESP-01 adapter (but the same happens with another power supply)

This circuit is the following:

**ESP8266-01:** 
VCC <--> 3V3 power supply
GND <--> GND (power supply)
CH_PD <--> 3V3 power supply
GPIO2 <--> IN (relay)

**3V relay:**
VCC <--> 3V3 power supply
GND <--> GND (power supply)
IN <--> GPIO2 (ESP-01)

The relay is mounted on a power extension cord, on which I can connect various devices.

Here is my circuit diagram (the breadboard is not represented): circuit diagram

My sketch is the following:

#include <ESP8266WiFi.h>

const int switch_pin = 2;
int state = 0;


void setup() {
  Serial.begin(115200);

  WiFi.forceSleepBegin();

  pinMode(switch_pin, OUTPUT);
}



void loop() {

  if (state == 0){
    digitalWrite(switch_pin, HIGH);
    state = 1; 
    Serial.println("1");
  }

  else{
    digitalWrite(switch_pin, LOW);
    state = 0;
    Serial.println("0");
  }
  delay(1000);
}

which produces, on the serial:

0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

Thus, sometimes, the Esp-01 resets and, sometimes it cannot "recover" from such resets.

However, when I disconnect the extension cord (from the electrical outlet in the wall), the relay switches indefinitely as expected (I do not know if it's a clue to solve my problem).

I tried with 2 relays and 2 Esp-01 and always got the same behaviour.

Would you have any idea about the origin of such a problem?

\$\endgroup\$
6
  • \$\begingroup\$ Please specify the relay type and a picture of the wiring. \$\endgroup\$ Nov 9 '20 at 9:09
  • \$\begingroup\$ @MatsKarlsson: picture of the relay module: images-na.ssl-images-amazon.com/images/I/… \$\endgroup\$
    – floflo29
    Nov 9 '20 at 9:15
  • \$\begingroup\$ Nice, many questions is with 5v "china" relay modules that isn't reliable at 3,3volt. That module looks like it has optocoupler for isolation and driving transistor for the relay. \$\endgroup\$ Nov 9 '20 at 9:18
  • \$\begingroup\$ @MatsKarlsson: it's a 3V3 relay module (not 5V) \$\endgroup\$
    – floflo29
    Nov 9 '20 at 9:20
  • 1
    \$\begingroup\$ @MatsKarlsson: circuit diagram added \$\endgroup\$
    – floflo29
    Nov 9 '20 at 10:22
0
\$\begingroup\$

The relay contacts used to switch mains voltage arc and spark when the contacts are closed or opened. The radiated electromagnetic interference from the spark is enough to cause a malfunction in the microcontroller board. This arcing and sparking does not happen when mains is disconnected.

\$\endgroup\$
3
  • \$\begingroup\$ It is much more likely that the power peak from the coil is causing a dip in the voltage and thereby causing the ESP to reboot. \$\endgroup\$ Nov 9 '20 at 9:00
  • \$\begingroup\$ @MatsKarlsson if so, how come the relay coil can be toggled without rebooting when there is no load on contacts? \$\endgroup\$
    – Justme
    Nov 9 '20 at 9:05
  • \$\begingroup\$ Then it could be a wiring problem. That the arc should cause problem the ESP needs to be glues to the relay case. The range of the radio interference that the arc can produce is very limited. If we are talking about a higher voltage and amperage and heavy duty contactors then it would be another matter. \$\endgroup\$ Nov 9 '20 at 9:11
0
\$\begingroup\$

It is likely that the power peak from when the relay coil is powered on, is causing a dip in the voltage and thereby causing the ESP to reboot.

This is a common topic on many forums like here in EE, https://arduino.stackexchange.com/ and others.

By adding a large electrolyte capacitor close to the VCC and GND on the ESP is a common way to solve this problem.

Another root cause is the usage of inferior cables (USB) with wery low AWG (Area) on the copper in the cable, see https://www.youtube.com/watch?v=n70N_sBYepQ

\$\endgroup\$
2
  • \$\begingroup\$ Could you give an example of the capacitance of such a capacitor and (exactly) where to insert it in my circuit? \$\endgroup\$
    – floflo29
    Nov 9 '20 at 9:21
  • \$\begingroup\$ 100uF -1 000uF as close to Vcc and GND on the ESP-01 \$\endgroup\$ Nov 9 '20 at 9:35

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.