Problem with Rele 5V and repeated cycles

Good morning everyone!

I am new to the forum and I hope I am not writing in the wrong place!
I am writing to you because I have a simple code that does not seem to work in the correct way, I will explain what it should do.

I have an Arduino UNO R3 (powered via 9-12V PIN from an external power supply) to which is connected a 5V relay that activates a pump (powered at 12V from an external power supply).

My intention is that 4 times the pump will turn on for 5 minutes and stop for 1 minute after which it will turn on for 5 minutes and stop for 5 minutes. Then start again from the beginning.

Example:
5 min ON - 1 min OFF
5 min ON - 1 min OFF
5 min ON - 1 min OFF
5 min ON - 1 min OFF
5 min ON - 5 min OFF
back to the beginning

Then there is a second 5V relay that activates a fan also powered at 12V from the same external power supply as the pump.

The code I used is this:

int PUMP = 11;
int FAN = 8;


void setup() {
  pinMode(PUMP, OUTPUT);
  pinMode(FAN, OUTPUT);
  digitalWrite(FAN,HIGH);
  delay(2000);
}

void loop() {

  digitalWrite(PUMP,HIGH);
  delay(300000);
  digitalWrite(PUMP,LOW);
  delay(60000);
  digitalWrite(PUMP,HIGH);
  delay(300000);
  digitalWrite(PUMP,LOW);
  delay(60000);
  digitalWrite(PUMP,HIGH);
  delay(300000);
  digitalWrite(PUMP,LOW);
  delay(60000);
  digitalWrite(PUMP,HIGH);
  delay(300000);
  digitalWrite(PUMP,LOW);
  delay(60000);
  digitalWrite(PUMP,HIGH);
  delay(300000);
  digitalWrite(PUMP,LOW);
  delay(300000);
}

I don't understand where the error is, but sometimes the pump keeps going without stopping anymore, sometimes it stops without activating anymore.
Sometimes I seem to experience a very brief interruption of 1 or 2 seconds and then it restarts immediately.

Can you tell me where I am going wrong?

Thank you very much and good work to everyone!

Nicola

could it be a power glitch because you're powering the pumps, relays and arduino with the same supply?

could disconnect the pumps from the relay and see if you have the same problem. if so, try replacing the relay with an LED (use LED_BUILTIN) and see if the problem clears.

if either case, may need a (8V) regulator with a large capacitor on it's output to supply the Arduino and/or a 5V regulator supply power to the relay (presumably instead of powering the relay thru the Arduino, don't know)

Hi,
Welcome to the forum.

Thankyou for using code tags.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

In particular your relay and a link to its specs/data.
What are you using as your power supplies?

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

Hi,
Note that the delay function value is an integer.

With a UNO -32,768 to 32,767

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

First I hope you are testing with smaller numbers so you aren't waiting around to see if things are working.

That's another advantage to using an LED proxy.

Second you are flying blind, there's no need to.

Place

    Serial.begin(115200);
    Serial.println("System reset!");

in your setup() function, open the serial monitor window and make sure it is set to 115200 to match the sketch, and you will see (maybe) that a power problem is happening.

You can use Serial.print strategic like to see where your program has flown.

Syntax


delay(ms);


Parameters


ms: the number of milliseconds to pause. Allowed data types: unsigned long

delay() takes an unsigned long as an argument. For constants larger than 32767, you should use the UL specifier like

 delay(300000UL);

in any calls.

HTH

a7