ESP8266 keep resetting when powering DC water pump

Hi everyone, so I have a project with ESP8266 that uses ultrasonic sensor to detect water level and a 5V relay module that will be powering a micro submersible DC water pump. Everything works fine without the pump connected to the relay module and I could switch on or off the relay module through Blynk app.

When I connect the pump to the relay module and power it, the ESP8266 keep resetting after a few seconds and the relay keep switching on or off by itself even the water level is low. The LCD display just goes crazy by displaying weird character.

I make sure everything is connected to the common ground and I am powering the entire system with a MB102 module which I suspect it could not deliver enough power to the system and causes resetting of the ESP8266?

Thank you!

Sorry, from your description I am unable to reproduce the code or create a schematic of your project or reproduce the error. Could you post your code, post an image of your project, links to datasheets, and other wot not.

Code goes into code tags.

When you say that everything is connected to common ground, does that include the pump?

Best to run pump from a separate DC supply. It is completely isolated via the relay.
Or, try using decoupling capacitor close to the ESP. - 220uF 16v and a 0.1uF capacitor over the DC supply of the ESP.

This is a code for my project and I will attach my diagram below. I used my phone charging adapter rated at 9V 2A or 5V 2A to power the project through the MB102 module. I wonder is there any error from all the connection? A logic level converter is used to convert 3.3V to 5v for the relay to work well.

The ESP8266 keep resetting when I connect the pump to the relay but the ESP8266 won't reset when the pump is not connected. The LCD display display weird characters after few resets. I hope my code and diagram are not messy as I am beginner to this. Thanks!

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

WidgetLED led1(V2);

char auth[] = "";//Enter your Auth token
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password
BlynkTimer timer;
bool pinValue = 0;

long duration;
int distance; 
int lvlmin = 5;

#define trig D7
#define echo D8
#define relay D5
void setup() {
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(relay, OUTPUT);
  Wire.begin(D2, D1);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1L, Wlevel);
  digitalWrite(relay, HIGH);

  pinValue = param.asInt();
void loop() {;;

void Wlevel(){
  digitalWrite(trig, LOW);
  digitalWrite(trig, HIGH);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = duration * 0.034 / 2;
  Blynk.virtualWrite(V1, distance);

 if (pinValue == 1)
       if (distance >= lvlmin)
          digitalWrite(relay, LOW);
          lcd.print("Water Lvl:");
          lcd.print("Pump: ON  (AUTO)");
          digitalWrite(relay, HIGH);
          Blynk.notify("Hey! Tank is full!");
          lcd.setCursor(0, 0);
          lcd.print("Water Lvl:");
          lcd.print(" cm");
          lcd.print("Pump: OFF (AUTO)");
      digitalWrite(relay, HIGH);
      lcd.print("System is OFF   ");
      lcd.print("Check Blynk     ");;




I would say so , there is a diagram attached below for your reference. Thanks!

Do not source power for a motor through a breadboard.

What the the power requirements of the motor, what is the power supply current rating?

It is a 3-5V and 100-200mA DC micro submersible pump. As what I have seen, the MB102 is able to deliver maximum 700mA. I suspect the MB102 is not able to deliver the power needed?

How may I source power for a motor if not through a breadboard?

Thank you.

Might be the supply thingy cannot handle the motor and the relay together.

I soldered up my own power boards that I use for testing of servos and motors.

I think you have misunderstood the purpose of the relay. It is supposed to isolate pump power from Arduino power so that the pump can't trouble the Arduino.

The pump is supposed to have its own power supply switched on and off by the relay, which the Arduino controls but does not power. By connecting pump ground to Arduino ground, the protection the relay offers is lost.

The pump will draw many times it's normal running current at the moment it starts up. This could be too much for your power supply, causing a voltage drop which resets the esp. You could try connecting a large electrolytic cap, e.g. 470uF, as close as you can to the power input to the relay. This will act as a local power reservoir when the pump starts up, and help reduce that voltage drop. Be sure to connect the cap correctly, they can explode if connected in reverse.

I assume the grey rectangle in the bottom left of your diagram is representing the pump? You need a flyback diode there to protect the circuit against a the reverse voltage that will be generated when the pump is switched off. That reverse voltage may already have damaged some of your components, so be sure to test them all again. A suitable flyback diode could be 1N4001. Again, be sure to connect the diode correctly, with its cathode to +V and anode to -V terminals of the motor.

It's also possible the pump is causing electrical noise when running which is affecting the rest of the circuit, such as the strange LCD characters. Attach a 0.1uF ceramic capacitor across the terminals of the pump to suppress any noise. With this type of cap you don't need to worry about which way around to connect it.

You could consider replacing the relay with a MOSFET. These are smaller, make no noise, don't wear out, and don't need a large current to power a coil like a relay does. Choose an N-channel MOSFET with a logic a logic level gate and a low on-resistance, such as stp16nf06l.

Indeed. The MB102 is very nice for powering a sensor or two. But it's not a proper power supply. It's very, very limited and the 700mA you've read about is far too optimistic. With 9V input and 5V output it would dissipate 4*0.7=2.8W, which it will refuse to do; it will overheat and shut down.
A more realistic current supply capability at 9V in and 5V out is something like 100mA absolute maximum. If you feed 12V into the board or jumper it to supply 3.3V it's even less.

Forgot to say: don't think you need that level shifter (I assume that's what it is) either for relay or MOSFET.

Hi , I have connected the motor with an external power supply and it worked better without resetting. However, the LCD screen will display weird characters and I think it is due to the interference of the motor with the LCD screen.

How can connect a large electrolytic capacitor as close as I can to the power input to the relay ? Does that mean I need to connect it on the breadboard?

As far as I am concerned, a diode is present in the relay module? Do I still need a flyback diode, if yes how can I add it ? How about the 0.1uF ceramic capacitor, you have mentioned to connect across the terminals of the pump which mean the capacitor is connected between the relay module and the pump ?

I would want to try a MOSFET but the delivery time is painfully long. The logic level shifter is needed to convert the 3.3v signal from the ESP8266 to 5v signal to the relay module as it needed 5v signal to switch the coil, I can't switch the coil without it.

Thank you.

I have separated the pump supply with the breadboard supply and it worked well just the LCD screen will display weird character after few switching on and off of the pump. How can I solve this ?

Thank you.

You can connect it to the breadboard, yes, or however you like, but close to the relay. This is so that when the pump starts, the cap is already fully charged, and closer (along the wires) than other parts of the circuit, so it can act as a reservoir.

That diode is for the relay's coil. The new diode is for the pump. Devices like relays, motors and electromagnets all contain coils. When the power to any coil is switched off, a reverse current is created (induced) for a moment which can damage the rest of the circuit. Connecting a diode across the terminals of the coil allows the reverse current to dissipate harmlessly through the diode. Connect it as close to the pump terminals as you can. If you connect the diode the wrong way around, it will short-circuit the pump and the diode may be destroyed.

No, it is connected across the pump's terminals, like the diode.

Have you tried not using it? It should not be needed, I think. On relay modules there is normally a transistor which switches the current to the coil, so the relay trigger input can be low voltage and low current.

Maybe a few other suggestions - use a 7805 regulator plus the caps as suggested by others.
Use the 1.5A rated TO-220 package - this will give you more than an Amp to play with.
Maybe, also strap the reset pin to 5v on the Arduino.
An N-Channel FET will also be a much better bet than the relay - as suggested.
It is obvious, that you have a problem with the power.

Hi , as what I have read from your reply , I try to understand it and come out with a schematic diagram. Please correct me if I am wrong. I have put a 47uF polarized capacitor on the breadboard power rails between the positive terminal and negative terminal. Also, a ceramic capacitor 0.1uF is connected across the pump terminal. Is this correct?

Without the logic level shifter, I could not trigger the switch on the relay module and it just works after I install the shifter.

Thank you.

The 47uF is in the correct place but it's value is too small to have much effect I think. I suggest 470uF or maybe even 1000uF.

The 0.1uF cap is ok. But where is the diode? That should be in the same place.

Hi, I connected the cathode to the positive terminal and anode to the negative terminal of the pump. Could I solder the ceramic capacitor and diode together?

Thank you