user37325: the aim of the project I'm working on is to water my bonsai automatically, depending on numerous sensor inputs. So basically I have Arduino Nano with huminity and light sensor, a relay to switch the water pump and ESP8266 wifi module, which I use to check the data from the sensors in the Blynk app on my phone. I use two isolated circuits. The first one is used only by the DC motor (water pump) and is supplied by a 5V 600 mA power source. The second takes care of the rest (arduino, ESP, sensors, relay) while it's supplied by a 5V 1A power source. I'm using this with the ESP8266 board.
Once I run the program, it connects to the Blynk server and I can read data from the sensors on my phone. The problem comes when I want to switch the relay from the Blynk app. Than the ESP8266 disconnects (nearly immediately, or after few seconds). I tried a different DC motor (not a water pump) and it worked fine. I also tried to switch the pump without using EPS8266, that worked as well (so the code should be ok). I think this has something to do with the current draw caused by the water pump, but that makes no sense - I'm using two independent circuits, the pump draws maximally 300 mA from the 600 mA source, while the rest of the electronics draws no more than 200 mA from the 1 A power supply. Neither different power supplies, nor another relay worked.
Here's my code:
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

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

#include <BH1750.h>
#include <Time.h>
#include <SoftwareSerial.h>

#define PUMP  10
#define SENSOR A0
#define BUTTON 2


char ssid[] = "XXXXX";
char pass[] = "XXXXXXXXXXXXXXXXXX";


SoftwareSerial EspSerial(11, 12);
ESP8266 wifi(&EspSerial);

BlynkTimer timer;
BH1750 lightMeter;
int humidity;
int light;
bool pressed = 0  ;
bool pump=1;
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXX";


void sendData(){
      humidity=analogRead(SENSOR);
      light=lightMeter.readLightLevel();
      Blynk.virtualWrite(V0,humidity);
      Blynk.virtualWrite(V1,light);  
//      Serial.print("humidity: ");  
//      Serial.println(humidity);  
//      Serial.print("light: ");  
//      Serial.println(light);  
}
void checkConnection(){  
  if(!Blynk.connected()){ 
    digitalWrite(PUMP,1);
    Blynk.begin(auth, wifi, ssid, pass);
  }
 }
void checkButton(){   
  if(digitalRead(BUTTON) && pressed){
     Blynk.virtualWrite(V3,digitalRead(BUTTON));
     pump=!pump;   
//      Serial.println("pump from button");          
     }
  else if(digitalRead(BUTTON) && !pressed){
    pressed=1;    
    }
  else{
    pressed=0;
    }      
}
BLYNK_WRITE(V2)
{
    Serial.println("switching pump"); 
    pump=!param.asInt();
    digitalWrite(PUMP,pump);
}
void setup() { 
  Serial.begin(9600);  
  delay(10);
  EspSerial.begin(9600);  
  delay(10);
  lightMeter.begin();    
  pinMode(PUMP, OUTPUT); 
  pinMode(BUTTON, INPUT);
  digitalWrite(PUMP, pump); 
  Blynk.begin(auth, wifi, ssid, pass);
  timer.setInterval(5000L, sendData);
  //timer.setInterval(5L, checkButton);  
//  timer.setInterval(2000L, checkConnection);
  }

void loop() {  
  if (Blynk.connected()) {
      Blynk.run();
      timer.run();
    }
}

and the Blynk log:
[2631095] <[06|05|14|00|00]
[2631389] >[00|05|14|00|C8]
[2632112] <[14|05|15|00|08]vw[00]0[00]632
[2632280] <[14|05|16|00|07]vw[00]1[00]28
[2637109] <[14|05|17|00|08]vw[00]0[00]630
[2637214] <[14|05|18|00|07]vw[00]1[00]28
[2641393] <[06|05|19|00|00]
[2651445] Cmd error
[2656470] Cmd skipped:20
[2656471] Cmd skipped:20

[EDIT] and the circuit:


user37325: The problem was hidden in a wrong relay wiring. Once I'm using only COM and NO PIN as it is showed in this article, not only that the whole system is stable and the ESP8266 is not disconnecting any more, but I can also power the circuit using only one 5V 2A power supply. 
Here's my updated schematics 

37325: <p>the aim of the project I'm working on is to water my bonsai automatically, depending on numerous sensor inputs. So basically I have Arduino Nano with huminity and light sensor, a relay to switch the water pump and ESP8266 wifi module, which I use to check the data from the sensors in the Blynk app on my phone. I use two isolated circuits. The first one is used only by the DC motor (water pump) and is supplied by a 5V 600 mA power source. The second takes care of the rest (arduino, ESP, sensors, relay) while it's supplied by a 5V 1A power source. I'm using <a href="https://www.tindie.com/products/blkbox/esp8266-esp-01-programming-and-development-board/" rel="nofollow noreferrer">this</a> with the ESP8266 board.</p>

<p>Once I run the program, it connects to the Blynk server and I can read data from the sensors on my phone. The problem comes when I want to switch the relay from the Blynk app. Than the ESP8266 disconnects (nearly immediately, or after few seconds). I tried a different DC motor (not a water pump) and it worked fine. I also tried to switch the pump without using EPS8266, that worked as well (so the code should be ok). I think this has something to do with the current draw caused by the water pump, but that makes no sense - I'm using two independent circuits, the pump draws maximally 300 mA from the 600 mA source, while the rest of the electronics draws no more than 200 mA from the 1 A power supply. Neither different power supplies, nor another relay worked.</p>

<p>Here's my code:</p>

<pre><code>#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

#include &lt;ESP8266_Lib.h&gt;
#include &lt;BlynkSimpleShieldEsp8266.h&gt;

#include &lt;BH1750.h&gt;
#include &lt;Time.h&gt;
#include &lt;SoftwareSerial.h&gt;

#define PUMP  10
#define SENSOR A0
#define BUTTON 2


char ssid[] = "XXXXX";
char pass[] = "XXXXXXXXXXXXXXXXXX";


SoftwareSerial EspSerial(11, 12);
ESP8266 wifi(&amp;EspSerial);

BlynkTimer timer;
BH1750 lightMeter;
int humidity;
int light;
bool pressed = 0  ;
bool pump=1;
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXX";


void sendData(){
      humidity=analogRead(SENSOR);
      light=lightMeter.readLightLevel();
      Blynk.virtualWrite(V0,humidity);
      Blynk.virtualWrite(V1,light);  
//      Serial.print("humidity: ");  
//      Serial.println(humidity);  
//      Serial.print("light: ");  
//      Serial.println(light);  
}
void checkConnection(){  
  if(!Blynk.connected()){ 
    digitalWrite(PUMP,1);
    Blynk.begin(auth, wifi, ssid, pass);
  }
 }
void checkButton(){   
  if(digitalRead(BUTTON) &amp;&amp; pressed){
     Blynk.virtualWrite(V3,digitalRead(BUTTON));
     pump=!pump;   
//      Serial.println("pump from button");          
     }
  else if(digitalRead(BUTTON) &amp;&amp; !pressed){
    pressed=1;    
    }
  else{
    pressed=0;
    }      
}
BLYNK_WRITE(V2)
{
    Serial.println("switching pump"); 
    pump=!param.asInt();
    digitalWrite(PUMP,pump);
}
void setup() { 
  Serial.begin(9600);  
  delay(10);
  EspSerial.begin(9600);  
  delay(10);
  lightMeter.begin();    
  pinMode(PUMP, OUTPUT); 
  pinMode(BUTTON, INPUT);
  digitalWrite(PUMP, pump); 
  Blynk.begin(auth, wifi, ssid, pass);
  timer.setInterval(5000L, sendData);
  //timer.setInterval(5L, checkButton);  
//  timer.setInterval(2000L, checkConnection);
  }

void loop() {  
  if (Blynk.connected()) {
      Blynk.run();
      timer.run();
    }
}
</code></pre>

<p>and the Blynk log:</p>

<pre><code>[2631095] &lt;[06|05|14|00|00]
[2631389] &gt;[00|05|14|00|C8]
[2632112] &lt;[14|05|15|00|08]vw[00]0[00]632
[2632280] &lt;[14|05|16|00|07]vw[00]1[00]28
[2637109] &lt;[14|05|17|00|08]vw[00]0[00]630
[2637214] &lt;[14|05|18|00|07]vw[00]1[00]28
[2641393] &lt;[06|05|19|00|00]
[2651445] Cmd error
[2656470] Cmd skipped:20
[2656471] Cmd skipped:20
</code></pre>

<p>[EDIT] and the circuit:
<a href="https://i.stack.imgur.com/HmDav.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HmDav.png" alt="circuit"></a></p>
 37325: <p>The problem was hidden in a wrong relay wiring. Once I'm using only COM and NO PIN as it is showed in <a href="https://bocoup.com/blog/javascript-relay-with-johnny-five/" rel="nofollow noreferrer">this article</a>, not only that the whole system is stable and the ESP8266 is not disconnecting any more, but I can also power the circuit using only one 5V 2A power supply. </p>

<p>Here's my updated schematics <a href="https://i.stack.imgur.com/wupDW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wupDW.png" alt="enter image description here"></a></p>
