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