ESP8266-01 + Relays + Blynk : The ESP disconnect when the pump is turned on

Good day Guys!

My name is Yann! This is my first post in this forum but not my first visit! :slight_smile:
I'm French Canadian, so this is probably not best english writting but I'm pretty sure that you'll understand! :wink:

What is my my project?

My project is an irrigation system to monitor and water my houseplants via WIFI. There are 16 Soil moisture sensors and 16 water pumps controlled via Blynk.

What are the parts used?

  • Arduino Mega 2560 (From Keyestudio model: ks0002) : Here
  • ESP8266-01 (From Keyestudio model : ks0339) : Here
  • 16-Channel 12V Relay Module (From Sain Smart) : Here
  • MB102 3,3 V/5 V Breadboard power module (From UCEC) : Here
  • Adapter Input: AC 100-240V 50/60Hz, Output: DC 12V 5A (From COOLM) : Here
  • 9 V 2 A AC/DC adaptater (From Haitronic) : Here
  • Capacitive Soil moisture sensor (From Keyees) : Here
  • DC 3V 5V Micro Submersible Mini Water Pump (From Gikfun model: EK1893) : Here

Schematic:

P.s. On the schematic The MB102 have 1 bridge on 3.3V and the other on 5V , but both are on 3.3V on my setup.

Code : This is my first code, so It's probably not the cleanest on! :slight_smile:

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "3jpnxAfsQiu5-dvEksUUQMNGSYWQpSZm";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TheCoon";
char pass[] = "AndFriends";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

int sens1 = 0;
int sens2 = 0;
int sens3 = 0;
int sens4 = 0;
int sens5 = 0;
int sens6 = 0;
int sens7 = 0;
int sens8 = 0;
int sens9 = 0;
int sens10 = 0;
int sens11 = 0;
int sens12 = 0;
int sens13 = 0;
int sens14 = 0;
int sens15 = 0;
int sens16 = 0;

ESP8266 wifi(&EspSerial);

BlynkTimer timer;


void myTimerEvent()
{
  
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);  
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);  
digitalWrite(22, HIGH);
digitalWrite(23, HIGH);
digitalWrite(24, HIGH);
digitalWrite(25, HIGH);
}


void loop()
{
 sens1 = analogRead(A0); 
 sens1 = map(sens1, 590, 310, 0, 100);
 Blynk.virtualWrite(V5, sens1); 

 sens2 = analogRead(A1); 
 sens2 = map(sens2, 592, 310, 0, 100);
 Blynk.virtualWrite(V6, sens2); 

 sens3 = analogRead(A2); 
 sens3 = map(sens3, 582, 307, 0, 100);
 Blynk.virtualWrite(V7, sens3); 

 sens4 = analogRead(A3); 
 sens4 = map(sens4, 589, 311, 0, 100);
 Blynk.virtualWrite(V8, sens4); 

 sens5 = analogRead(A4); 
 sens5 = map(sens5, 577, 305, 0, 100);
 Blynk.virtualWrite(V9, sens5); 

 sens6 = analogRead(A5); 
 sens6 = map(sens6, 581, 308, 0, 100);
 Blynk.virtualWrite(V10, sens6); 

 sens7 = analogRead(A6); 
 sens7 = map(sens7, 575, 302, 0, 100);
 Blynk.virtualWrite(V11, sens7); 

 sens8 = analogRead(A7); 
 sens8 = map(sens8, 580, 273, 0, 100);
 Blynk.virtualWrite(V12, sens8); 

 sens9 = analogRead(A8); 
 sens9 = map(sens9, 579, 308, 0, 100);
 Blynk.virtualWrite(V13, sens9); 

 sens10 = analogRead(A9); 
 sens10 = map(sens10, 585, 306, 0, 100);
 Blynk.virtualWrite(V14, sens10); 

 sens11 = analogRead(A10); 
 sens11 = map(sens11, 588, 310, 0, 100);
 Blynk.virtualWrite(V15, sens11); 

 sens12 = analogRead(A11); 
 sens12 = map(sens11, 577, 306, 0, 100);
 Blynk.virtualWrite(V16, sens11); 

 sens13 = analogRead(A12); 
 sens13 = map(sens13, 583, 311, 0, 100);
 Blynk.virtualWrite(V17, sens13); 

 sens14 = analogRead(A13); 
 sens14 = map(sens14, 583, 310, 0, 100);
 Blynk.virtualWrite(V18, sens14); 

 sens15 = analogRead(A14); 
 sens15 = map(sens15, 577, 306, 0, 100);
 Blynk.virtualWrite(V19, sens15); 

 sens16 = analogRead(A15); 
 sens16 = map(sens16, 584, 309, 0, 100);
 Blynk.virtualWrite(V20, sens16); 
 
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

My problem :

When the pump is not connected to the relay, all the system works properly via Blynk! (I receive all the data from my sensors and I can turn on or turn off the relay).

But, when I connect the pump on the relay and start it via Blynk, the pump starts the ESP8266 lost the connection (and lost the Blynk connection) and the pump stays On. ( I can't turn off with Blynk).

My guess

Maybe the pump draw a huge amount of current at the startup and the ESP8266 can't support this drop.

Maybe there is a high voltage variation and the ESP8266 can't handle it.

Solutions???

Some people talk about Flyback diodes like 1N4007 to put at the pump, supply or at the ESP.

Other people proposed to use MOSFET transistor like 2N7000 or capacitor.

Honestly, I don't know if I did a mistake in my wires connections , but I'm not sure what to try and I need your help find a solution and understand why that solution works!

Just a wild guess and probably wrong but maybe the pump somehow jams the wifi signal?

I can try to isolate the pump with a kind of Faraday cage, but I'm not sure that will change something.

I'll try and let you know! :slight_smile:

Thanks!