-->
Page 1 of 1

Esp-01 and 3V3 relay: reset cause 4

PostPosted: Mon Nov 09, 2020 3:16 am
by Jean Charles
I am working on a simple circuit (for debugging purpose) which switches a 3V3 relay module every second through the Esp-01 GPIO2 pin.

This circuit is the following:

Code: Select all**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.

My sketch is the following:

Code: Select all#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:

Code: Select all0
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), it 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?

Thanks

Re: Esp-01 and 3V3 relay: reset cause 4

PostPosted: Thu Dec 10, 2020 10:01 pm
by guysnraw
It's a power issue, hook up with a capacitor

Re: Esp-01 and 3V3 relay: reset cause 4

PostPosted: Sat Dec 12, 2020 1:59 pm
by StanJ
Depending on the relay and how you're driving it, you could also be driving high voltage spikes back into the ESP-01 GPIO when you switch it off, potentially damaging the ESP. That would be a Bad Thing.

I haven't used electro-mechanical relays in decades due to the inductive kick-back; I'd use a bipolar transistor, TRIAC, MOSFET or SSR (Solid State Relay) depending on what I wanted to drive. If I had absolutely no other choice, I'd use a relay. They're noisy, the coil sucks a lot of power, and the contacts fail, as well as the back-EMF from switching them off.

All things considered, relays are a 1930s solution to a 2020 problem.