The relay module goes crazy after connecting the power supply

Hi.

I'm building an automatic watering system and I'm currently stuck with switches and pumps. Below is my code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int pomiar = 0;
int RelayPinSix = 6;
int RelayPinSeven = 7;



void setup() {
  Serial.begin(115200);
  pinMode(RelayPinSix, OUTPUT);
  pinMode(RelayPinSeven, OUTPUT);
  digitalWrite(RelayPinSix, LOW);
  digitalWrite(RelayPinSeven, LOW);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
   display.clearDisplay();
}

void loop() {
  runPompOne();

  runPompTwo();
}


void runPompOne() {
  digitalWrite(RelayPinSix, HIGH);
  Serial.println("6 high");
  displayText("Pompa1:ON");
  delay(5000);
  digitalWrite(RelayPinSix, LOW);
  displayText("Pompa1:OFF");
  delay(1000);

}

void runPompTwo() {
  digitalWrite(RelayPinSeven, HIGH);
  displayText("Pompa2:ON");
  delay(5000);
  digitalWrite(RelayPinSeven, LOW);
  displayText("Pompa2:OFF");
  delay(1000);
}

void displayText(String textToDisplay) {
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println(textToDisplay);
  display.display();
  delay(100);
}

Everything works fine until power is connected to the pumps. Below is a link to the video:

https://drive.google.com/file/d/1r1L5Xv1-255oMOb5-lWkz-k8uS0JhB7_/view?usp=sharing

Perhaps a wiring diagram?

Did you add the required freewheel diodes?

The video shows he's using one of those relay boards (so all that's on there),
wiring details, other pertinent information - not included.


@runaway_pancake i connected it like that

if only one pump is connected then everything is ok

The powerbank, in the video, powers only the pumps (through the relays) and nothing else?

What is the power source for the Arduino (not shown in your diagram).

@runaway_pancake yes, powerbank powers only pomps. The power source for arduino is USB 3.0 port in my laptop

maybe the problem is that it is an arduino clone?

Hi, @maciejunio

Can I suggest you reverse engineer your project and draw a schematic.

Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Please do not use cut and paste or Fritzy imaging.

Can you please post a link to data/specs of your pump?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

The problem is that you are powering the relay board from the Arduino 5V output. Might be OK for one relay but not for 2 or more.
You need a separate power supply for the relay board
Remove the yellow jumper.
Connect the Vcc pin the the arduino 5V.
Disconnect the relay GND from the Arduino GND
Connect the JD-Vcc pin to an external 5V supply
Connectet the external supply ground to the relay board ground(GND).

1 Like

@jim-p I tried as you wrote and the result is the same

I may have edited my post since you last seen it, Please see 11 again

@jim-p i saw it, result is the same

In your circuit diagram you have the relay VCC connected to Arduino Vin, hope that is a mistake.

I am having a similar issue, I think there could be voltage spike problems. I can see that you get power from the relay module to Arduino and this could cause temporary spikes when relays are started taking away power from Arduino putting it the state you mentioned. I think you need to plan the activation like activating one pump after another instead of starting all of them at once. Or try powering Arduino from a different source than the relay module source and tie the grounds together. Problem could be more than meets the eye. I am just suggesting this as I have experienced these power problems often. Infact a right strategy can help you run the system with the given power. Also please check the battery power, a low powered battery can cause a lot of damage putting the machine in unknown states.

@jim-p it is only picture from shop where i bought this set. I tried connect Relay VCC to external power source and the result is same. After this i tried again connect Relay VCC to 5v on arduino and again result is same

Can you share a link to a website so we can see what you bought, maybe we'll see some clues as to what's wrong.

Sure, https://a.aliexpress.com/_EzPt2Y9

Thanks