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

#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";

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

BlynkTimer timer;
BH1750 lightMeter;
int humidity;
int light;
bool pressed = 0  ;
bool pump=1;

void sendData(){
//      Serial.print("humidity: ");  
//      Serial.println(humidity);  
//      Serial.print("light: ");  
//      Serial.println(light);  
void checkConnection(){  
    Blynk.begin(auth, wifi, ssid, pass);
void checkButton(){   
  if(digitalRead(BUTTON) && pressed){
//      Serial.println("pump from button");          
  else if(digitalRead(BUTTON) && !pressed){
    Serial.println("switching pump"); 
void setup() { 
  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()) {

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: circuit

  • Your question does not have any schematic or other details regarding the hardware. Optical relay? Mechanical relay? If mechanical did you use a fly-back diode? Or mechanics. Were you testing the motor under load? (For example with water in the pump?) Or did you try it with no load? (For example, dry?) Are the power supplies floating? Did you share a common ground?
    – st2000
    Aug 14 '17 at 12:41
  • @st2000 Hi, thanks for your response. I added the circuit to my post. I'm using this 1 channel relay from ebay. The motor was tested under load. I'm sharing a common ground. Neither of the power supplies is connected to the ground pin in the power socket (so they're both floating, I guess).
    – mayorBurns
    Aug 14 '17 at 20:05
  • Separate your grounds. The relay provides isolation. The optical coupler even more. I see you may be driving the EPS8266 with a 5 volt signal. Yet it is power from a 3.3 volt source. This is not a good arrangement. Unless the EPS8266 has over voltage protection on its input, this could lead to unexpected results. The relay in your schematic is very confusing. I am hoping that it actually is something very different from the symbol.
    – st2000
    Aug 15 '17 at 1:11
  • Separating the grounds really did the thing - thanks a lot! I just don't understand why? And is there any way I could power both the electronics and the water pump from only one power supply? @st2000 As I mentioned in my question, I'm using this board with the ESP8266. Regarding the relay - I used the symbol I found in Fritzing. Link to the relay I'm actually using is mentioned in my previous comment.
    – mayorBurns
    Aug 15 '17 at 8:33
  • Not absolutely sure w/o testing why separating the grounds works. However, it is likely you are still (and this still might the the root cause of your problems) driving a 3 volt powered ESP8266 with a 5 volt serial port signal. This is not good. You might, at the very least, look into a resistor divider circuit to reduce the serial port voltage down to 3 volts.
    – st2000
    Aug 16 '17 at 5:10

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 enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.