0

I am working on a simple circuit whose goal is to control a high voltage device (e.g. a lamp) thanks to a (3V3) relay module, ESP8266-01 and the MQTT protocol.

To power this circuit, I am using a 5V phone charger producing a 3.3V voltage through an AMS1117 voltage regulator (5V --> 3V3). This 3V3 output from the AMS1117 is what I call "3V3 power supply" below.

The wiring 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)

While it sometimes works, as I am often experiencing some problems (ESP-01 not connecting to the wifi, relay switching on its own, ...), I am wondering wether my circuit is lacking something (diode?) or if the wiring is wrong.

UPDATE:

Following @SimSon advice, I wrote this simple sketch:

#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);
}

However, while it will indeed switch the high voltage device (as expected) it will do it for less than a minute before freezing. As I have Serial.println() at each switch, the ESP blue led also blinks every second when the relay switches but it stops blinking once the relay also stop working.

I have tried with a second relay but the problem still occurs.

SECOND EDIT:

Here is what I got with on the serial port when switching the realy every second until crash:

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
floflo29
  • 111
  • 3
  • You need to tell which relay you use. 3.3V is not the whole story and the relay probably requires more current than the esp can provide, so you would still need a transistor to drive the relay. As a relay is an inductive load, you also must have a freewheeling diode accross the relay. – Sim Son Nov 08 '20 at 13:19
  • 1
    @Sim-Son: It's a relay module, not a bare relay, so it probably alread has a diode and a 3.3V logic level input, plus a separate power supply connection for energising the coil. – ocrdu Nov 08 '20 at 13:36
  • @ocrdu I see, my fault – Sim Son Nov 08 '20 at 13:38
  • You're circuit is fine (sorry, thought you were using a bare relay). How is your setup assembled? If you are on a breadboard, wifi can interfere with it quite dramatically. In this case, test wifi and the relay separately. – Sim Son Nov 08 '20 at 13:42
  • When testing WiFi on the usb to esp01 adapter (the one I use to program the esp) it works as expected (to check this the esp publishes a message every second over mqtt). Indeed, it’s a relay module. Without the relay, the esp sometimes do not connect to WiFi. Indeed I work on a breadboard. Is it a problem for the esp and the relay to be connected to the same power supply? – floflo29 Nov 08 '20 at 13:45
  • Connecting them to the same power supply is fine (at least if the relay isn't faulty, which seems to be the case). But using a breadboard and wifi can be a severe problem, try to use it without the breadboard if possible. Alternatively write a sketch that switches the relay each second (**wifi disabled**). If it works, then the breadboard is likely to be the reason. – Sim Son Nov 08 '20 at 14:11
  • @floflo29 btw. you should reply to a comment explicitly (like I did with @floflo29), so users get a notification. I just saw your response by chance – Sim Son Nov 08 '20 at 14:13
  • @SimSon I've updated my question with your suggestion. Still unexpected behaviour. – floflo29 Nov 08 '20 at 16:25
  • Please compile your sketch with highest verbosity and run it again. There will hopefully be more information on the serial line (do you actually read what the esp prints out or do you only see the led blink). – Sim Son Nov 08 '20 at 16:39
  • @SimSon I've noticed tht before freezing, the relay seems to perform a "double" switch very quickly if it can help. I do not read the esp output on the serial. – floflo29 Nov 08 '20 at 16:54
  • @floflo29 you need to see the serial output. If there is a crash, that's where the esp tells you what happend. – Sim Son Nov 08 '20 at 16:56
  • I guess there is a crash and the 8266 sometimes fails to force a reboot from my experience. That's the only explanation I have why your test sketch should stop running. – Sim Son Nov 08 '20 at 16:59
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/115968/discussion-between-floflo29-and-sim-son). – floflo29 Nov 08 '20 at 19:08
  • @SimSon: first post edited with logs – floflo29 Nov 08 '20 at 19:10
  • I also had this issue, but with Atmega processor working on external quartz. Switching to internal RC oscillator solved the problem. (not case with esp) - switching relay (and arcing high power contacts) doesn't like processors running nearby :). – fifi_22 Nov 08 '20 at 19:16
  • When I unplug the high voltage device, however, the problem does not occur... – floflo29 Nov 09 '20 at 07:55

0 Answers0